Light controlled by switch and motion detector

Hi,

I realise that what I’m asking appears to be handled by the SmartSwitch plugin. Unfortunately it doesn’t seem to work on my UI7 Vera Edge, or I’m doing something wrong that doesn’t let it work.

I’m looking to trigger a light (Fibaro dimmer module) via a motion sensor (Fibaro 3-in-1 sensor), and have it turn off again after there’s no more motion being detected, but only at night. I’m also looking to have the light stay on if the switch is pushed to turn it on.

I can do the former quite happily with the built-in scenes and the is_night code. The latter is what I’m struggling with.

Is there an easy way to achieve this using LUUP or PLEG?

Ta much

I`m not very good with LUUP yet, but I found this:

return luup.is_night() == false

I use it on my Aeon Motion sensor to trigget a Smart Switch only at night. Just paste it in the LUUP code. And I change “false” to “true”. Works perfectly.

Be sure to refer to the Conditional Scene Execution thread (sticky) that is at the top of this section:

http://forum.micasaverde.com/index.php/topic,18679.0.html

Lots of good information there on how to do things such as described here, plus a lot of stuff that can give you additional ideas.

Cool. I’ll take a look at the Conditional Scene thread. Sounds like that’s what I might need.

Thanks!

Try this: it works only at night and checks if the switch is already turned on. If that is the case, the light will not turn off after 1 minute. I created a nightlight scene. Trigger is the motion detector , whether armed or not, turn on the light. Then create a delayed action in the scene to turn it of after x seconds. Use this code but change the dID to the device id of your switch :

local function checkNight()
if (luup.is_night()) then
return true
else
return false
end
end

local function checkOn()
local dID = 7
local allow = false
local status = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,dID)
return ((status == “1”) == allow)
end

return checkNight() and checkOn()

Not to be picky, but your CheckNight function is a little redundant.

Your could just have:

return luup.is_night() and checkOn()

[quote=“aa6vh, post:6, topic:185574”]Not to be picky, but your CheckNight function is a little redundant.

Your could just have:

return luup.is_night() and checkOn() [/quote]
;D tanks, not picky at all. Any other improvements are welcome to !

I am trying to achieve the same idea.

local sensorDeviceNo = 2
local lightDeviceNo = 1
local periodInSeconds = 10
local maxTripped = 5
local sensorTripped = 0

– Environment variables –
local SENSOR_MOTION_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
local DIMMABLE_LIGHT_SID = “urn:upnp-org:serviceId:SwitchPower1”

function checkLastTrip()
local lastTrip = luup.variable_get (SENSOR_MOTION_SID, “LastTrip”, sensorDeviceNo) or os.time()
if (os.difftime (os.time(), tonumber (lastTrip)) >= periodInSeconds) then
if (sensorTripped <= maxTripped) then
sensorTripped = sensorTripped + 1
else
luup.call_action (DIMMABLE_LIGHT_SID, “SetTarget”, {[“newTargetValue”] = 0}, lightDeviceNo)
end
else
luup.call_delay (“checkLastTrip”, periodInSeconds)
end
end

luup.call_delay (“checkLastTrip”, periodInSeconds)

return true

What really happens is when the motion sensor detects motion the lights turn on. Next the luup code should have turned off the lights after 50 seconds but just lasts forever… Any ideas?

What really happens is when the motion sensor detects motion the lights turn on. Next the luup code should have turned off the lights after 50 seconds but just lasts forever... Any ideas?

When the global function checkLastTrip() is called after the delay, the original code has already terminated so the local variables are no longer available. See Delayed Actions for an explanation and alternative ways to pass values to the delayed function.

A simple fix would be to define the local variables inside the function.