I have the following problem, I am unable to turn on the fan in the toilet when the lamp in the toilet is on for more than 2 minutes.
I now use a blockly where I can only set the fan to turn on after x number of seconds, but if the lamp is on for less than the set number of seconds, the fan will still turn on.
Now I have seen that with a LUA script you can control it better with the 'last seen' status of the lamp. But unfortunately I can't get this done ..

example script which I am currently using but does not work. :
Code: Select all
t1 = os.time ()
s = otherdevices_lastupdate ['WC']
- returns a date time like 2013-07-11 17:23:12
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)
commandArray = {}
t2 = os.time {year = year, month = month, day = day, hour = hour, min = minutes, sec = seconds}
difference = (os.difftime (t1, t2))
if (otherdevices ['WC'] == 'On' and difference> 120 and difference <130) then
commandArray ['ventilation'] = 'On'
end
return commandArray
Mark