# AND - how it works?

**URL:** <https://discourse.nodered.org/t/and-how-it-works/85663>\
**Category:** General\
**Created:** [19 February 2024 07:05 UTC](https://discourse.nodered.org/t/and-how-it-works/85663 "2024-02-19T07:05:15Z")\
**Posts on this page:** 17\
**Page:** 2

<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:** [19 February 2024 10:31 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/21 "2024-02-19T10:31:46Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/19c771c894872119db5e7d6a9b53d8eb2d353b7d.png)

I would recommend to watch [all the videos in this playlist](https://www.youtube.com/watch?v=ksGeUD26Mw0&list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6) to get an understanding how node-red works - takes 45 mins but it will clear up a lot of concepts that you are currently struggling with.

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 10:32 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/22 "2024-02-19T10:32:57Z")

</div>

could you pls show me the inside of the "set msg.payload to true", thx

already watching the videos

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 10:38 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/23 "2024-02-19T10:38:01Z")

</div>

![set_to_true](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/6028bda4f1c04f559cfff9295eb97508312f4ed2.png)

---

<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:** [19 February 2024 10:38 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/24 "2024-02-19T10:38:23Z")

</div>

The dropdown next to "to the value" allows you to set several different datatypes.  
For boolean there is also a dropdown at the right to choose true or false.

It takes a while to start to grasp how Node-red does things but it quickly gets easier.

---

<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:** [19 February 2024 10:39 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/25 "2024-02-19T10:39:05Z")

</div>

> [@4711Austria](#):
>
> could you pls show me the inside of the "set msg.payload to true", thx
> 
> already watching the videos

Ask again if you still cannot work it out after watching the videos. Note that @bakman2's post was just to give you an idea, the values set in the change node must be whatever you need for the three conditions.

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 10:47 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/26 "2024-02-19T10:47:12Z")

</div>

msg.payload (value) to boolean  
just to be sure, a value above 0,00001 will be true, 0 = false ? no it doesnt.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 11:24 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/27 "2024-02-19T11:24:24Z")

</div>

Not sure what the value 0.00001 has to do with Boolean values.

Boolean values represent the two truth values: true or false. In programming, these values are often used in conditional statements, logical operations, and decision-making processes.  
Boolean values can only be one of two states - true or false. True represents a condition that is considered as "yes" or "correct," while false represents a condition that is "no" or "incorrect."

So in the flow above the test for... "Is the battery voltage equal to or above 60 - results in "yes" or "no" or "True" or "False".

I think a simple explanation of "data-types", including Boolean, is covered in the videos.

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 11:25 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/28 "2024-02-19T11:25:59Z")

</div>

just watched the videos, some new infos, some I will never use, also a bit difficult becouse it is not my motherlanguage.

verry interesting on watching the options node red delivers, but nothing detailed for me solve my problem.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 11:27 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/29 "2024-02-19T11:27:27Z")

</div>

> [@4711Austria](#):
>
> but nothing detailed for me solve my problem

So what problem do you have remaining?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 11:51 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/30 "2024-02-19T11:51:44Z")

</div>

Just looked on the website at some of the example-flows for your Victron Cerbo GX.  
If you scroll down, towards the end of the web-page, there is an example of how to operate a relay.

> **[Example Flows](https://github.com/victronenergy/node-red-contrib-victron/wiki/Example-Flows)**
>
> Contribute to victronenergy/node-red-contrib-victron development by creating an account on GitHub.

It shows to drive a relay, a "logic" level is used (NOT Boolean).  
 ![driving_relay](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3d2ba4252361a26a3f7cf06b2f6126d037c5d0b.png)  
The settings inside the UI-Switch node - note the payload type is numeric and the use of msg.topic  
 ![UI_switch](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/263658394861faa770a56e36784eff44366d020f.png)

---

<div class="post-metadata">

**Author:** ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)\
**Post date:** [19 February 2024 16:47 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/31 "2024-02-19T16:47:07Z")

</div>

