Hi All,
With much help from the forums I’ve written a LUA script to change the time my accent lights turn on.
We have a number of accent lights that create a nice ambiance during the evening. I originally set them to trigger after sunset + some fixed time. We noticed on a cloudy day we would like them to come on sooner. I looked into Lux sensors but I saw too many forums reports that the Lux sensors are not repeatable. So I decided to use the sky conditions from the Wunderground plugin to modify my scene. This approach is also simpler.
I have two “ON” scenes:
#1) Turn on the accent lights using the lua code to only enable this scene when the sky is not (sunny or clear or mostly sunny). Triggered after sunset + fixed time (but less time than #2 scene.) If Wundergound is not reachable the program defaults to aborting Scene #1 (this scene). Purely an arbitrary decision.
#2) Turn on the accent light at a later time. This is the time we would like them to come on when sunny. It is triggered after sunset + fixed time.
There results are quite nice. It’s been running for over a week with no changes except for some minor tweaking of the fixed times to get them the way we like.
The code below is used in the first “on” scene with no code in the second. After a time I will reduce the luup.log calls but for now there is no harm. BTW the XXXXXX and ZZZZZZ make it easy for me to search the log file.
For the future I think I can access the sky conditions directly from Vera, as there are shown on the dashboard screen. At the moment I’m not sure how to fine the Vera information to accomplish this but will keep looking.
I’d be interested in thoughts or comments. BTW this is my first Lua script.
JohnRob
-- Version 1
function readsky ()
local t = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "ConditionGroup", 15)
return t
end
local skyerror, skycondition -- skyerror will be true/false depending on success of pcall
skyerror, skycondition = pcall (readsky) --returns boolean error, returneddata1, returneddata2 .....
luup.log("XXXXX condition then pcallSuccess/error")
luup.log(skycondition)
luup.log (tostring(skyerror))
luup.log("ZZZZZ")
if (skyerror)
then
luup.log("skyerror if interpreted as true")
if ( (skycondition == "clear")
or (skycondition == "sunny")
or (skycondition == "mostlysunny")
)
then
return false -- if sunny, abort scene and lights will go on by the later scene
else
return true -- if not sunny turn on lights in this scene
end
else
luup.log("skyerror if interpreted as false")
return false -- if call to readsky return error, abort this scene (arbitrary decision)
end