Page 1 of 1
The light stays on while there is movement.
Posted: Tuesday 16 October 2018 23:16
by ReWiG
I have a xiaomi motion sensor and a lamp. I want to turn on the lamp when motion is detected and turn it off only when the movement stops. But I can not. Can you help me write a script dzvents?
Re: The light stays on while there is movement.
Posted: Wednesday 17 October 2018 0:58
by waaren
ReWiG wrote: ↑Tuesday 16 October 2018 23:16
I have a xiaomi motion sensor and a lamp. I want to turn on the lamp when motion is detected and turn it off only when the movement stops. But I can not. Can you help me write a script dzvents?
This is almost the same as one of the examples on the
wiki
-
Code: Select all
- XMotion
local motionDetector = 670 -- device idx of your motion detector
local light = 535 -- device idx of your light
return {
on = { devices = { motionDetector }}, -- your motion detector
execute = function(dz, XMotion)
if XMotion.state == "On" then
dz.devices(light).switchOn().checkFirst()
else
dz.devices(light).switchOff().checkFirst()
end
end
}
Re: The light stays on while there is movement.
Posted: Wednesday 17 October 2018 8:03
by ReWiG
I do not have the opportunity to check now, but I think that it does not work. I used the condition
Code: Select all
"if (device.state == 'Off') then devices.switchOn ()"
end instead of checkFirst () and it did not work. The fact is that the xiaomi sensor regains its state at least once a minute. That is, what happens is: Motion is detected, the sensor changes to the On state, the lamp turns on. Then exactly 1 minute it burns. All this time in the area of the sensor movement occurs. Further, when 1 minute expires, the sensor goes to the Off state and immediately again to the On state. Accordingly, the lamp turns off first and then turns on again. I would not want this to happen, I would like it to burn continuously as long as there is movement.
Re: The light stays on while there is movement.
Posted: Wednesday 17 October 2018 9:08
by waaren
ReWiG wrote: ↑Wednesday 17 October 2018 8:03
I do not have the opportunity to check now, but I think that it does not work. I used the condition
Code: Select all
"if (device.state == 'Off') then devices.switchOn ()"
end instead of checkFirst () and it did not work. The fact is that the xiaomi sensor regains its state at least once a minute. That is, what happens is: Motion is detected, the sensor changes to the On state, the lamp turns on. Then exactly 1 minute it burns. All this time in the area of the sensor movement occurs. Further, when 1 minute expires, the sensor goes to the Off state and immediately again to the On state. Accordingly, the lamp turns off first and then turns on again. I would not want this to happen, I would like it to burn continuously as long as there is movement.
Not sure if it is the
same sensor and if something can be configured in these sensors but the log of my xiaomi motion sensor does not show the behavior that you describe.

- loglines of one of my xiaomi motion sensors
- Xmotion.log.png (68.88 KiB) Viewed 887 times
But maybe for your situation this works better.
Code: Select all
-- XMotion
local motionDetector = 70 -- device idx of your motion detector
local lightID = 71 -- device idx of your light
return {
on = { devices = { motionDetector }}, -- your motion detector
execute = function(dz, XMotion)
local light = dz.devices(lightID)
if XMotion.state == "On" then
if light.state ~= "On" then
light.cancelQueuedCommands()
light.switchOn()
end
else
light.switchOff().afterSec(30)
end
end
}
Re: The light stays on while there is movement.
Posted: Wednesday 17 October 2018 9:28
by ReWiG
I use this sensor
https://www.gearbest.com/alarm-systems/pp_659226.html
It shows this behavior
https://yadi.sk/i/_scN-UYlXlaGDw https://yadi.sk/i/VU-6Zcxbi7sxfg That is, it turns on, turns off and on again after a minute. At the same time, in the sensor settings, I have this
https://yadi.sk/i/Aq-JS0M3Fywy-A. If the shutdown delay is set to 0, then it will work every 2 minutes, and it takes a very long time.
Re: The light stays on while there is movement.
Posted: Wednesday 17 October 2018 9:57
by waaren
The setting in the Off delay field explains why you see a different behavior. If you leave that out the sensor.state won't go to "Off" while there is movement detected.
So if you want to keep that Off delay of 60 seconds you should use the 2nd script. If you take it out the first script will do.