i have a x10 motion sensor, wich works with the 'normal' PIR lua script.
It goes on, and off after 60 seconds.
But, i just want to do it only when it is dark, but what i'm just doing, its not gonna work.
I use the script_time_PIRs.lua and the script_device_PIRs.lua as seen in the Wiki.
Also i've struggeling with the "Reacting to a Dummy Switch" part, wich is also not working.
The light is going on, but never goes off anymore.
Also there is no "monitoring" of what the lua is doing.
If i turn off the light by hand, and it's switched on when motion is detected, it's not going off anymore

This are my scripts:
Code: Select all
-- ~/domoticz/scripts/lua/script_device_pirs.lua
-- Each of the motion sensors in Domoticz follow this name convention:
-- PIRxrzSwitchName or PIRxgzGroupName
-- 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
-- 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 customtest(nowhours, nowmins, starthours, startmins, endhours, endmins)
nowmins = nowmins + (nowhours * 60)
startmins = startmins + (starthours * 60)
endmins = endmins + (endhours * 60)
if (startmins > endmins) then
-- spans midnight
if ((nowmins >= startmins) or (nowmins <= endmins)) then
return true
else
return false
end
else
-- doesn't span midnight
if ((nowmins >= startmins) and (nowmins <= endmins)) then
return true
else
return false
end
end
end
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 == "s" then
if (otherdevices['HetisDonker'] == "On") then
return true
else
return false
end
end
if opertime == "1" then
time = os.date("*t")
return customtest(time.hour, time.min, 22, 0, 7, 30)
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
Code: Select all
-- ~/domoticz/scripts/lua/script_time_PIRs.lua
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
timeon = 240
tc = tostring(i)
v = i:sub(1,3)
if (v == 'PIR') then
difference = timedifference(otherdevices_lastupdate[tc])
if (difference > timeon and difference < (timeon + 60)) then
tempdiff = tostring(difference)
c = i:sub(4)
tempmessage = c.." Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds"
print(tempmessage)
commandArray[c] = 'Off'
end
end
end
return commandArray
switch named as Trap
Thanks!