# Gate control by HA entity node

**URL:** <https://discourse.nodered.org/t/gate-control-by-ha-entity-node/73032>\
**Category:** General\
**Tags:** function-node, home-assistant\
**Created:** [1 January 2023 21:19 UTC](https://discourse.nodered.org/t/gate-control-by-ha-entity-node/73032 "2023-01-01T21:19:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![migsun](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/migsun/32/54164_2.png) [@migsun](https://discourse.nodered.org/u/migsun)\
**Post date:** [1 January 2023 21:19 UTC](https://discourse.nodered.org/t/gate-control-by-ha-entity-node/73032/1 "2023-01-01T21:19:47Z")

</div>

Hello, I want to control this [function node](https://flows.nodered.org/flow/a985944e789d90e0cd2008d85b7aaa65) through an entity node switched by Home Assistant. How do I configure the entity switch for an output with the msg.topic = "Gate" and boolean value true and false?

 ![entity](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/14ddfee49ec4ac8f7c0f46922ded08ba120c2aaf.jpeg)

function node

> if (msg.topic === "gate") {  
> context.pass = (msg.payload === true) ? true : false;  
> return null; // exit out early as it's just the control  
> }  
> if (context.pass) {  
> return msg; // if enabled pass msg  
> }  
> return null; // or drop it

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [1 January 2023 21:46 UTC](https://discourse.nodered.org/t/gate-control-by-ha-entity-node/73032/2 "2023-01-01T21:46:11Z")

</div>

Probably easier than making a function node act as a gate, have you considered node-red-contrib-simple-gate?

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/952f0abdf0fb94e9acd429d68fbbd662657f42d6.jpeg)

```auto
[{"id":"125062fd02dd4e5e","type":"gate","z":"a19719d3e57004eb","name":"","controlTopic":"gate","defaultState":"closed","openCmd":"true","closeCmd":"false","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":490,"y":140,"wires":[["fc232abf7483ba90"]]},{"id":"fc232abf7483ba90","type":"debug","z":"a19719d3e57004eb","name":"debug 232","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":140,"wires":[]},{"id":"0e9939cfc16143e0","type":"inject","z":"a19719d3e57004eb","name":"Normal input","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":200,"wires":[["125062fd02dd4e5e"]]},{"id":"023fc48a3c3c1bbd","type":"group","z":"a19719d3e57004eb","name":"Gate control - topic \"gate\" payload true/false","style":{"label":true},"nodes":["b6011414c26fe2b2","08ef1bdaaaf18432"],"x":114,"y":39,"w":282,"h":122},{"id":"b6011414c26fe2b2","type":"inject","z":"a19719d3e57004eb","g":"023fc48a3c3c1bbd","name":"Open the gate","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gate","payload":"true","payloadType":"bool","x":230,"y":80,"wires":[["125062fd02dd4e5e"]]},{"id":"08ef1bdaaaf18432","type":"inject","z":"a19719d3e57004eb","g":"023fc48a3c3c1bbd","name":"Close the gate","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gate","payload":"false","payloadType":"bool","x":230,"y":120,"wires":[["125062fd02dd4e5e"]]}]

```

If the outputs from your HA node are not topic:"gate", payload:true/false, use change nodes to tweek them or adjust the gate settings.

---

<div class="post-metadata">

**Author:** ![migsun](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/migsun/32/54164_2.png) [@migsun](https://discourse.nodered.org/u/migsun)\
**Post date:** [3 January 2023 20:05 UTC](https://discourse.nodered.org/t/gate-control-by-ha-entity-node/73032/3 "2023-01-03T20:05:10Z")

</div>

thx - This looks like a way to solve my "problem"...

...but a need a switch in home assistant and I prefer to reduce additionaly installed nodes.

 ![away](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5a78ed9fa663fda99abf1c22509e5d447073366f.jpeg)

Now I set the msg.topic by another change node. Not realy elegant but it works.  
If anybody could make my way nicer I will be thankful.

---

<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:** [4 March 2023 20:05 UTC](https://discourse.nodered.org/t/gate-control-by-ha-entity-node/73032/4 "2023-03-04T20:05:16Z")

</div>

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