Two motion sensors for one lamp

There are two (or more?) motion sensors and one lamp in one room. How to make the lamp turn off only if both sensors do not detect movement? But it may be that only one sensor will see the movement. So from the second sensor the signal "no movement" will not come.

There are many ways you could do this and here is one.

Save the state of each sensor and then test them all. If the sensor sees motion, it sets it's value to 1 otherwise it sets it to 0 so if you have three sensors and sensor 2 notices movement you would have:
sensor1 = 0
sensor2 = 1
sensor3 = 0
if you add the values of the three up and it is greater than 0 turn on the light, if it equals 0 shut off the light. In this case the total is 1 so the light turns on.

1 Like

You mean context flow?

or just feed the movement detected from all into a trigger node set to whatever timeout you like - and extended by any input signal.

1 Like

Thank you. Not sure if I understood you correctly. I don't think this will work as it should. Could you make an example?

Why don't you try to do it and see what you end up with?

If this is about your idea, context flow, I'm sure it will work. I don't understand how to implement the idea from dceejay

Again try it. Play with the trigger node and see how it works

So far I have been able to make such an example. It works. But I think it's too complicated.

[{"id":"2da6a6319c628b8d","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"fe3b155cbf8835cf","type":"inject","z":"2da6a6319c628b8d","name":"Sensor1 On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["aae7ec2de8a80577"]]},{"id":"78a66c2fac9e59ef","type":"switch","z":"2da6a6319c628b8d","name":"","property":"$flowContext('Sensor1')+ $flowContext('Sensor2')\t\t","propertyType":"jsonata","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":180,"wires":[["463d56234ac9cedc"],["423ddf8967082c0c"]]},{"id":"aae7ec2de8a80577","type":"change","z":"2da6a6319c628b8d","name":"","rules":[{"t":"set","p":"Sensor1","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":100,"wires":[["78a66c2fac9e59ef"]]},{"id":"a4e2dc2053d33a51","type":"inject","z":"2da6a6319c628b8d","name":"Sensor1 Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":160,"wires":[["5a5cb5c05853e998"]]},{"id":"08fe5d589339de1f","type":"inject","z":"2da6a6319c628b8d","name":"Sensor2 On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":220,"wires":[["f078c65f0cd30c5c"]]},{"id":"a20b8577fc59325e","type":"inject","z":"2da6a6319c628b8d","name":"Sensor2 Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":280,"wires":[["3d223032dc5ddc44"]]},{"id":"5a5cb5c05853e998","type":"change","z":"2da6a6319c628b8d","name":"","rules":[{"t":"set","p":"Sensor1","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":160,"wires":[["78a66c2fac9e59ef"]]},{"id":"f078c65f0cd30c5c","type":"change","z":"2da6a6319c628b8d","name":"","rules":[{"t":"set","p":"Sensor2","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":220,"wires":[["78a66c2fac9e59ef"]]},{"id":"3d223032dc5ddc44","type":"change","z":"2da6a6319c628b8d","name":"","rules":[{"t":"set","p":"Sensor2","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":280,"wires":[["78a66c2fac9e59ef"]]},{"id":"463d56234ac9cedc","type":"debug","z":"2da6a6319c628b8d","name":"ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":140,"wires":[]},{"id":"423ddf8967082c0c","type":"debug","z":"2da6a6319c628b8d","name":"OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":220,"wires":[]}]

Simplified a little

[{"id":"2da6a6319c628b8d","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"fe3b155cbf8835cf","type":"inject","z":"2da6a6319c628b8d","name":"Sensor1 On","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"filename","v":"Sensor1","vt":"flow"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":100,"wires":[["aae7ec2de8a80577"]]},{"id":"78a66c2fac9e59ef","type":"switch","z":"2da6a6319c628b8d","name":"","property":"$flowContext('Sensor1')+ $flowContext('Sensor2')\t\t","propertyType":"jsonata","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":180,"wires":[["463d56234ac9cedc"],["423ddf8967082c0c"]]},{"id":"aae7ec2de8a80577","type":"change","z":"2da6a6319c628b8d","name":"","rules":[{"t":"set","p":"Sensor1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":140,"wires":[["78a66c2fac9e59ef"]]},{"id":"a4e2dc2053d33a51","type":"inject","z":"2da6a6319c628b8d","name":"Sensor1 Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":130,"y":160,"wires":[["aae7ec2de8a80577"]]},{"id":"08fe5d589339de1f","type":"inject","z":"2da6a6319c628b8d","name":"Sensor2 On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":220,"wires":[["d4d58edff41df973"]]},{"id":"a20b8577fc59325e","type":"inject","z":"2da6a6319c628b8d","name":"Sensor2 Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":130,"y":280,"wires":[["d4d58edff41df973"]]},{"id":"463d56234ac9cedc","type":"debug","z":"2da6a6319c628b8d","name":"ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":140,"wires":[]},{"id":"423ddf8967082c0c","type":"debug","z":"2da6a6319c628b8d","name":"OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":220,"wires":[]},{"id":"d4d58edff41df973","type":"change","z":"2da6a6319c628b8d","name":"","rules":[{"t":"set","p":"Sensor2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":240,"wires":[["78a66c2fac9e59ef"]]}]

Trying to undersstand your problem with @dceejay's suggetion...
Are your motion sensors PIR modules?

Some of these have two modes: "normal" and "retriggering".

It's probably best for Node-red use to have normal mode, where continuous movement results in repeated messages.

If your sensors are like this, you can feed all the messages into a trigger node set to send ON and send OFF after say 5 minutes unless another message arrives.

But if they are set to retriggering, you might not get another messsage despite the movement continuing.

Now I got it. My sensors are battery powered so they don't have repeated messages. So the trigger method won't work.
Is my example with context flow correct?

I don't see the relevance of battery power. Can you post a link to the type of sensor?

1 Like

My I suggest the Boolean logic node (node-red-contrib-boolean-logic)?
set it to AND with an invert after.

if not aware of the node:

It asks for the number of topics (and topic name): Sensor
each sensor passes it a boolean with a topic of Sensor# (1,2,3,4....)

operating in AND mode - the node will return true if all payloads (for each topic) are true
but then you can invert it.

the sensors inputs can arrive at different times - it doesn't need to come in as 1 big payload.

the moment a false is passed - it returns false (in AND mode)

I can't see why this should not work with a trigger node. And for some reason you seem to refuse to focusing on the given recommendations here.

See how it works:

1 Like

Thanks everyone. The variant with context flow works as I need.
The variant with trigger is not suitable, precisely because the messages from the sensors are not repeated. For example:
1.Sensor1 ON
2.Sensor 2 ON
3.Sensor 2 OFF
The lamp should not turn off.
The variant with boolean node also works. But for it to work after rebooting for the first time, all sensors must work at least once.

[{"id":"2da6a6319c628b8d","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"fe3b155cbf8835cf","type":"inject","z":"2da6a6319c628b8d","name":"Sensor1 On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Sensor1","payload":"false","payloadType":"bool","x":130,"y":100,"wires":[["3b577c0b94b14716"]]},{"id":"a4e2dc2053d33a51","type":"inject","z":"2da6a6319c628b8d","name":"Sensor1 Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Sensor1","payload":"true","payloadType":"bool","x":130,"y":160,"wires":[["3b577c0b94b14716"]]},{"id":"08fe5d589339de1f","type":"inject","z":"2da6a6319c628b8d","name":"Sensor2 On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Sensor2","payload":"false","payloadType":"bool","x":130,"y":220,"wires":[["3b577c0b94b14716"]]},{"id":"a20b8577fc59325e","type":"inject","z":"2da6a6319c628b8d","name":"Sensor2 Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Sensor2","payload":"true","payloadType":"bool","x":130,"y":280,"wires":[["3b577c0b94b14716"]]},{"id":"463d56234ac9cedc","type":"debug","z":"2da6a6319c628b8d","name":"ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":160,"wires":[]},{"id":"423ddf8967082c0c","type":"debug","z":"2da6a6319c628b8d","name":"OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":240,"wires":[]},{"id":"3b577c0b94b14716","type":"BooleanLogic","z":"2da6a6319c628b8d","name":"","operation":"AND","inputCount":"2","topic":"result","x":340,"y":200,"wires":[["6dee421c08fe25ec"]]},{"id":"6dee421c08fe25ec","type":"Invert","z":"2da6a6319c628b8d","name":"Invert","x":490,"y":200,"wires":[["a60d9e1d0f1d2917"]]},{"id":"a60d9e1d0f1d2917","type":"switch","z":"2da6a6319c628b8d","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":200,"wires":[["463d56234ac9cedc"],["423ddf8967082c0c"]]}]

@Leopoll

You may also use OR Gate from this Node Contrib

Give a discrete "Topic" name to each sensor.

1 Like

Great!. This is the easiest option.