Hi,
This is the code which I expect that has now and then failures due to timing
------------------------------------------------------------------------------------------------------------------------
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, s=Dummy switch set in Domoticz which
-- has to be on for the PIR to operate - Dummy-SwitchName or Dummy-GroupName
-- custom-timers can be set by creating a timed dummy switch in Domoticz
-- 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 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 = {}
tc = next(devicechanged)
if (tc == 'Bew1-trap') or (tc == 'Bew2-trap') then
if timeofday['Daytime'] then
-- overdag het traplicht niet aan doen
return
end
-- tijdstip waarop lamp is aangezet
ccc = uservariables['TraplichtAanTijdstip']
-- aantal verstreken seconden sinds lamp is aangezet
x=timedifference(ccc)
-- als er weer een schakelcommando komt binnen 60 seconden na het eerste commando: doe verder niets
if x < 60 then
return
end
f=tostring(os.date('%Y-%m-%d %H:%M:%S'))
commandArray ['Variable:TraplichtAanTijdstip']= (f)
-- licht werkt met bistabiel relais ; bij 1e commando gaat licht aan; bij 2e uit
commandArray['Lamp-Trap'] = 'On REPEAT 2 INTERVAL 60' -- command will be repeated 2 times with 60 seconds interval
end
return commandArray
--------------------------------------------------------
I'm sorry as I don't know how to put the code in a "code window"
Remarks are in dutch language.
Brief explanation:
I have a lighting for the stairs which is controlled by a so called bi-stable relay. That means that you give a short pulse to the relay coil to change the status of the relay contacts.
And another pulse for changing the status again.
I have two movement-sensor (433Mhz) (Bew1 and Bew2) once there is one of them activated the light (Lamp-trap) goes on.
But sometimes it seems that (due to timing ?) the function of the relay has been inverted so once the sensor is activated the light goes off and after the requested "on "time the relay goes on iso off.
Any idea this is timing problem or something others?
TIA
-Bart