one trigger differnt scene based on time

Hi

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

luup.call_delay (“checkLastTrip”, intervalMinutes)

return true[/code]

Can someone help why not scene 43 not will start during daytime ?

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.

So much easier to do this in PLEG.

Ok

In pleg how? tried but i got it not to work properly. how to keep the light on when its detect movment?

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

i missed the last condition when i tried it before but dont quit understand what you mean to use the advance tab to re trigger autooff?

thanks for the help

hi again

The autooff timer dosent seem to start

not so easy when you are a newbie :cry:

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.

Hi again

I can’t still get the auto off to fire,

when you talk about the advance tab is it in pleg or somewhere else?

thanks in advance

[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]

I assume this is for UI5 and not UI7?

I assume this is for UI5 and not UI7?

Why do you assume it is not for UI7? PLEG works the same way for UI5 and UI7 - only the user interface is changed somewhat.