Scene based on no motion detected after midnight.

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 ?

Thanks

Gast

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:

  1. Create a new scene. In that scene:
  2. Create a timer and set it to run every 5 minute.
  3. 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 ?

Thanks

Gast

I suppose you already do that, but I have to ask, did you check the device number for your sensor is 34?

Also, you could check if the "LastTrip"variable in your sensor is actually changing every time it detects movement.

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 ?

Thanks

Gast

Ok, after the hint from mcardenas, I know that the code is working well. Thanks.

Now I want to add that this (turn off) should happen just if we are past midnight.

Someone can tell me what code should be added to the actual code ?

Tks

Gast

http://www.sperryware.com/veratools/time.html

This will convert the date/time to a readable format. Just cut and paste “1300131746” to get: Monday, March 14, 2011 12:42:26

Also see http://wiki.micasaverde.com/index.php/Luup_Scenes_Events

Near the bottom of the pages is “Access the current time” with more info

Thank you very much Shady.

Exactly what I was looking for.

Gaston

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]

Even if it works (please see previous post), it seems to have a problem.

When going to

http://192.168.1.8:49451/data_request?id=user_data&output_format=xml 

I have the following message:

[code]This page contains the following errors:

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.

Someone understand what is the problem ?

Gast

Nobody has an idea ? Something complex for me is probably easy for someone else, and this is new for me, and complex… ???

Thanks

Gast