Page 1 of 1

LUA script for Motion detector

Posted: Monday 27 March 2017 22:45
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.

Re: LUA script for Motion detector

Posted: Sunday 02 April 2017 7:42
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

Re: LUA script for Motion detector

Posted: Monday 03 April 2017 9:53
by mickeyr61
That did the trick! Thank you very much!