HAHnode Monitor Script

12 replies [Last post]
BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010

Here is a basic script that monitors a HAHnode's light level and triggers an action based on the current reading.  The script has been written as a framework that can/should be developed.  

There are a few comments in the code that will help those just starting.

 

Karl

AttachmentSize
lightlevel.lua2.95 KB
brett
Offline
Providence, United States
Joined: 9 Jan 2010
Karl,Thats great.  Do

Karl,

Thats great.  Do remember there are some nice BSC helper functions.

Code that you write like this

  local msg=string.format([[
xap-header
{
class=xAPBSC.cmd
target=dbzoo.livebox.Controller:relay.1
}
output.state.1
{
id=*
state=%s
}]], triggerAction)

-- Send the message
  xap.sendShort(msg)

Can also be represented like this:

bsc.sendState("dbzoo.livebox.Controller:relay.1", triggerAction)

I had to check that I actually wrote this up, and I did !

http://www.dbzoo.com/livebox/hah_plugboard_v2#bsc_command_helper_functions

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Part 2

Thanks Brett,

I'll put that in part 2, when I make the script only function between certain times.  This will be an example of controlling lights during the winter months, but obviously turning them off during sleeping hours.

It will also cover the motion sensor, and timers.

Any other improvements or suggests anyone?

Karl

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Good work Karl, i will be

Good work Karl, i will be sure to use this as 5 of my RF outputs are purely lighting

 

Andrew

magill
Offline
Joined: 27 Apr 2012
Sunrise Sunset

Hi Karl

Another extension to the functionality might be sunrise/sunset. Here is a link to a webservice that provides info.

http://www.earthtools.org/webservices.htm#sun

I have no idea how you would implement this request in lua but it would be useful for bringing on porch lights etc.

Just a thought..

John

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Lights on at sunset and off at sunrise

John,

Thats a cool idea.

I wrote two applets one that is a SunRise/SunSet forecaster and another that uses these events to figure out if the lights should be on or off.  (See attached)

You should adjust the sunForecastApplet.lua to setup your long/lat so it knows where you live, it uses this to compute the correct sunrise/sunset times.

Adjust automaticLightsApplet.lua if you want some other relay or event to fire - the basic structure is there.

UPDATE: two minor bugs.  I had not tested sunrise as I wrote this when it was dark :)

Brett

AttachmentSize
automaticLightsApplet.lua 1.05 KB
sunForecastApplet.lua 1.88 KB
magill
Offline
Joined: 27 Apr 2012
Brett you're a superstar

I reckon you responded with what I'm sure is a fully functioning script in 2 hours. How do you do that?

John

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
up and running now on a

up and running now on a couple of lamps, combined with bedtime and movement sense :)

Cheers Karl and Brett

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Nice One

Great stuff.  How about posting it in the samples section so we can all pick the changes up.

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
will do

will do

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Updated applets

I updated those two applets to simplify the code and to correct a defect.  Whilst doing so I found a bug in the penlight library which means those applets won't work until you upgrade to the beta 309.10.   If you do upgrade you'll find them included them in the sample directory /etc_ro_fs/plugboard/samples

The sunset/sunrise applet now has a 'daylight=yes/no' field to indicate if its daylight or not.  This makes figuring out if lights should be on or off much easier, no need to code time calculattions everywhere we might require it.

I've raised bug #97 against the library: https://github.com/stevedonovan/Penlight/issues/97

As this program uses localtime to compare against the sunrise/sunset times your TZ must set correctly for me I had to set it like this ( this TZ spece below does not correct for DST but I'll fix that later )

# echo 'AEST-9:30' > /etc/TZ

ref: post http://www.homeautomationhub.com/content/british-summer-time

Brett

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
I'll mod this code for my set

I'll mod this code for my set up and post again. I was ready to post them but saw you had updated again :)

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Mark the latest beta that I

Mark the latest beta that I pushed and the applets I updated on this thread as well are working fine,  I have a relay that toggles on and off with the rise and fall of the sun.   I think I might connect this to a LED for my office as a night light.

Brett

Hardware Info