In one of my rooms I have a zwave controlled lamp around 3m from the door. The lamp turns on automatically after sunset and off around 1am. Additionally when it's dark the lamp will turn on if someone walks into the room and activates my alarm system PIR. Finally if the alarm PIR isn't activated for 30 min the lamp will turn itself off even if it's before its normal scheduled time.
My problem is that my wife hates to leave the lamp to its own schedule and insists on turning it off at the switch which then means that as she walks to the door she sets if off again due to the PIR activating. I had intended on setting a check of a few seconds to not automatically reactivate the lamp with a PIR triggering but this would mean that if we were sitting in the room very still and the 'no activity' script was triggered I wouldn't be able to simply wave my hand to turn it immediately back on.
Ultimately I want to be able to set things so that if the lamp is turned off by inactivity, immediate activity will turn it back on but if it was turned off using the switch then it won't automatically reactivate within 1 minute.
My current PIR code is below, I reduced the time difference to 1 second for the moment, any ideas on how I can amend it to achieve what I want? I had thought about setting a user variable but how would I get that to reset after 1 minute without leaving the script running?
Code: Select all
t1 = os.time()
s = otherdevices_lastupdate['Lounge Lamp']
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 (devicechanged['PIR_Lounge'] == 'On')
then
print ("Time since lamp last on ".. difference)
if (otherdevices['Nighttime'] == 'On' and (otherdevices['Lounge Lamp'] == 'Off') and difference > 1)
then
commandArray['Lounge Lamp']='On'
print('Lounge Lamp Auto Activated')
end
end
return commandArray