The light stays on while there is movement.
Moderator: leecollings
-
- Posts: 3
- Joined: Sunday 14 October 2018 11:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
The light stays on while there is movement.
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?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: The light stays on while there is movement.
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 3
- Joined: Sunday 14 October 2018 11:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: The light stays on while there is movement.
I do not have the opportunity to check now, but I think that it does not work. I used the condition 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.
Code: Select all
"if (device.state == 'Off') then devices.switchOn ()"
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: The light stays on while 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. But maybe for your situation this works better.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 conditionend 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.Code: Select all
"if (device.state == 'Off') then devices.switchOn ()"
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 3
- Joined: Sunday 14 October 2018 11:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: The light stays on while there is movement.
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.
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.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: The light stays on while there is movement.
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.
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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest