Motion sensor device - switch off after x minutes

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
paul402
Posts: 96
Joined: Monday 23 May 2016 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Motion sensor device - switch off after x minutes

Post 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.
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Motion sensor device - switch off after x minutes

Post 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)
Bugs bug me.
paul402
Posts: 96
Joined: Monday 23 May 2016 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Motion sensor device - switch off after x minutes

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest