--this script will turn of the light at the second living room when there is x min no movement detected on the Motion Sensor.
--The script does run and it sometime works, like once or twice a day. but it has to work always, I can't figure out why it is not working.
t1 = os.time()
s = otherdevices_lastupdate['Motion']
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))
print(difference)
if (otherdevices['Motion'] == 'On' and difference > 60 and difference < 200) then
commandArray['Light']= 'Off'
print('2 minutes no movement, turn off Light 2th Living Room')
end
return commandArray