HAHnode Monitor Script
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
Attachment | Size |
---|---|
lightlevel.lua | 2.95 KB |
Good work Karl, i will be sure to use this as 5 of my RF outputs are purely lighting
Andrew
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
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
Attachment | Size |
---|---|
automaticLightsApplet.lua | 1.05 KB |
sunForecastApplet.lua | 1.88 KB |
I reckon you responded with what I'm sure is a fully functioning script in 2 hours. How do you do that?
John
up and running now on a couple of lamps, combined with bedtime and movement sense :)
Cheers Karl and Brett
will do
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
I'll mod this code for my set up and post again. I was ready to post them but saw you had updated again :)
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
Karl,
Thats great. Do remember there are some nice BSC helper functions.
Code that you write like this
Can also be represented like this:
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