Domoticz and a bit of LUA script have turned these Siemens wireless PIRs into the ultimate smart PIRs (tm)

that work with the LightwaveRF system
The Siemens wireless PIRs only send an on signal (detectd) but no off signal, so I had to write a couple of scripts to make them function more like normal PIRs and actually turn things on and then off after a set length of time - see previous posts.
I liked the idea of having a single script that interacted with all the PIRs such that I could add more PIRs without adding any extra script. So by associating each PIR with a Domoticz motion sensor called "PIR roomx" it would turn on lightswitch "roomx". Initially this meant that each PIR and light switch did exactly the same thing, so I settled on turning things on all the day for a set length of time. However, having posted the script here and on the LightwaveRFcommunity.org.uk forum, then other people suggested why couldn't they control groups or only control at certain times.
So I have now extended the scripts to create the ultimate smart PIR (tm)
Each of the motion sensors in Domoticz follow this name convention:
PIRxyzSwitchName or PIRxyzGroupName
x speicifies when the PIR controls - a=all day, n=nighttime, d=daytime, 1=custom timer 1 set to 22:00 to 07:30
y specifies what the PIR is controlling - r = room (single Domoticz) switch and g = group
z specifies how long the ligth will stay on for in minutes, so z =5 turns the switch or the group on for 5 minutes, or u = don't turn off ever
So to use and install just place the two scripts in ~/domoticz/scripts/lua, then create your correctly named PIRs and you will have the ultimate smart PIR (tm)

system.
script_device_pirs.lua
Code: Select all
-- ~/domoticz/scripts/lua/script_device_pirs.lua
-- Each of the motion sensors in Domoticz follow this name convention:
-- PIRxyzSwitchName or PIRxyzGroupName
-- x speicifies when the PIR controls - a=all day, n=nighttime, d=daytime, 1=custom timer 1 set to 22:00 to 07:30
-- y specifies what the PIR is controlling - r = room (single Domoticz) switch and g = group
-- z specifies how long the ligth will stay on for in minutes, so z =5 turns the switch or the group on for 5 minutes, or u = don't turn off ever
-- N.B. be carefully as currently there is little error checking so wrongly named PIRs in Domoticz may cause an error
-- N.B. one wrongly named PIR may stop the script, check log for any issues
function timetest(opertime)
if opertime == "a" then
return true
end
if opertime == "n" then
if timeofday['Nighttime'] then
return true
else
return false
end
end
if opertime == "d" then
if timeofday['Daytime'] then
return true
else
return false
end
end
if opertime == "1" then
time = os.date("*t")
if ((time.hour <= 7) and (time.min <= 30)) or (time.hour >= 22) then
return true
else
return false
end
end
return false
end
commandArray = {}
tc=next(devicechanged)
v=tostring(tc)
if (v:sub(1,3) == 'PIR') then
if timetest(v:sub(4,4)) then
c=v:sub(7)
if v:sub(5,5) == "g" then
c="Group:"..c
end
commandArray[c] = 'On'
tmess = c..' On - time 0'
print(tmess)
end
end
return commandArray
script_time_pirs.lua
Code: Select all
-- ~/domoticz/scripts/lua/script_device_pirs.lua
-- Each of the motion sensors in Domoticz follow this name convention:
-- PIRxyzSwitchName or PIRxyzGroupName
-- x speicifies when the PIR controls - a=all day, n=nighttime, d=daytime, 1=custom timer 1 set to 22:00 to 07:30
-- y specifies what the PIR is controlling - r = room (single Domoticz) switch and g = group
-- z specifies how long the ligth will stay on for in minutes, so z =5 turns the switch or the group on for 5 minutes, or u = don't turn off ever
-- N.B. be carefully as currently there is little error checking so wrongly named PIRs in Domoticz may cause an error
-- N.B. one wrongly named PIR may stop the script, check log for any issues
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
commandArray = {}
for i, v in pairs(otherdevices) do
tc = tostring(i)
v = i:sub(1,3)
if (v == 'PIR') then
onmode = i:sub(6,6)
if onmode ~= "u" then
timeon = (tonumber(onmode) * 60) - 1
difference = timedifference(otherdevices_lastupdate[tc])
if (difference > timeon and difference < (timeon + 60)) then
tempdiff = tostring(difference)
c = i:sub(7)
if i:sub(5,5) == "g" then
c="Group:"..c
end
tempmessage = c.." Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds"
print(tempmessage)
commandArray[c] = 'Off'
end
end
end
end
return commandArray
So please enjoy the ultimate smart PIR (tm)

system
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266