two motion sensors together to active notification - solved [Solved]
Moderator: leecollings
two motion sensors together to active notification - solved
Hello!
I'm new and I'm still learning, but there's a lot of information and I can't find what I need.
I'm looking for a script for the notification to be sent to me only when there are 2 motion sensors that are active at the same time.
If sensor1 is activated and there is no movement on sensor2 for up to 3 seconds, do not send me a notification. If both sensors are activated, only then will a notification arrive. In this way I want to reduce the false effects of the sensors.
Tnx!
I'm new and I'm still learning, but there's a lot of information and I can't find what I need.
I'm looking for a script for the notification to be sent to me only when there are 2 motion sensors that are active at the same time.
If sensor1 is activated and there is no movement on sensor2 for up to 3 seconds, do not send me a notification. If both sensors are activated, only then will a notification arrive. In this way I want to reduce the false effects of the sensors.
Tnx!
Last edited by nalivikam on Thursday 19 May 2022 7:05, edited 1 time in total.
- heggink
- Posts: 980
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: two motion sensors together to active notification
The challenge is probably that your motion sensors may switch off within the 3 second window so you need some way of tracking that either sensor was on within the 3 second window. dzvents has a lastupdate attribute but there appear to be (?) issues with that for python plugins + it does not indicate what the last state is.
One way to go about it is to have 2 dummy motion sensors which get switched on if the corresponding motion sensor gets switched on. If you then set the off delay in the configuation of the dummy sensor to 3 seconds, it will stay on for 3 seconds. You can then wite a simple script that gets triggered if both are on. You also need a script that switches the dummy on if one of the motion sensors is on.
This would be one way to do this.
One way to go about it is to have 2 dummy motion sensors which get switched on if the corresponding motion sensor gets switched on. If you then set the off delay in the configuation of the dummy sensor to 3 seconds, it will stay on for 3 seconds. You can then wite a simple script that gets triggered if both are on. You also need a script that switches the dummy on if one of the motion sensors is on.
This would be one way to do this.
Docker in Truenas scale, close to latest beta
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
-
- Posts: 153
- Joined: Wednesday 02 October 2019 11:47
- Target OS: Linux
- Domoticz version: 2023.1
- Location: DE / BY / LT
- Contact:
Re: two motion sensors together to active notification
I did something similar with node-red by using a join node that will trigger the alarm, if 2 motions are detected in a certain period of time (to avoid false positives).
Re: two motion sensors together to active notification
I would like to ask someone if they can help me with the code? I tried to search for topics for similar projects already done, but I did not find exactly such code.
I ask for help!
I ask for help!
- heggink
- Posts: 980
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: two motion sensors together to active notification
Try this (NOT TESTED!!!):
Say your 2 motion sensors are called M1 and M2
Create dummy hardware under hardware
Then create 2 switch devices under that dummy hardware and call them DM1 and DM2
Go to the switches tab and edit first DM1 and then DM2 as follows: enter 3 in the off delay field and save
You now have the 2 dummy devices that will switch off after 3 seconds when switched on.
Now let's write a simple dzvents script that switches them on if the motion sensor is triggered:
You now have a script that switches the dummy devices on if based on the motion sensors
Now the script that triggers if both are on:
This is just one very simple approach. There are many more (sophisticated) ways to do this. You can remane DM1 and DM2 to $DM1 and $DM2 (everywhere!!) and then they will not show up in the devices list.
Say your 2 motion sensors are called M1 and M2
Create dummy hardware under hardware
Then create 2 switch devices under that dummy hardware and call them DM1 and DM2
Go to the switches tab and edit first DM1 and then DM2 as follows: enter 3 in the off delay field and save
You now have the 2 dummy devices that will switch off after 3 seconds when switched on.
Now let's write a simple dzvents script that switches them on if the motion sensor is triggered:
Code: Select all
return {
on = {
devices = { 'M1', 'M2' }
},
execute = function(dz, dev)
if (dev.active) then
if (dev.name == 'M1') then
dz.devices('DM1').switchOn()
else
dz.devices('DM2').switchOn()
end
end
end
}
Now the script that triggers if both are on:
Code: Select all
return {
on = {
devices = { 'DM1', 'DM2' }
},
execute = function(dz, dev)
if (dev.state == 'On' and dz.devices('DM1').state == 'On' and dz.devices('DM1').state == 'On') then
-- do whatever you need to do
end
end
}
Docker in Truenas scale, close to latest beta
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Re: two motion sensors together to active notification
Thank you very much for your time and help with the code!heggink wrote: โThursday 21 April 2022 13:47 Try this (NOT TESTED!!!):
Say your 2 motion sensors are called M1 and M2
Create dummy hardware under hardware
Then create 2 switch devices under that dummy hardware and call them DM1 and DM2
Go to the switches tab and edit first DM1 and then DM2 as follows: enter 3 in the off delay field and save
You now have the 2 dummy devices that will switch off after 3 seconds when switched on.
Now let's write a simple dzvents script that switches them on if the motion sensor is triggered:
You now have a script that switches the dummy devices on if based on the motion sensorsCode: Select all
return { on = { devices = { 'M1', 'M2' } }, execute = function(dz, dev) if (dev.active) then if (dev.name == 'M1') then dz.devices('DM1').switchOn() else dz.devices('DM2').switchOn() end end end }
Now the script that triggers if both are on:
This is just one very simple approach. There are many more (sophisticated) ways to do this. You can remane DM1 and DM2 to $DM1 and $DM2 (everywhere!!) and then they will not show up in the devices list.Code: Select all
return { on = { devices = { 'DM1', 'DM2' } }, execute = function(dz, dev) if (dev.state == 'On' and dz.devices('DM1').state == 'On' and dz.devices('DM1').state == 'On') then -- do whatever you need to do end end }
But I think I still have a problem. Something is wrong. Maybe I'm mistaken somewhere or?
https://youtu.be/bbm3YOpMLfk
Each works individually and sends a notification. They are still independent of each other.
I made a video so you can better see how they work.
Have I missed an option somewhere to choose?
Re: two motion sensors together to active notification
I lost hope today!
I thought someone could help, but it took so long and no one could help me!
Every day I check if someone has given a working code, but no one has written. How to make the code so that the notification works only when there are 2 sensors activated.
I thought someone could help, but it took so long and no one could help me!
Every day I check if someone has given a working code, but no one has written. How to make the code so that the notification works only when there are 2 sensors activated.
Re: two motion sensors together to active notification
Could you try this: (Tested with dummy light switches)nalivikam wrote: โMonday 09 May 2022 22:47 I lost hope today!
I thought someone could help, but it took so long and no one could help me!
Every day I check if someone has given a working code, but no one has written. How to make the code so that the notification works only when there are 2 sensors activated.
(Edit1: simpler version. Edit2: forgot to 'or')
Code: Select all
return {
on = {
devices = {'Sensor1',
'Sensor2'},
},
data = {},
logging = {},
execute = function(dz, trigger)
if trigger.isDevice and
(dz.devices('Sensor1').active or
dz.devices('Sensor2').active) and
(dz.devices('Sensor1').lastUpdate.secondsAgo < 4 or
dz.devices('Sensor2').lastUpdate.secondsAgo < 4 )
then
print('================> Both sensors ON within 3 seconds window')
end
end
}
Re: two motion sensors together to active notification
Hello! First of all, let me express my gratitude for the help you are giving me!plugge wrote: โTuesday 10 May 2022 13:19Could you try this: (Tested with dummy light switches)nalivikam wrote: โMonday 09 May 2022 22:47 I lost hope today!
I thought someone could help, but it took so long and no one could help me!
Every day I check if someone has given a working code, but no one has written. How to make the code so that the notification works only when there are 2 sensors activated.
(Edit1: simpler version. Edit2: forgot to 'or')Code: Select all
return { on = { devices = {'Sensor1', 'Sensor2'}, }, data = {}, logging = {}, execute = function(dz, trigger) if trigger.isDevice and (dz.devices('Sensor1').active or dz.devices('Sensor2').active) and (dz.devices('Sensor1').lastUpdate.secondsAgo < 4 or dz.devices('Sensor2').lastUpdate.secondsAgo < 4 ) then print('================> Both sensors ON within 3 seconds window') end end }
But I still can't stop notifications coming from 1 device.
I followed your code, but maybe I'm missing something. Someone option may need to be included or the path of the code to specify?
I don't know where the mistake is. The code does not generate any error, but still receives notification from only one sensor / switch.
Would you look at the video I made so we could finish the project?!
This is my setting and script => https://youtu.be/nVjCk2Sbmps
This step is very important to me!
Thanks!
- heggink
- Posts: 980
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: two motion sensors together to active notification
There was a typo in my second script where it chedcked for DM1 twice instead of testing for DM1 and DM2:
I tested it myself and it works.
Code: Select all
return {
on = {
devices = { 'DM1', 'DM2' }
},
execute = function(dz, dev)
if (dev.state == 'On' and dz.devices('DM1').state == 'On' and dz.devices('DM2').state == 'On') then
-- do whatever you need to do
end
end
}
Docker in Truenas scale, close to latest beta
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Re: two motion sensors together to active notification
to understand! now I saw the mistake too, but I think it should be as it is written. so I just copied it.
changed DM1 to DM2. just like you say change it!
upload a screenshot to take a look please.
please take a look at my settings as well. do I have to describe the path of the script somewhere or something else?
I still receive notifications from only one sensor.
looking at the logos there is no mistake. maybe I missed something somewhere. if I have to shoot somewhere else some setting?
changed DM1 to DM2. just like you say change it!
upload a screenshot to take a look please.
please take a look at my settings as well. do I have to describe the path of the script somewhere or something else?
I still receive notifications from only one sensor.
looking at the logos there is no mistake. maybe I missed something somewhere. if I have to shoot somewhere else some setting?
Re: two motion sensors together to active notification
more 3 pics
- Attachments
-
- d55.png (215.83 KiB) Viewed 1803 times
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: two motion sensors together to active notification [Solved]
Your mistake is activating notifications for each switch.
You need to add a notification in the script, or add a third virtual switch that will turn on when the first two are ON
Then the third switch may have an active notification
DM1 = no notifications
DM2 = no notifications
DM3 = notification but then DM1 and DM2 = ON
or This script is what colleagues suggest but
You need to add a notification in the script, or add a third virtual switch that will turn on when the first two are ON
Then the third switch may have an active notification
DM1 = no notifications
DM2 = no notifications
DM3 = notification but then DM1 and DM2 = ON
or This script is what colleagues suggest but
Code: Select all
return {
on = {
devices = { 'DM1', 'DM2' }
},
execute = function(dz, dev)
if (dev.state == 'On' and dz.devices('DM1').state == 'On' and dz.devices('DM2').state == 'On') then
dz.notify('Two switch open', dz.PRIORITY_HIGH)
end
end
}
Last edited by besix on Monday 16 May 2022 20:36, edited 2 times in total.
- heggink
- Posts: 980
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: two motion sensors together to active notification
Exactly! In the script, replace:
with something like:
That should be enough. Get rid of the other notifications.
Find all the info here: https://www.domoticz.com/wiki/DzVents:_ ... terface.29
Code: Select all
-- do whatever you need to do
Code: Select all
dz.notify('Domoticz notification', 'Both sensors were active', dz.PRIORITY_HIGH)
Find all the info here: https://www.domoticz.com/wiki/DzVents:_ ... terface.29
Docker in Truenas scale, close to latest beta
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Re: two motion sensors together to active notification - solved
Thanks for all !!!
Finally my problem is fixed.
Finally my problem is fixed.
- heggink
- Posts: 980
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: two motion sensors together to active notification - solved
Wonderful. Hope you learnt some new (dzvents) skills in the process
.

Docker in Truenas scale, close to latest beta
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ ๐
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Re: two motion sensors together to active notification - solved
Of course! That I'm going to hit my head a lot.
Good thing it was you. If it weren't for you, I wouldn't be able to accomplish my task. Every day I hoped someone would help. Be good people and help people like me.
God bless you!

Who is online
Users browsing this forum: No registered users and 1 guest