Still learning the syntax…
If I wanted to only run a scene if between sunset and 11pm how do I do that? And is there a way to see if a scene is active? i.e. if a scene is active (it turned the lights on to 50%) and will turn them off at 11. I want another scene to trigger on an event then if this other scene is active return the lights to their previous settings.
EDIT
I found this snippit… I think will do what I want. The only thing missing is how to reference the internal sunset variable.
Scene that runs only in a user set time interval
Add this code in the Luup Code section:
local startTime = "22:30"
local endTime = "05:30"
local hour = tonumber( startTime:sub( startTime:find("%d+") ) )
local minute = tonumber(startTime:sub(-2))
if hour and minute then
startTime = hour * 100 + minute
else
luup.log("ERROR: invalid start time")
return false
end
hour = tonumber( endTime:sub( endTime:find("%d+") ) )
minute = tonumber(endTime:sub(-2))
if hour and minute then
endTime = hour * 100 + minute
else
luup.log("ERROR: invalid end time")
return false
end
local currentTime = os.date("*t")
currentTime = currentTime.hour * 100 + currentTime.min
luup.log("startTime = " .. startTime .. "; currentTime = " .. currentTime .. "; endTime = " .. endTime)
if startTime <= endTime then
-- Both the start time and the end time are in the same day:
-- if the current time is in the given interval, run the scene.
if startTime <= currentTime and currentTime <= endTime then
return true
end
else
-- The start time is before midnight, and the end time is after midnight:
-- if the current time is not outside the given interval, run the scene.
if not (endTime < currentTime and currentTime < startTime) then
return true
end
end
return false
This code allows the scene to run only between 22:30 and 5:30.