```auto
[{"id":"3aa1e2ee83a6814b","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"8cb30f11bbe52e11","type":"junction","z":"3aa1e2ee83a6814b","x":340,"y":200,"wires":[["8d3e188d3bb213c2","8f7751900ce13e11"]]},{"id":"d0235022e8e3ac29","type":"junction","z":"3aa1e2ee83a6814b","x":260,"y":380,"wires":[["8cb30f11bbe52e11"]]},{"id":"5f1c92dcce75788f","type":"junction","z":"3aa1e2ee83a6814b","x":660,"y":260,"wires":[["5102d56c371856d8"]]},{"id":"092520097a3dcc4c","type":"victron-input-system","z":"3aa1e2ee83a6814b","service":"com.victronenergy.system/0","path":"/Dc/Battery/Voltage","serviceObj":{"service":"com.victronenergy.system/0","name":"Venus system"},"pathObj":{"path":"/Dc/Battery/Voltage","type":"float","name":"Battery voltage (V)"},"name":"","onlyChanges":false,"x":170,"y":200,"wires":[["8cb30f11bbe52e11"]]},{"id":"bad4236f5c9f4a03","type":"comment","z":"3aa1e2ee83a6814b","name":"@victronenergy/node-red-contrib-victron","info":"","x":180,"y":60,"wires":[]},{"id":"8f7751900ce13e11","type":"limit-monitor","z":"3aa1e2ee83a6814b","name":"lower limit","topic":"","limit":"65","kind":"2","delay":"0","hysteresis":"0","x":430,"y":260,"wires":[["5ce2c0e6eab53336"]]},{"id":"8d3e188d3bb213c2","type":"limit-monitor","z":"3aa1e2ee83a6814b","name":"upper limit","topic":"","limit":"60","kind":"1","delay":"0","hysteresis":"0","x":430,"y":140,"wires":[["5ce2c0e6eab53336"]]},{"id":"cbdd1df00741ce9f","type":"comment","z":"3aa1e2ee83a6814b","name":"node-red-contrib-limit-monitor","info":"","x":490,"y":60,"wires":[]},{"id":"5d3929129c3b1b83","type":"comment","z":"3aa1e2ee83a6814b","name":"@mschaeffler/node-red-logic","info":"","x":760,"y":60,"wires":[]},{"id":"481908949239c018","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"66","payloadType":"num","x":150,"y":320,"wires":[["d0235022e8e3ac29"]]},{"id":"4bffd9320f455288","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"59","payloadType":"num","x":150,"y":440,"wires":[["d0235022e8e3ac29"]]},{"id":"24543ba8698a2033","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"62","payloadType":"num","x":150,"y":380,"wires":[["d0235022e8e3ac29"]]},{"id":"b4cb27612ef4ca81","type":"comment","z":"3aa1e2ee83a6814b","name":"upper limit 60","info":"","x":430,"y":100,"wires":[]},{"id":"27f5ec899d40ec4a","type":"comment","z":"3aa1e2ee83a6814b","name":"lower limit 65","info":"","x":430,"y":220,"wires":[]},{"id":"cb8e593b1a940cb8","type":"and","z":"3aa1e2ee83a6814b","name":"","topic":"","property":"payload","minData":"2","filter":false,"x":690,"y":380,"wires":[[]]},{"id":"fc9f21ef0ddbfa3e","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"1","payload":"true","payloadType":"bool","x":430,"y":360,"wires":[["cb8e593b1a940cb8"]]},{"id":"c3677d41a0dfbebf","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"1","payload":"false","payloadType":"bool","x":430,"y":400,"wires":[["cb8e593b1a940cb8"]]},{"id":"6445cfcc37c44c6f","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"2","payload":"true","payloadType":"bool","x":430,"y":460,"wires":[["cb8e593b1a940cb8"]]},{"id":"4f3ae1026891d662","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"2","payload":"false","payloadType":"bool","x":430,"y":500,"wires":[["cb8e593b1a940cb8"]]},{"id":"5ce2c0e6eab53336","type":"or","z":"3aa1e2ee83a6814b","name":"","topic":"","property":"payload","minData":"1","filter":false,"x":570,"y":200,"wires":[["ae8066c3ca3603f6","5f1c92dcce75788f"]]},{"id":"ae8066c3ca3603f6","type":"not","z":"3aa1e2ee83a6814b","name":"","property":"payload","showState":true,"filter":false,"x":710,"y":200,"wires":[["06e111f1cf97f8c0"]]},{"id":"06e111f1cf97f8c0","type":"debug","z":"3aa1e2ee83a6814b","name":"debug 1","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":860,"y":200,"wires":[]},{"id":"5102d56c371856d8","type":"debug","z":"3aa1e2ee83a6814b","name":"debug 2","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":860,"y":260,"wires":[]}]

```

 ![pic03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f58f332381ee11b556db99b224e4326cf7bdc919.png)

