Ideas on how to do this?

Moderator: leecollings

Post Reply
User avatar
C4rtm4N
Posts: 53
Joined: Saturday 07 February 2015 21:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: UK
Contact:

Ideas on how to do this?

Post by C4rtm4N »

I've come across a small problem that I'm struggling to come up with a solution for so thought it worth asking you guys for help.

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
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests