Close only the doors which are open

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:

[{"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"}]

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.

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.

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

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

[{"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?

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:

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:

IS this what you need?

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

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.

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

Yah, ignore the wife :slight_smile: 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.

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

Craig

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