I have a Philips hue outdoor motion sensor connected to my Zigate. I wanted to write a script with dzvents that turns the lights off after 5 min no motion. But if i use devices.lastupdate the devices.lastupdate resets after 4 minutes, even when there is no motion. Sometimes the device announces himself again after 4 min. I watched the log from last night, and a couple times the counter got to 5 of 9 min. But most of the time it only get till 4 min.
The cooldown for the motion sensor is 5 min. So if i write a script with lights off after 4 and we stay outside longer then that the lights go out for a minute, before motion is detected again.
Mayby i can get creative with a variable, but i like to know why it is behaving like this.
RezaRose wrote: ↑Tuesday 02 February 2021 10:29
Can somebody explain what is happening?
When looking for help here on a script related issue, please always include both the complete script (obscure any sensitive stuff) and the loglines.
Thx
RezaRose wrote: ↑Tuesday 02 February 2021 10:29
Can somebody explain what is happening?
When looking for help here on a script related issue, please always include both the complete script (obscure any sensitive stuff) and the loglines.
Thx
The script is working fine, it only shows what is happening with the device last update status. I think it is more a zigate or device related.
But for the one who wants to know:
RezaRose wrote: ↑Tuesday 02 February 2021 11:17
The script is working fine, it only shows what is happening with the device last update status. I think it is more a zigate or device related.
Thx for sharing.
Could it be that the motion sensor reacts to the light?
Most motion sensors change state when motion is detected AND they change state after the set timeout period. In domoticz this will update the lastUpdate field in both cases.
-- ************************************************************************
-- Motion - Process the motion detector. If no Motion is detected
-- while someone is home send out an alarm.
-- When no motion is detected for period grace1, send out
-- an e-mail to Rob. If no motion is detected for period grace2
-- send out an e-mail to xxxx and yyyy
--
--
-- Programmer: R. Muller
-- date 2019-02-25
--
-- Version date Programmer Reasom
-- ========== ========== ========== ===================================
-- 1.0.0 2019-02-25 RM Initial release
-- 1.0.1 2019-10-02 RM rewritten for RCWP-0516 sensor
--
-- ************************************************************************
return {
on = {
devices = {
'DopplerSensor' -- Motion sensor switch
},
timer = {'every minute'}
},
data = {
msg1sent = { initial = 1 },
msg2sent = { initial = 1 },
Motion = { history = true, maxItems = 100, maxMinutes = 40 } -- declare list
},
execute = function(domoticz, item)
local grace1 = '00:10:00' -- periode waarna een alert naar Rob gaat (hh:mm:ss)
local grace2 = '00:15:00' -- periode waarna een alert naar xxxx en yyyy gaat (hh:mm:ss)
local email1 = '[email protected]'
local email2 = '[email protected]'
--print('Motion Script Running')
if (domoticz.devices('iPhone-R').state == 'On' and -- R Home
domoticz.devices('iPhone-M').state == 'Off') then -- M Away
print('domoticz.data.msg1sent at start: ' .. domoticz.data.msg1sent)
print('domoticz.data.msg2sent at start: ' .. domoticz.data.msg2sent)
if (item.isDevice) then
print('Inside item.isDevice: Device name = ' .. item.name .. ' Device state = ' .. item.state)
-- motion detected, so reset message counters
domoticz.data.msg1sent = 0
domoticz.data.msg2sent = 0
-- store current device status in data table for later retieval
if (item.state == "On") then
domoticz.data.Motion.add(tonumber('1'))
else
domoticz.data.Motion.add(tonumber('0'))
end
elseif (item.isTimer) then
print('Inside isTimer')
if (domoticz.data.Motion.maxSince(grace1) == nil) then -- no data found in last grace1 minutes
print('domoticz.data.Motion.maxSince: nil found as value, no data to process')
else
print('domoticz.data.Motion.maxSince: ' .. domoticz.data.Motion.maxSince(grace1))
end
if ( (domoticz.data.Motion.maxSince(grace1) == 0 or
domoticz.data.Motion.maxSince(grace1) == nil) and
(domoticz.data.msg1sent == 0 or
domoticz.data.msg1sent == nil ) ) then
print('Action required send message to email1 (Rob)')
domoticz.log('No Motion detected for ' .. grace1 .. ' minutes, sending alert to Rob', domoticz.LOG_INFO)
domoticz.data.msg1sent = 1 -- message sent indicator
print('domoticz.data.msg1sent (s/b 1): ' .. domoticz.data.msg1sent)
-- send message to rob
domoticz.email('Reageer!!', 'De computer heeft Rob al ' .. grace1 .. ' minuten niet gezien', email1 )
end -- if (domoticz.data.Motion.maxSince(grace1) = 0
if ( (domoticz.data.Motion.maxSince(grace2) == 0 or
domoticz.data.Motion.maxSince(grace2) == nil ) and
(domoticz.data.msg1sent == 1 and
domoticz.data.msg2sent == 0) ) then
print('Action required send data to email2 (Marianne en Paul)')
domoticz.log('No Motion detected for ' .. grace2 ..' minutes, sending alert', domoticz.LOG_INFO)
domoticz.data.msg2sent = 1 -- message2 sent indicator
print('domoticz.data.msg2sent (s/b 1): ' .. domoticz.data.msg2sent)
-- send message to paul en marianne
domoticz.email('Geen beweging van Rob', 'De computer heeft Rob al ' .. grace2 .. ' minuten niet gezien', email2 )
end -- if (domoticz.data.Motion.maxSince(grace2) = 0
end -- if (item.IsDevice )
end -- if domoticz.devices('iPhone-R').state == 'On'
--print('Motion Script Ending')
end -- function(domoticz, item)
}
erem wrote: ↑Wednesday 03 February 2021 19:00
here is a different approach..
Maybe I am overlooking something but to solve the gardenlight/ motion issue of @RezaRose it should be possible to just code it like below.
assuming the initial state is that the garden lights are On / Mixed.
return
{
on =
{
devices =
{
'Buitensensor',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'motion',
},
execute = function(dz, item)
local lights = dz.groups('Tuinverlichting')
local timeout = 300 -- timeout in seconds
if item.active and lights.state ~= 'Off' then
lights.switchOff().afterSec(timeout) -- this is also an implicit cancelQueuedCommands() for this device
end
end
}
I have tried your version. With .afterMinutes. It does not work properly because it only activates when the sensor is detecting motion.
Maybe i can fix it with a variable that update +1 when te timer get on 4 min or above. And if the variable gets on 2 the lights go off. So that is between 5 or 8 min then. And that is fine.
Raspberry Pi 4 - Raspbian bullseye - Python 3.9 - stable
Dashticz on apache2 - Mqqt - node red
Zigate - USB Tll - Philips hue - Ikea - Innr - Xiaomi - TPlink - Nest -v3
RezaRose wrote: ↑Wednesday 03 February 2021 21:37
I have tried your version. With .afterMinutes. It does not work properly because it only activates when the sensor is detecting motion.
OK.
Below version will also be triggered when the group is switched.
return
{
on =
{
devices =
{
'Buitensensor',
},
groups =
{
'Tuinverlichting',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'motion',
},
execute = function(dz, item)
local lights = dz.groups('Tuinverlichting')
local sensor = dz.devices('Buitensensor')
local timeout = 300 -- timeout in seconds
if item.state ~= 'Off' and lights.state ~= 'Off' then
lights.switchOff().afterSec(timeout) -- this is also an implicit cancelQueuedCommands() for this device
end
end
}