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?
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.
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
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
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.
Best Home Automation shopping experience. Shop at Ezlo!