# Close only the doors which are open

**URL:** <https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501>\
**Category:** General\
**Tags:** home-assistant\
**Created:** [12 November 2022 18:07 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501 "2022-11-12T18:07:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sevenmp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sevenmp/32/70610_2.png) [@sevenmp](https://discourse.nodered.org/u/sevenmp)\
**Post date:** [12 November 2022 18:07 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/1 "2022-11-12T18:07:24Z")

</div>

Hi all,

I am pretty new to nodered or programming in general and need your help for a flow.

I have an outside gate and a garage door which I have wired to shellies as such I can open or close them from home assistant.

I am now trying to setup a NFCtag and want to open the gates when the tag is scanned however when my wife is home its normal that the garage door is open and only the outside gate is closed so I need to open only the gate.

This is where I'm stuck, I can get the entity Ids of the ones which are open but now don't know how to progress this. Can I have any pointers pls? This is what I have so far:

```auto
[{"id":"b79ee612.ad5248","type":"server-events","z":"662dfd9f43833c42","name":"","server":"80e82e1cf59bf581","version":1,"event_type":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":240,"y":280,"wires":[["2505b4d0.1d2edc"]]},{"id":"2505b4d0.1d2edc","type":"switch","z":"662dfd9f43833c42","name":"","property":"payload.event.tag_id","propertyType":"msg","rules":[{"t":"cont","v":"823459da-b2c9-44ba-9e1f-d3eadba18eed","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":280,"wires":[["f8e3a0766b2c9090"]]},{"id":"f757662a2e919eac","type":"inject","z":"662dfd9f43833c42","name":"","props":[{"p":"payload.event.tag_id","v":"823459da-b2c9-44ba-9e1f-d3eadba18eed","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":200,"wires":[["2505b4d0.1d2edc"]]},{"id":"521a6a7904e41427","type":"function","z":"662dfd9f43833c42","name":"function 1","func":"","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":280,"wires":[[]]},{"id":"f8e3a0766b2c9090","type":"ha-get-entities","z":"662dfd9f43833c42","name":"","server":"80e82e1cf59bf581","version":0,"rules":[{"property":"entity_id","logic":"includes","value":"binary_sensor.portao_garagem_input, binary_sensor.portao_rua_input","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":550,"y":280,"wires":[["521a6a7904e41427"]]},{"id":"80e82e1cf59bf581","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 November 2022 18:32 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/2 "2022-11-12T18:32:29Z")

</div>

I think you may have more luck on the home assistant forums, most people here don't use HA. And it is kind of hard to replicate your setup.

---

<div class="post-metadata">

**Author:** ![sevenmp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sevenmp/32/70610_2.png) [@sevenmp](https://discourse.nodered.org/u/sevenmp)\
**Post date:** [12 November 2022 20:54 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/3 "2022-11-12T20:54:52Z")

</div>

Well, aside from getting the entities and calling the services to close the gates the rest is managed in nodered as is all the different automation I have setup like telegram notifications etc.

My difficulty here is how to get the entities that are open (which Is done) and now according with what those are send out the corresponding close service call.

---

<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:** [12 November 2022 21:24 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/4 "2022-11-12T21:24:13Z")

</div>

> [@sevenmp](#):
>
> now according with what those are send out the corresponding close service call.

Show us a debug node of the message coming in containing the entities and tell us what output you need.

---

<div class="post-metadata">

**Author:** ![sevenmp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sevenmp/32/70610_2.png) [@sevenmp](https://discourse.nodered.org/u/sevenmp)\
**Post date:** [12 November 2022 21:43 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/5 "2022-11-12T21:43:00Z")

</div>

I think I have been able to accomplish what I wanted but this just seems to be a very sloppy solution.

```auto
[{"id":"b79ee612.ad5248","type":"server-events","z":"662dfd9f43833c42","name":"","server":"80e82e1cf59bf581","version":1,"event_type":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":200,"y":260,"wires":[["2505b4d0.1d2edc"]]},{"id":"2505b4d0.1d2edc","type":"switch","z":"662dfd9f43833c42","name":"","property":"payload.event.tag_id","propertyType":"msg","rules":[{"t":"cont","v":"823459da-b2c9-44ba-9e1f-d3eadba18eed","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":260,"wires":[["f8e3a0766b2c9090"]]},{"id":"f757662a2e919eac","type":"inject","z":"662dfd9f43833c42","name":"","props":[{"p":"payload.event.tag_id","v":"823459da-b2c9-44ba-9e1f-d3eadba18eed","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":200,"wires":[["2505b4d0.1d2edc"]]},{"id":"f8e3a0766b2c9090","type":"ha-get-entities","z":"662dfd9f43833c42","name":"","server":"80e82e1cf59bf581","version":0,"rules":[{"property":"entity_id","logic":"includes","value":"binary_sensor.portao_garagem_input, binary_sensor.portao_rua_input","valueType":"str"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":550,"y":260,"wires":[["f79a7216b072eb89","0a6ef71d3669d286"]]},{"id":"f79a7216b072eb89","type":"switch","z":"662dfd9f43833c42","name":"","property":"payload[0].entity_id","propertyType":"msg","rules":[{"t":"eq","v":"binary_sensor.portao_rua_input","vt":"str"},{"t":"eq","v":"binary_sensor.portao_garagem_input","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":180,"wires":[["332ecf2a0c7a1402"],["0d3c6a4acc1066e6"]]},{"id":"0d3c6a4acc1066e6","type":"api-call-service","z":"662dfd9f43833c42","name":"Abrir Garagem","server":"80e82e1cf59bf581","version":5,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"cover.garage_door","data":"0","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":920,"y":220,"wires":[[]]},{"id":"332ecf2a0c7a1402","type":"api-call-service","z":"662dfd9f43833c42","name":"Abrir Portão Rua","server":"80e82e1cf59bf581","version":5,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"cover.gate_door","data":"0","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":140,"wires":[[]]},{"id":"0a6ef71d3669d286","type":"switch","z":"662dfd9f43833c42","name":"","property":"payload[1].entity_id","propertyType":"msg","rules":[{"t":"eq","v":"binary_sensor.portao_rua_input","vt":"str"},{"t":"eq","v":"binary_sensor.portao_garagem_input","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":340,"wires":[["cc9c23af77327c1d"],["9760ddd2eba74bb6"]]},{"id":"cc9c23af77327c1d","type":"api-call-service","z":"662dfd9f43833c42","name":"Abrir Portão Rua","server":"80e82e1cf59bf581","version":5,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"cover.gate_door","data":"0","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":300,"wires":[[]]},{"id":"9760ddd2eba74bb6","type":"api-call-service","z":"662dfd9f43833c42","name":"Abrir Garagem","server":"80e82e1cf59bf581","version":5,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"cover.garage_door","data":"0","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":920,"y":380,"wires":[[]]},{"id":"80e82e1cf59bf581","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

```

Can someone help me get this done by maybe using a function node?

---

<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:** [12 November 2022 21:52 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/6 "2022-11-12T21:52:26Z")

</div>

Do you need four service call nodes or could there be one with different messages passed to it? If yes, then, as I suggested already:

> [@Colin](#):
>
> Show us a debug node of the message coming in containing the entities and tell us what output you need.

---

<div class="post-metadata">

**Author:** ![sevenmp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sevenmp/32/70610_2.png) [@sevenmp](https://discourse.nodered.org/u/sevenmp)\
**Post date:** [12 November 2022 22:10 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/7 "2022-11-12T22:10:49Z")

</div>

Apologies, I did not see your reply before I posted the update.

I can pass 2 arguments to the service call by putting (1 entity,2 entity) but I don't know how an output of a function can populate this field:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c88f19c2acde77d62842fbf7eb8be3f37087232f.png)

IS this what you need?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/3/331c286a5b711931ec5a1ab13a797d8ab8a189ea.png)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [13 November 2022 03:46 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/8 "2022-11-13T03:46:34Z")

</div>

OK so fairly simple

(Also when building these sorts of things with HA i would suggest you replace/disconnect the various HA nodes and instead put inject nodes

1. I assume you do some form of presence detection with your wife - as that is the overriding condition that needs to be your first switch node - if she is home then you will branch one way (open only gate) - if she it out then you will open both the gate and the garage

Q) - What happens if you send an open command and the door is already open ? Does it close it or just ignore it ?

Craig

---

<div class="post-metadata">

**Author:** ![sevenmp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sevenmp/32/70610_2.png) [@sevenmp](https://discourse.nodered.org/u/sevenmp)\
**Post date:** [13 November 2022 21:09 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/9 "2022-11-13T21:09:57Z")

</div>

Hi Craig,

Thanks for the help. The wife being home does not mean that 100% of the time the garage will be open so I can't use that as a condition. I need to use the sensor each door has to tell me its state.

Unfortunately, if the door is open and I switch it, it is going to close which is precisely why I want to run this condition only to do so if closed.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [13 November 2022 21:13 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/10 "2022-11-13T21:13:14Z")

</div>

So then the wife being home (or not) is just a furfy and has no real meaning in the context of this and should not affect it in any way ?

Basically you want to know the current state of the doors and reverse them - presumably you have something else that is accurately reporting the open/close status of both of them as the Shelly is unable to ?

Craig

---

<div class="post-metadata">

**Author:** ![sevenmp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sevenmp/32/70610_2.png) [@sevenmp](https://discourse.nodered.org/u/sevenmp)\
**Post date:** [13 November 2022 21:22 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/11 "2022-11-13T21:22:15Z")

</div>

Yah, ignore the wife 🙂 that was just for context, sorry if it added confusion.

I wouldn't say I want to revert it since if it is open, I don't want to close it. The way I see it There are the following options:

1. Outdoor gate is closed and Garage door is closed -\> Open both doors

2. Outdoor gate is closed and Garage door is open -\> Open only the outdoor gate

3. Outdoor Gate is Open and Garage door is closed -\> Open only the garage door

4. Outdoor Gate is Open and Garage door is Open -\> do nothing

Both shellies have a wired reed sensor so I can have the current state when I run the "get entities" to only give the open gates.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [15 November 2022 01:27 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/12 "2022-11-15T01:27:09Z")

</div>

Ok that makes more sense - have a look at Node-red-contrib-ultimate-boolean - it will fix you up

Craig

---

<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:** [14 January 2023 01:27 UTC](https://discourse.nodered.org/t/close-only-the-doors-which-are-open/70501/13 "2023-01-14T01:27:56Z")

</div>

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