Page 1 of 1

Motion sensor device - switch off after x minutes

Posted: Thursday 23 May 2024 6:06
by paul402
I have a pir detector setup as switch type motion sensor/off delay=0

Code: Select all

return {
    active = true,
    
   logging = {
            level = domoticz.LOG_DEBUG,
            marker = 'patio sensor' 
           },
        
    on = {
        timer = {'Every minute'}
    },

    
        execute = function(domoticz)

                --local movement sensor 1
                local patiosensor1 = domoticz.devices(3530)
                if (patiosensor1.state == 'On'  ) then
                    domoticz.log('set sensor 1 ON')
                end
	            
                if (patiosensor1.state == 'On' and patiosensor1.lastUpdate.minutesAgo >= 1 ) then
                    domoticz.log('set sensor 1 off')
                    patiosensor1.switchOff()    
                end
                
        end
}
There is no error in the log but the sensor is not switching off. It is covered so not being triggered.
I must have used an incorrect command but cannot see what. Any hints appreciated.

Re: Motion sensor device - switch off after x minutes

Posted: Thursday 23 May 2024 11:19
by HvdW
You execute the function every minute, so you can change te code to something like:
if domoticz.devices('patiosensor').state() == 'off'
domoticz.devices('patiolightswitch').switchOFF()
end
To be shure you won't endup sitting in the dark I'd suggest to change it to domoticz.devices('patiolightswitch').switchOFF().afterMin(3)

Re: Motion sensor device - switch off after x minutes

Posted: Thursday 23 May 2024 13:51
by paul402
OK I believe that I found what the problem is. The sensor doesn't send "off" and I think that it is not possible to force it off using Dzvents.
So I created a dummy sensor which is updated whenever an "on" signal is received and I can switch the dummy sensor off after x minutes.
The dummy sensor is only reset to on when a new "on" is received.
I used 1 minute delay only for testing.
I don't know if it is the best way to do it but it now works! I hope it helps someone else.
Now I can stop the shutters going down when people are on the patio!

Code: Select all

 execute = function(domoticz)

                --local movement sensor 1
                local patiosensor1 = domoticz.devices(3530)
                local patioswitch1 = domoticz.devices(3533)
                if (patiosensor1.state == 'On'  ) then
                    patioswitch1.switchOn() -- dummy
                    domoticz.log('set sensor 1 ON')
                end
	            
                if (patiosensor1.state == 'On' and patiosensor1.lastUpdate.minutesAgo >= 1 ) then
                    domoticz.log('set sensor 1 off')
                    -- patiosensor1.switchOff() 
                    patioswitch1.switchOff()
                end
                
        end
Thanks for all the suggestions.

Re: Motion sensor device - switch off after x minutes

Posted: Friday 24 May 2024 12:11
by BazemanKM