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
Member for
16 years 10 monthsKarl,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
Member for
16 years 5 monthsPart 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
Member for
13 years 11 monthsGood 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
Member for
14 years 6 monthsSunrise 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
Member for
16 years 10 monthsLights 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
Member for
14 years 6 monthsBrett 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
Member for
14 years 5 monthsup and running now on a
up and running now on a couple of lamps, combined with bedtime and movement sense :)
Cheers Karl and Brett
Member for
16 years 5 monthsNice One
Great stuff. How about posting it in the samples section so we can all pick the changes up.
Member for
14 years 5 monthswill do
will do
Member for
16 years 10 monthsUpdated 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 /content/british-summer-time
Brett
Member for
14 years 5 monthsI'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 :)
Member for
16 years 10 monthsMark 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