Page 1 of 1

(Solved) Extend switchOff time after movement

Posted: Sunday 18 December 2022 8:21
by Bospieper
Hello, I have a room with three lights and a motion sensor. After movement, the lamps switch on for a certain time. The motion sensor has a reset time of 2 minutes. I would like that, when in the switch-off time there is movement and the reset time is over, the switch-off time is automatically extended.
Grz. Piet

Code: Select all

	local sensor = dz.devices('Badkamersensor')
		local lamp1A = dz.devices('Badkamer- lamp1A')
		local lamp1B = dz.devices('Badkamer- lamp1B')
		local lamp1C = dz.devices('Badkamer- lamp1C')
		
		if sensor.active and dz.time.matchesRule('between 05:30 and 07:30') then
		    lamp1C.switchOn()
		    lamp1C.switchOff().afterMin(4)
		    end
		if sensor.active and dz.time.matchesRule('between 07:30 and 11:30') then
		    lamp1C.switchOn()
		    lamp1B.switchOn()
		    lamp1A.switchOn()
		    lamp1C.switchOff().afterMin(6)
		    lamp1B.switchOff().afterMin(6)
		    lamp1A.switchOff().afterMin(6)
		    end

Re: Extend switchOff time after movement

Posted: Sunday 18 December 2022 20:03
by waltervl
It should do this already with this script.
If sensor is the trigger it will again do the switchOff.afterMin.

Re: Extend switchOff time after movement

Posted: Sunday 18 December 2022 20:38
by Bospieper
Hi Waltervl,
In this example the lights go off after 4 minutes when no movement is detected. The sensor is after 2 minutes ready to see new movements.
When in the timelaps of four minutes movement is detected the lights go off after four minutes and after the fifth minute movement from the sensor wil switch the lights on for another four minutes. So detection within the four minutes is ignored and that is what I wanted to change in the script.
Piet

Re: Extend switchOff time after movement

Posted: Sunday 18 December 2022 21:54
by waltervl
You should check the log as after say 3 minutes you enter the room the lights will switch on (are already on) and a new afterMin will be set. You can check the log to see if the switch0n is logged.

If not then the script is not triggered correctly.

Re: Extend switchOff time after movement

Posted: Monday 19 December 2022 21:30
by Bospieper
waltervl wrote: Sunday 18 December 2022 21:54 You should check the log as after say 3 minutes you enter the room the lights will switch on (are already on) and a new afterMin will be set. You can check the log to see if the switch0n is logged.

If not then the script is not triggered correctly.
Hi Waltervl, thanks for your suggestion. I found that when I am staying in the room and keep moving the Lidl Motion sensor not reset itself after 2 minutes. When I activate the sensor and leaving the room then the sensor resets after 2 minutes. So the problem is the type sensor I use.
I've tested it with several the same sensors they all show the same behavior.
My following question is, is there a programming solution for this?
Grz.Piet

Re: Extend switchOff time after movement

Posted: Tuesday 20 December 2022 0:32
by waltervl
It is perhaps possible to set that switch off behavior on the zigbee2mqtt parameters. But for these lidl devices not possible it seems. https://www.zigbee2mqtt.io/devices/HG06335_HG07310.html

Alternative is to check every minute if the sensor shows motion and if so set the afterMin. When sensor has no motion then the last afterMin will become active.

Re: Extend switchOff time after movement

Posted: Tuesday 20 December 2022 19:05
by Bospieper
waltervl wrote: Tuesday 20 December 2022 0:32 It is perhaps possible to set that switch off behavior on the zigbee2mqtt parameters. But for these lidl devices not possible it seems. https://www.zigbee2mqtt.io/devices/HG06335_HG07310.html

Alternative is to check every minute if the sensor shows motion and if so set the afterMin. When sensor has no motion then the last afterMin will become active.
Here's my complete script, can you tell me where to adjust it?

Code: Select all

return {
	on = {
		devices = {
			'Badkamersensor'
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'Badkamer',
	},
	execute = function(dz,domoticz,device)
		
		
		local sensor = dz.devices('Badkamersensor')
		local lamp1A = dz.devices('Badkamer- lamp1A')
		local lamp1B = dz.devices('Badkamer- lamp1B')
		local lamp1C = dz.devices('Badkamer- lamp1C')
		
		if sensor.active and dz.time.matchesRule('between 05:30 and 07:30') then
		    lamp1C.switchOn()
		    lamp1C.switchOff().afterMin(4)
		    end
		if sensor.active and dz.time.matchesRule('between 07:30 and 11:30') then
		    lamp1C.switchOn()
		    lamp1B.switchOn()
		    lamp1A.switchOn()
		    lamp1C.switchOff().afterMin(6)
		    lamp1B.switchOff().afterMin(6)
		    lamp1A.switchOff().afterMin(6)
		    end
		 if sensor.active and dz.time.matchesRule('between 11:30 and 21:30') then
		    lamp1B.switchOn()
		    lamp1A.switchOn()
		    lamp1B.switchOff().afterMin(4)
		    lamp1A.switchOff().afterMin(4)
		    end
		 if sensor.active and dz.time.matchesRule('between 21:30 and 00:30') then
		     lamp1C.switchOn()
		     lamp1B.switchOn()
		     lamp1A.switchOn()
		     lamp1C.switchOff().afterMin(6)
		     lamp1B.switchOff().afterMin(6)
		     lamp1A.switchOff().afterMin(6)
		     end
		  if sensor.active and dz.time.matchesRule('between 00:30 and 05:30') then
		    lamp1C.switchOn()
		    lamp1C.switchOff().afterMin(1)
		  end
		    
		    
	end
}

Re: Extend switchOff time after movement

Posted: Tuesday 20 December 2022 19:42
by waltervl
Add timer trigger, for example

Code: Select all

on = {
		devices = {
			'Badkamersensor'
		},
		timer = { 'every minute' }
	},

Re: Extend switchOff time after movement

Posted: Tuesday 20 December 2022 20:01
by Bospieper
waltervl wrote: Tuesday 20 December 2022 19:42 Add timer trigger, for example

Code: Select all

on = {
		devices = {
			'Badkamersensor'
		},
		timer = { 'every minute' }
	},
I will try it out, let you know.

(Solved) Extend switchOff time after movement

Posted: Tuesday 20 December 2022 20:16
by Bospieper
Hi Waltervl, it works :D :!:
Thanks for your suggestions.
Grz Piet

Re: Extend switchOff time after movement

Posted: Tuesday 20 December 2022 20:29
by waltervl
You're welcome, happy showering in the enlightened bathroom!