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
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.
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
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
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
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
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?
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
}