Dual condition switch?

hello I am on home assistant and I start on node-red.
That's my problem. I have an IKEA on/off switch and an IKEA motion detector. I would like that when I press the switch to have "on" that the detector is taken into account.
And if I press the switch again to have "off" that I do not take into account the detector.

so if switch is "on" and the PIR is "on" the output is "on"
if switch is "on" and the PIR is "off" the output is "off"
if switch is "off" and the PIR is "on or off" the output is "off"

separately it works see pictures below


Try something like this

[{"id":"33a4a125.5feda6","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":80,"y":4360,"wires":[["134df535.05ce53"]]},{"id":"134df535.05ce53","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"switch","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":4380,"wires":[["6aaa15a2.03bc34"]]},{"id":"d3409c04.3ffeb","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":90,"y":4400,"wires":[["134df535.05ce53"]]},{"id":"6aaa15a2.03bc34","type":"join","z":"c791cbc0.84f648","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":4440,"wires":[["c20f2520.6eb15"]]},{"id":"79797e04.aaa64","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"sensor","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280.3333282470703,"y":4529.33349609375,"wires":[["6aaa15a2.03bc34"]]},{"id":"c20f2520.6eb15","type":"switch","z":"c791cbc0.84f648","name":"","property":"payload.sensor","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":560,"y":4440,"wires":[["54a388b.8fe3e78"],["9d735223.113ef8"]]},{"id":"3a6bf638.e95d32","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":80,"y":4520,"wires":[["79797e04.aaa64"]]},{"id":"e4b1fdaa.8dfee","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":90,"y":4560,"wires":[["79797e04.aaa64"]]},{"id":"54a388b.8fe3e78","type":"switch","z":"c791cbc0.84f648","name":"","property":"payload.switch","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":720,"y":4440,"wires":[["9f6af503.e8c52"],["9d735223.113ef8"]]},{"id":"9d735223.113ef8","type":"debug","z":"c791cbc0.84f648","name":"off","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":856.6666870117188,"y":4476.33349609375,"wires":[]},{"id":"9f6af503.e8c52","type":"debug","z":"c791cbc0.84f648","name":"on","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":4420,"wires":[]}]

To import, copy flow.json, press ctrl i in editor, paste flow.json, and click import

It sounds like you just need to store the value of the switch state in a flow.variable.
Then send the pir via a switch node which checks if the switch is on or off and routes the pir message accordingly.

try this flow ....

[{"id":"ab69e19efe105460","type":"inject","z":"0918ee609bf69fc7","name":"switch on","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":500,"y":620,"wires":[["ed00809422c8d808"]]},{"id":"2382e74d3ed85bbd","type":"debug","z":"0918ee609bf69fc7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":740,"wires":[]},{"id":"ed00809422c8d808","type":"change","z":"0918ee609bf69fc7","name":"store switch state","rules":[{"t":"set","p":"switch","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":640,"wires":[[]]},{"id":"93e700229c4f2fda","type":"switch","z":"0918ee609bf69fc7","name":"route msg","property":"switch","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":740,"wires":[["2382e74d3ed85bbd"],[]]},{"id":"7b9bd121a9c796b1","type":"inject","z":"0918ee609bf69fc7","name":"switch off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":500,"y":660,"wires":[["ed00809422c8d808"]]},{"id":"388af3c97654a622","type":"inject","z":"0918ee609bf69fc7","name":"pir on","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":490,"y":720,"wires":[["93e700229c4f2fda"]]},{"id":"f7876c50e6e167bf","type":"inject","z":"0918ee609bf69fc7","name":"pir off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":490,"y":760,"wires":[["93e700229c4f2fda"]]}]

Thank you for answering me so quickly.
I will try to import your flows, if I understand how to do it.

Hello, I can't use your flows.
can you see what is missing?
thank you

[{"id":"3cd77b7019ec37e2","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ab69e19efe105460","type":"inject","z":"3cd77b7019ec37e2","name":"switch on","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":200,"y":240,"wires":[["ed00809422c8d808"]]},{"id":"2382e74d3ed85bbd","type":"debug","z":"3cd77b7019ec37e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":360,"wires":[]},{"id":"ed00809422c8d808","type":"change","z":"3cd77b7019ec37e2","name":"store switch state","rules":[{"t":"set","p":"switch","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":260,"wires":[["61f73f98abcc46d6"]]},{"id":"93e700229c4f2fda","type":"switch","z":"3cd77b7019ec37e2","name":"route msg","property":"switch","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":360,"wires":[["2382e74d3ed85bbd"],[]]},{"id":"7b9bd121a9c796b1","type":"inject","z":"3cd77b7019ec37e2","name":"switch off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":200,"y":280,"wires":[["ed00809422c8d808"]]},{"id":"388af3c97654a622","type":"inject","z":"3cd77b7019ec37e2","name":"pir on","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":190,"y":340,"wires":[["93e700229c4f2fda"]]},{"id":"f7876c50e6e167bf","type":"inject","z":"3cd77b7019ec37e2","name":"pir off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":190,"y":380,"wires":[["93e700229c4f2fda"]]},{"id":"b06eb90887fbf786","type":"server-state-changed","z":"3cd77b7019ec37e2","name":"inter_1","server":"703e56e6e5cfdf2a","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.inter_1_click","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":170,"y":540,"wires":[["9595bb9fd71105f0"]]},{"id":"9595bb9fd71105f0","type":"change","z":"3cd77b7019ec37e2","name":"store switch state","rules":[{"t":"set","p":"inter_1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":540,"wires":[["cb20952242287a4d"]]},{"id":"aba0ff1c4b522d80","type":"server-state-changed","z":"3cd77b7019ec37e2","name":"PIR_1","server":"703e56e6e5cfdf2a","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.pir_1_occupancy","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"true","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":170,"y":680,"wires":[["02a1c2aba5ff636f"],["02a1c2aba5ff636f"]]},{"id":"02a1c2aba5ff636f","type":"switch","z":"3cd77b7019ec37e2","name":"route msg","property":"switch","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":680,"wires":[["138d2c70766c621d"],[]]},{"id":"138d2c70766c621d","type":"debug","z":"3cd77b7019ec37e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":680,"wires":[]},{"id":"cb20952242287a4d","type":"debug","z":"3cd77b7019ec37e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":540,"wires":[]},{"id":"61f73f98abcc46d6","type":"debug","z":"3cd77b7019ec37e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]},{"id":"703e56e6e5cfdf2a","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

there is a problem with the switch because it sends a
switch:""

This debug output looks like it didn't come from my flow ?

[{"id":"ab69e19efe105460","type":"inject","z":"3cd77b7019ec37e2","name":"switch on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Switch","payload":"on","payloadType":"str","x":200,"y":240,"wires":[["ed00809422c8d808"]]},{"id":"2382e74d3ed85bbd","type":"debug","z":"3cd77b7019ec37e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":360,"wires":[]},{"id":"ed00809422c8d808","type":"change","z":"3cd77b7019ec37e2","name":"store switch state","rules":[{"t":"set","p":"switch","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":260,"wires":[["61f73f98abcc46d6"]]},{"id":"93e700229c4f2fda","type":"switch","z":"3cd77b7019ec37e2","name":"route msg","property":"switch","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":360,"wires":[["2382e74d3ed85bbd"],[]]},{"id":"7b9bd121a9c796b1","type":"inject","z":"3cd77b7019ec37e2","name":"switch off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Switch","payload":"off","payloadType":"str","x":200,"y":280,"wires":[["ed00809422c8d808"]]},{"id":"388af3c97654a622","type":"inject","z":"3cd77b7019ec37e2","name":"pir on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"PIR","payload":"on","payloadType":"str","x":190,"y":340,"wires":[["93e700229c4f2fda"]]},{"id":"f7876c50e6e167bf","type":"inject","z":"3cd77b7019ec37e2","name":"pir off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"PIR","payload":"off","payloadType":"str","x":190,"y":380,"wires":[["93e700229c4f2fda"]]},{"id":"61f73f98abcc46d6","type":"debug","z":"3cd77b7019ec37e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]}]

This is the output from my flow, I added topics to make it easier to follow.

image

When switch is on PIR on and off messages pass to debug, when switch is off nothing is passed to debug.

I'll keep looking and let you know.
Thank you smsgann99

hello, with this flow it works well

[{"id":"396acb1e4ebd684a","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"8621643ad6ec03d6","type":"debug","z":"396acb1e4ebd684a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":400,"wires":[]},{"id":"2746bd01b2da8298","type":"change","z":"396acb1e4ebd684a","name":"store switch state","rules":[{"t":"set","p":"switch","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":300,"wires":[["73d840d0a154d260"]]},{"id":"deafdc2e33953346","type":"switch","z":"396acb1e4ebd684a","name":"route msg","property":"switch","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":400,"wires":[["8621643ad6ec03d6"],[]]},{"id":"73d840d0a154d260","type":"debug","z":"396acb1e4ebd684a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":300,"wires":[]},{"id":"12b34f471dbdfaf8","type":"server-state-changed","z":"396acb1e4ebd684a","name":"inter_1","server":"703e56e6e5cfdf2a","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.inter_1_click","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":180,"wires":[["e40823b9ad5a9d3d"]]},{"id":"e263d26ecfd05e9c","type":"server-state-changed","z":"396acb1e4ebd684a","name":"PIR_1","server":"703e56e6e5cfdf2a","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.pir_1_occupancy","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"true","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":420,"wires":[["deafdc2e33953346"],[]]},{"id":"e40823b9ad5a9d3d","type":"switch","z":"396acb1e4ebd684a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":210,"y":300,"wires":[["2746bd01b2da8298"],["2746bd01b2da8298"],[]]},{"id":"703e56e6e5cfdf2a","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.