# How to make an AND gate graphically

**URL:** https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315
**Category:** General
**Created:** [22 November 2020 09:58 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315 "2020-11-22T09:58:12Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![hdehaseleer](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hdehaseleer](https://discourse.nodered.org/u/hdehaseleer)
#### Post date: [22 November 2020 09:58 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/1 "2020-11-22T09:58:12Z")

</div>

I'm very new with Home Assistant and Node-Red.

I'm searching how to make an AND gate with the graphical representation.

I want to make:

if "we are at home" AND "we are not sleeping" AND "it's dark"  
then "turn all lights on"  
else "turn all lights off"

With some trial and error I found the following working. But it looks very complicated on screen

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

How can i make the represention more simple? By using an AND gate?  
Something like this

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/473f75041d3bb6b90d070b6170135999440886b3.png)

Thanks

---

<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: [22 November 2020 10:15 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/2 "2020-11-22T10:15:40Z")

</div>

Have a look at [node-red-contrib-bool-gate](https://flows.nodered.org/node/node-red-contrib-bool-gate). There you can configure the AND gate of all three inputs. Make sure the three inputs have different topics so they can be identified in the gate. That will give you a `true` or `false` output which may be able to feed direct to the lights, or you may have to convert the true/false to on/off or whatever which you can do in a Change node.

---

<div class="post-metadata">

### Author: ![hdehaseleer](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hdehaseleer](https://discourse.nodered.org/u/hdehaseleer)
#### Post date: [22 November 2020 11:17 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/3 "2020-11-22T11:17:30Z")

</div>

Thanks. It seems that this node is what i need.  
But i still have a problem to make it work.

This simple example of "ANDing" twice a value that is TRUE at this moment, should return TRUE and shoud turn the ligt on. But it is not.  
What am I doing wrong?

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

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [22 November 2020 11:39 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/4 "2020-11-22T11:39:00Z")

</div>

The topics "switch\_wij\_zijn\_thuis" are the same.  
This need to be 2 different topics.

---

<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: [22 November 2020 11:39 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/5 "2020-11-22T11:39:02Z")

</div>

What isn't working? Is it the value coming out of the AND node or the value is correct but it doesn't turn the light on?

If it is the value that is coming out of the node that is wrong then add a debug node showing the two messages that are going into the AND node and show us what you see. Did you see my previous comment: Make sure the three inputs have different topics so they can be identified in the gate?

---

<div class="post-metadata">

### Author: ![hdehaseleer](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hdehaseleer](https://discourse.nodered.org/u/hdehaseleer)
#### Post date: [22 November 2020 12:09 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/6 "2020-11-22T12:09:16Z")

</div>

I started with three different topics. But at the end I tried with two same topics

First the debug output of two topics. We are at home is True . We are sleeping is false

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

The debug of the AND gate shows null

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96fe976c652cc4d7f86056f3609ff021295c4cb4.png)

---

<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: [22 November 2020 12:14 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/7 "2020-11-22T12:14:56Z")

</div>

> [@hdehaseleer](#):
>
> The debug of the AND gate shows null

What do you mean it shows null? Do you mean it sends a message containing a payload of null?  
Show us what you see in the debug nodes for the data going in and the data coming out.

---

<div class="post-metadata">

### Author: ![hdehaseleer](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hdehaseleer](https://discourse.nodered.org/u/hdehaseleer)
#### Post date: [22 November 2020 13:18 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/8 "2020-11-22T13:18:06Z")

</div>

Sorry, I'm very new

First a screenshot of the tet configuration

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

And now the result of my tests. In test4, only one value is TRUE, the other FALSE. But the light changed like you can see in the debug output

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/620d7f2cac571cb337a151481eae106e6175875f.png)

---

<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: [22 November 2020 13:31 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/9 "2020-11-22T13:31:58Z")

</div>

You haven't shown the debug for the failing state with one true and one false. I want to see it in the debug output. You don't need to show the flow again, just the debug outputs.

---

<div class="post-metadata">

### Author: ![hdehaseleer](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hdehaseleer](https://discourse.nodered.org/u/hdehaseleer)
#### Post date: [22 November 2020 13:40 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/10 "2020-11-22T13:40:53Z")

</div>

Indeed.

But it seems that the debug screen shows only the values changing to TRUE and not the values changing to FALSE. What should I do?

But below the input you can see one state FALSE at 14u03 and one state becoming TRUE later at 14u04. Ans also at 14u04, the light changed.

---

<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: [22 November 2020 13:57 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/11 "2020-11-22T13:57:26Z")

</div>

Well if you aren't getting a false output from the Sleeping and At Home nodes then obviously the gate won't know what to do. I don't know those blue nodes at all, are they supposed to send out true and false? Perhaps false comes on the other output. Have a look at the docs for that node.

---

<div class="post-metadata">

### Author: ![hdehaseleer](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hdehaseleer](https://discourse.nodered.org/u/hdehaseleer)
#### Post date: [22 November 2020 14:09 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/12 "2020-11-22T14:09:46Z")

</div>

Thanks for you time.  
I will check your tip: "Perhaps false comes on the other output"

---

<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: [21 January 2021 14:09 UTC](https://discourse.nodered.org/t/how-to-make-an-and-gate-graphically/36315/13 "2021-01-21T14:09:59Z")

</div>

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