Hi guys,
I am still a novice when it comes to coding. The goal of this script is to turn on the entry light when a code is entered on the front door keypad and to turn it off 90 seconds later if the dimming level hasn’t been manually adjusted. I only want the script run if it is getting dark or is already dark; I thought 2 hours before sunset until sunrise would work best. I also wanted to include an exception if the entry light is already on. I tried to make this as simple as possible, but it looks messy to me:
function lightOff()
if luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 33) == “75” then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 33)
end
end
local switchOnOff = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 33)
local sunsetTimeOffset = tonumber(luup.sunset()) - tonumber(os.time())
if switchOnOff == “0” then
if sunsetTimeOffset < 7200 or luup.is_night() == true then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “75”}, 33)
luup.call_delay(‘lightOff’, 90)
end
end
Any advice would be MUCH appreciated!