Hi everyone, newbie question here…not asking for this to be done for me, just asking about the right way to progress.
I have a zwave keypad padlock, automated front lights, and just added a motion sensor to the front porch. I automatically run the front lights on different schedules every night. In the case someone comes to the front door when the front lights are off (say they arrive late night), I want to turn on the front lights for 5 minutes to make it easy for them to enter their door code and get their stuff in.
Basically, logic I am after is this:
If motion sensor is tripped
check if lights are already on
if yes, exit
if no
check if ambient light is > x% (is it daytime)
if yes, exit
if no
turn on front lights
turn off front lights after five minutes
Is this something best done in Luup code? or are there plugins that suit this type of logic? Really appreciate the help to get started!
My attempt at some Luup code…MIOS is returning an error, and I can’t seem to get kwikLog to work. I added this to the trigger when the motion detector is tripped.
Anyone have any ideas? Would love any thoughts. Thanks!
if checkNight() and checkOff() then
return true
else
return false
end
local function checkNight()
local allow = true -- true runs scene at night, false blocks it
return ((luup.is_night()) == allow)
end
local function checkOff()
local dID = 25 -- Device ID of your Z-Wave Switch
local allow = true -- true runs scene if switch is on, false blocks it
local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",dID)
return ((status <> "1") == allow)
end
Well, I went with the below, and it seems to be working. Hopefully there is nothing wrong with this approach…
check if it is night
check if light is already on
if luup.is_night() then
local dID = 25 -- Device ID of your Z-Wave Switch
local allow = true -- true runs scene if switch is on, false blocks it
local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",dID)
return ((status == "0") == allow)
else
return false
end
[quote=“cranked, post:2, topic:183067”]My attempt at some Luup code…MIOS is returning an error, and I can’t seem to get kwikLog to work. I added this to the trigger when the motion detector is tripped.
Anyone have any ideas? Would love any thoughts. Thanks!
[code]
if checkNight() and checkOff() then
return true
else
return false
end
local function checkNight()
local allow = true – true runs scene at night, false blocks it
return ((luup.is_night()) == allow)
end
local function checkOff()
local dID = 25 – Device ID of your Z-Wave Switch
local allow = true – true runs scene if switch is on, false blocks it
local status = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,dID)
return ((status <> “1”) == allow)
end
[/code][/quote]
The error is in the line return ((status <> “1”) == allow). Lua does not use <> for not-equal, it uses ~=. In my original example I used == and provided the variable allow to enable the logic to be inverted without changing the comparison operator.
If you are new to Lua, you may also find the book Programming In Lua very helpful.
I created a tool to help test Lua code for scenes. See LuaTest.[/quote]
No idea how I missed the manual…I guess I was searching for Luup. Really appreciate the help getting started…this testing tool alone has made it way easier. Thanks again!
Best Home Automation shopping experience. Shop at Ezlo!