AND/OR for multiple entity current states


I am trying to create a flow that prevents me from arming the alarm if any door is open at that time. It is part of a much bigger project im working on to make a "decently"-fledged security system.

Here is an overview of the whole thing:

So you will understand why I don't share the JSON for the entire flow.

I am interested in this section in particular:

[{"id":"d1309cd8.eb7a1","type":"switch","z":"b0e56e3d.dcc36","name":"Arm Alarm?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"input_boolean.alarm_home","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":320,"y":100,"wires":[["1bd5bf39.e28bb1"],["f600e5c5.bce7b8"]]},{"id":"10ca0ae8.314665","type":"api-call-service","z":"b0e56e3d.dcc36","name":"Disarm","server":"59c38194.90565","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.dev_alarm_armed","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":660,"y":100,"wires":[[]]},{"id":"f600e5c5.bce7b8","type":"api-call-service","z":"b0e56e3d.dcc36","name":"Arm","server":"59c38194.90565","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.dev_alarm_armed","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":650,"y":150,"wires":[[]]},{"id":"1bd5bf39.e28bb1","type":"api-call-service","z":"b0e56e3d.dcc36","name":"Reset Trigger","server":"59c38194.90565","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.dev_alarm_triggered","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":510,"y":100,"wires":[["10ca0ae8.314665"]]},{"id":"59c38194.90565","type":"server","name":"Home Assistant","addon":true}]

I want to put a node between the "Arm Alarm?" switch and the "Arm" service call. Here:

Screenshot 2020-10-30 at 00.51.26

Basically, what I would like to do in pseudocode is:

If any of [binary_sensor 1, 2 or 3] is open:

  • Notify me via push
  • Disarm


  • Arm alarm

Now, I know how to do everything except for the IF part. So my question is:

  1. Is there any way to query the current state of an entity from within a function node?
  2. If not, is there any contrib node that lets me put multiple entity states in an AND or OR type?
  3. Or is the only way to either create a network of connected "current state" nodes to check each entity separately or writing each entity state into the flow context?

Thank you for enlightening me!

When you sensors trip open or closed, write there values to context storage. Then in your function node you can retrieve the current values from context, and act accordingly.

1 Like

Have a look at node-red-contrib-bool-gate, it may be helpful

Thank you for your recommendations! I'll try both methods this weekend!

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