have a motionsensor that i want to turn on a lamp whit diffrent brightness depending if it is night or day. I have two scenes and i the first i have the following luup code.
But i seems that it dosent matter if is night or day just the first scene will start
the luup code is:
[code]-- Run only at night
if (luup.is_night() == false) then return
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{ SceneNum=“43” },0)
end
– Motion Sensor device number
local sensorDeviceNo = 72
– Light device number
local lightDeviceNo = 56
– Minutes to wait before shutting off light
local intervalMinutes = 2
local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1” – Switch Power Service ID
function checkLastTrip()
local lastTrip = luup.variable_get (SS_SID, “LastTrip”, sensorDeviceNo) or os.time()
if (os.difftime (os.time(), tonumber (lastTrip))/60 >= intervalMinutes) then
– Turn off the light.
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 0}, lightDeviceNo)
else
– Check when the sensor was last tripped every seconds.
luup.call_delay (“checkLastTrip”, intervalMinutes)
end
end
The luup.call_action(…) in the first part will never be executed. If you want it to run when it is night, try:
if (luup.is_night() == false) then return
else luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{ SceneNum="43" },0)
end
If you want it to run when it is not night, try:
if (luup.is_night() == false) then
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{ SceneNum="43" },0)
return
end
You may also have problems with your delayed function checkLastTrip(). When this is run by the delayed callback, it is in the global context but it is referring to some local variables that may not always still exist. The easy fix is to define the variables inside the function.
Input Motion: Motion When your motion detector detects motion
Input Schedule: called Night
Mon - Friday schedule ON after sunset off at sunrise.
Input Schedule: called MotionTimer
Self Retrigger … off after the specified interval.
Three conditions: NightMotion Motion and Night DayMotion Motion and Not Night AutoOff Motion; !MotionTimer
The last condition is not obvious without reading the documentation. It fires whem the MotionTimer turns false AFTER motion happened.
Add appropriate actions (Device Commands) to NightMotion, DayMotion, and AutoOff
Both the DayMotion and NightMotion should use the Advanced tab to (re-)start the OffTimer
To start the auto off timer you need to edit the actions for the condition you want to start the timer.
Then select the advanced tab. Add the PLEG device. Then select the action to Restart the timer.
You will need to provide the timer name.
You only need to provide the interval if you want to override the interval specified when the timer was created.
There are a lot of commands available for your devices that are not available via the graphical editor.
It’s worth while to look through the actions to see what’s available.
[quote=“RichardTSchaefer, post:5, topic:183762”]Input Motion: Motion When your motion detector detects motion
Input Schedule: called Night
Mon - Friday schedule ON after sunset off at sunrise.
Input Schedule: called MotionTimer
Self Retrigger … off after the specified interval.
Three conditions: NightMotion Motion and Night DayMotion Motion and Not Night AutoOff Motion; !MotionTimer
The last condition is not obvious without reading the documentation. It fires whem the MotionTimer turns false AFTER motion happened.
Add appropriate actions (Device Commands) to NightMotion, DayMotion, and AutoOff
Both the DayMotion and NightMotion should use the Advanced tab to (re-)start the OffTimer[/quote]