Maybe this can be used?

---

<div class="post-metadata">

**Author:** ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)\
**Post date:** [19 February 2024 18:39 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/32 "2024-02-19T18:39:10Z")

</div>

OR and NOT have the disadvantage that it must go through the combinations before it works correctly.

Here is a new version.

 ![pic04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/ef7066bf02b170c75a1307ac61715ba9f70c2b9b.png)

```auto
[{"id":"801010e6b3685e8c","type":"change","z":"3aa1e2ee83a6814b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":740,"wires":[["61a40aa56fb468e9"]]},{"id":"a15ccf60701e2fc5","type":"switch","z":"3aa1e2ee83a6814b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"65","vt":"str"},{"t":"lt","v":"60","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":350,"y":760,"wires":[["801010e6b3685e8c"],["801010e6b3685e8c"],["153f9e7c7d1efb73"]]},{"id":"61a40aa56fb468e9","type":"debug","z":"3aa1e2ee83a6814b","name":"debug 418","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":760,"wires":[]},{"id":"153f9e7c7d1efb73","type":"change","z":"3aa1e2ee83a6814b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":780,"wires":[["61a40aa56fb468e9"]]},{"id":"ee50ab62820198de","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"66","payloadType":"num","x":130,"y":700,"wires":[["f92b643bb36afe53"]]},{"id":"280db08726887f51","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"59","payloadType":"num","x":130,"y":820,"wires":[["f92b643bb36afe53"]]},{"id":"31837a601c20afeb","type":"inject","z":"3aa1e2ee83a6814b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"62","payloadType":"num","x":130,"y":760,"wires":[["f92b643bb36afe53"]]},{"id":"37be05a0c0af4489","type":"debug","z":"3aa1e2ee83a6814b","name":"debug 419","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":370,"y":800,"wires":[]},{"id":"f92b643bb36afe53","type":"junction","z":"3aa1e2ee83a6814b","x":240,"y":760,"wires":[["a15ccf60701e2fc5","37be05a0c0af4489"]]}]

```

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [20 February 2024 17:10 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/33 "2024-02-20T17:10:01Z")

</div>

- I was blocked by the forum as new by 24h.... sry

I do know what booleans and the rest are  
I ask for the node settings to get boolean out, your change node, does only change the output to a boolean yes, this is not what I am looking for. your function node does it correct. true and false output.

still looking to standard nodes to get a true/false out of my value in range or not. This is all.  
the next step is to summery (OR) more conditions on setting the Relais.

- the samples did help me a lot, now it is working

---

<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:** [20 February 2024 17:28 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/34 "2024-02-20T17:28:44Z")

</div>

@Frida's last suggestion should do what you want, being exactly what I suggested earlier. A Switch node to determine in range or not and then Change nodes to set the payload as you want. Have you tried it yet?

---

<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:** [20 February 2024 17:34 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/35 "2024-02-20T17:34:44Z")

</div>

A change node using JSONata will output true/false, If you want it in one node like the function node.  
e.g.

```auto
[{"id":"a6d89fd07304fbc4","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"60","payloadType":"num","x":390,"y":5140,"wires":[["6a0e9665632f90ca"]]},{"id":"6a0e9665632f90ca","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload < 60 and $$.payload > 40","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":5260,"wires":[["89102cc53f5dc444"]]},{"id":"7b6fb2795e5c12f9","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":390,"y":5260,"wires":[["6a0e9665632f90ca"]]},{"id":"8271b696f0de1cfe","type":"inject","z":"d1395164b4eec73e","name":"50","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":390,"y":5200,"wires":[["6a0e9665632f90ca"]]},{"id":"89102cc53f5dc444","type":"debug","z":"d1395164b4eec73e","name":"debug 416","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":5360,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [20 February 2024 20:00 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/36 "2024-02-20T20:00:40Z")

</div>

have tried it, works, all fine now  
THX to all!

---

<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:** [20 May 2024 20:01 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/37 "2024-05-20T20:01:26Z")

</div>

Closed on 20 May 2024 20:01 UTC

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

[Previous page](https://discourse.nodered.org/t/and-how-it-works/85663.md?page=1)
