The light stays on while there is movement.

Easy to use, 100% Lua-based event scripting framework.
Post Reply
ReWiG
Posts: 5
Joined: Sunday 14 October 2018 11:41
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

The light stays on while there is movement.

Post by ReWiG » 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?

User avatar
waaren
Posts: 1351
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The light stays on while there is movement.

Post by waaren » Wednesday 17 October 2018 0:58

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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

ReWiG
Posts: 5
Joined: Sunday 14 October 2018 11:41
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: The light stays on while there is movement.

Post by ReWiG » 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.

User avatar
waaren
Posts: 1351
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The light stays on while there is movement.

Post by waaren » Wednesday 17 October 2018 9:08

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.
Xmotion.log.png
loglines of one of my xiaomi motion sensors
Xmotion.log.png (68.88 KiB) Viewed 233 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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

ReWiG
Posts: 5
Joined: Sunday 14 October 2018 11:41
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: The light stays on while there is movement.

Post by ReWiG » Wednesday 17 October 2018 9:28

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.

User avatar
waaren
Posts: 1351
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The light stays on while there is movement.

Post by waaren » Wednesday 17 October 2018 9:57

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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests