# AND/OR for multiple entity current states

**URL:** https://discourse.nodered.org/t/and-or-for-multiple-entity-current-states/35050
**Category:** General
**Created:** [30 October 2020 00:07 UTC](https://discourse.nodered.org/t/and-or-for-multiple-entity-current-states/35050 "2020-10-30T00:07:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![robertash](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/robertash/32/30751_2.png) [@robertash](https://discourse.nodered.org/u/robertash)
#### Post date: [30 October 2020 00:07 UTC](https://discourse.nodered.org/t/and-or-for-multiple-entity-current-states/35050/1 "2020-10-30T00:07:11Z")

</div>

Hi!

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:

 ![Screenshot 2020-10-30 at 00.49.19](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6487ad330ecbd8ff391e56bd197ae74e01da3b3.png)

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

I am interested in this section in particular:

```auto
[{"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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/396a92fcb9515c10158ae721bdc08164654cf04f.png)

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

Else:

- 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!

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [30 October 2020 07:54 UTC](https://discourse.nodered.org/t/and-or-for-multiple-entity-current-states/35050/2 "2020-10-30T07:54:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 October 2020 10:38 UTC](https://discourse.nodered.org/t/and-or-for-multiple-entity-current-states/35050/3 "2020-10-30T10:38:06Z")

</div>

> [@robertash](#):
>
> is there any contrib node that lets me put multiple entity states in an AND or OR type

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

---

<div class="post-metadata">

### Author: ![robertash](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/robertash/32/30751_2.png) [@robertash](https://discourse.nodered.org/u/robertash)
#### Post date: [31 October 2020 08:44 UTC](https://discourse.nodered.org/t/and-or-for-multiple-entity-current-states/35050/4 "2020-10-31T08:44:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [30 December 2020 08:44 UTC](https://discourse.nodered.org/t/and-or-for-multiple-entity-current-states/35050/5 "2020-12-30T08:44:50Z")

</div>

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