(Solved) Extend switchOff time after movement

Moderator: leecollings

Post Reply
User avatar
Bospieper
Posts: 166
Joined: Thursday 07 November 2019 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: NL
Contact:

(Solved) Extend switchOff time after movement

Post 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
Last edited by Bospieper on Tuesday 20 December 2022 20:35, edited 1 time in total.
User avatar
waltervl
Posts: 5384
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Extend switchOff time after movement

Post by waltervl »

It should do this already with this script.
If sensor is the trigger it will again do the switchOff.afterMin.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Bospieper
Posts: 166
Joined: Thursday 07 November 2019 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: NL
Contact:

Re: Extend switchOff time after movement

Post 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
User avatar
waltervl
Posts: 5384
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Extend switchOff time after movement

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Bospieper
Posts: 166
Joined: Thursday 07 November 2019 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: NL
Contact:

Re: Extend switchOff time after movement

Post 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
User avatar
waltervl
Posts: 5384
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Extend switchOff time after movement

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Bospieper
Posts: 166
Joined: Thursday 07 November 2019 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: NL
Contact:

Re: Extend switchOff time after movement

Post 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
}
User avatar
waltervl
Posts: 5384
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Extend switchOff time after movement

Post by waltervl »

Add timer trigger, for example

Code: Select all

on = {
		devices = {
			'Badkamersensor'
		},
		timer = { 'every minute' }
	},
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Bospieper
Posts: 166
Joined: Thursday 07 November 2019 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: NL
Contact:

Re: Extend switchOff time after movement

Post 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.
User avatar
Bospieper
Posts: 166
Joined: Thursday 07 November 2019 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: NL
Contact:

(Solved) Extend switchOff time after movement

Post by Bospieper »

Hi Waltervl, it works :D :!:
Thanks for your suggestions.
Grz Piet
User avatar
waltervl
Posts: 5384
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Extend switchOff time after movement

Post by waltervl »

You're welcome, happy showering in the enlightened bathroom!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests