I have a scene that turn on a specific lamp at Sunset.
I have another scene where I turn off that same lamp at midnight.
It works well, but needs some improvement to make sure that the lamp is not turned off if there is still someone in the room.
I have a motion detector device in the room.
How do I do that: after midnight, closing the lamp as soon that there is no motion detected for 15 minutes ?
I started with something simpler (without the midnight constraint), but I need some help.
Based on the information in the wiki, I did the following:
Create a new scene. In that scene:
Create a timer and set it to run every 5 minute.
In the Luup Code section put the following code
[code]local deviceNo = 34
local period = 15
local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
local lastTrip = luup.variable_get(SS_SID, “LastTrip”, deviceNo) or os.time()
lastTrip = tonumber(lastTrip)
if (os.difftime(os.time(), lastTrip) / 60) >= period then
return true
end
return false[/code]
I also created a command to close the lamp.
Now, the light is closed even if there is no movement detected.
Could someone with more experience tell me if there is something wrong ?
Yes it is 34 (for the motion detector).
I was not aware for the “LastTrip” variable. Now I understand what where to look at. I will check. Right now the value is “1300131746”. How do we decode this value ?
There is also another variable, “tripped”. The value is “1”.
Also, how do I make this action (turn off) just after, let’s say, midnight ?
Here is the final code to turn off a lamp after 23h00 and after 15 minutes with no motion detected. This code is executed every 5 minutes.
Thanks again Shady
[code]local deviceNo = 34
local period = 15
local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight
local min_time_in_seconds = 23 * 3600 + 0 * 60 – 23:00
if (current_second > min_time_in_seconds) then
local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
local lastTrip = luup.variable_get(SS_SID, “LastTrip”, deviceNo) or os.time()
lastTrip = tonumber(lastTrip)
if (os.difftime(os.time(), lastTrip) / 60) >= period then
return true
else
return false
end
else
return false
end[/code]
error on line 690 at column 72: Specification mandate value for attribute FermerlampeSolariumNoMotion
Below is a rendering of the page up to the first error.[/code]
“FermerlampesolariumNoMotion” is the name of the scene.