LUA script for Motion detector

Moderator: leecollings

Post Reply
mickeyr61
Posts: 22
Joined: Thursday 19 May 2016 11:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

LUA script for Motion detector

Post by mickeyr61 »

I use the following script for the motion detector (from the Wiki)

Code: Select all

-- ~/domoticz/scripts/lua/script_device_PIRs.lua
 
commandArray = {}
 
tc=next(devicechanged)
v=tostring(tc)
if (v:sub(1,3) == 'PIR') then
    c=v:sub(4)
    commandArray[c] = 'On'
    tmess = c..' On - time 0'
    print(tmess)
end
 
return commandArray
When there is a motion, a dummy switch is set to ON, I use another script to turn it off after a couple of minutes. Now the following happens: someone crosses the motion the detector, the virtual switch is set to ON, now this person moves for the sensor and the script is sending the ON command again. I would like to send the ON signal just once. I am not so experienced in LUA scripting, so any help is appreciated.
gerard76
Posts: 53
Joined: Wednesday 22 March 2017 9:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: LUA script for Motion detector

Post by gerard76 »

So, you want to turn it on only when it's off:

Code: Select all

if otherdevices[c] == 'Off' then
  commandArray[c] = 'On'
end
mickeyr61
Posts: 22
Joined: Thursday 19 May 2016 11:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA script for Motion detector

Post by mickeyr61 »

That did the trick! Thank you very much!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests