Okay, please forgive the crudeness of my code, I am trying to learn here and was trying to put bits and pieces of examples I have seen together to something workable.
My goal is to set up a Scene that runs between 15 min. before sunset and 15 min. after sunrise.
The trigger will be a door sensor
The action will be to turn on a light (actually two light, but I set up a spare sensor and a spare Aeotec Smart Switch so I could test and play).
What I would like to happen is pretty obvious and straight forward. Between the times given, when the door is open (sensor is triggered) turn on the lights, but then turn them back off when the door is closed. Right now, I have two scenes set up, one to turn the lights on when the door is open and one to turn the lights back off. I wanted to consolidate this down to one scene and use Lua to check the sensor for when it is closed and turn the lights back off. What I post below is crude, trust me, I know, but I tried and so I am here seeing if I can get some input on the proper way to do this.
local sensorDevice = 52
local switchDevice = 46
local pStart = 15
local pEnd = 15
local allow = true
local SENSORID = "urn:schemas-micasaverde-com:device:DoorSensor:1"
loca SWITCHID = "urn:schemas-upnp-org:device:BinaryLight:1"
function switchON()
if SENSORID = 1 && luup.sunrise() = false
luup.call_action("urn:schemas-upnp-org:device:BinaryLight:1", "SetTarget", {newLoadlevelTarget = "1"}, 46)
else
luup.call_action("urn:schemas-upnp-org:device:BinaryLight:1", "SetTarget", {newLoadlevelTarget = "0"}, 46)
end
end
I thought that perhaps a DO/WHILE loop might work too, but I am not entirely sure. I would appreciate any assistance on this learning journey.