# How Can I Make Logic 1 and Logic 0 graphical with Node red and RPi 3

**URL:** <https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697>\
**Category:** Dashboard\
**Created:** [19 July 2018 14:40 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697 "2018-07-19T14:40:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [19 July 2018 14:40 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/1 "2018-07-19T14:40:49Z")

</div>

Hi everyone, just last 2 days Im trying to make something with raspberry and node red for some PLC's connection logic 1 and 0 changed need alarm .

Normally It should be like this  
for example ;

Vacuum pump running = Logic 1 --\> text : Everything is ok

Vacuum pump stopped = Logic 0 --\> text : Warning vacuum pump stopped. and pop up window appear for warning.

How can I make this with dashboard visualizing in node-red ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 July 2018 15:34 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/2 "2018-07-19T15:34:51Z")

</div>

how about a switch node testing the two cases and each output uses a change node to set the text you want and they feed into two ui-text nodes?

---

<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 July 2018 15:59 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/3 "2018-07-19T15:59:24Z")

</div>

You could configure a Change node to Set msg.payload to JSONata expression  
`msg.payload ? "Running" : "Stopped"`  
and feed that into the text node.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [19 July 2018 17:56 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/4 "2018-07-19T17:56:32Z")

</div>

Just for fun! \> here a solution with `node-red-contrib-dsm` (Version 0.7.0).

![pump-dsm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f5852851e5f5b66764ddf9e3ee619c5ac17fb158.png)

### Flow

```auto
[{"id":"dd522a21.4bc2c8","type":"dsm","z":"cb099c1f.9ea6b","name":"pump","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"stopped\",\n \"states\": {\n \"stopped\": {\n \"1\": \"running\"\n },\n \"running\": {\n \"0\": \"stopped\"\n }\n },\n \"methods\": {\n \"0\": \"sta.fill='red';\",\n \"1\": \"sta.fill='green';\"\n }\n}","x":300,"y":3840,"wires":[["12fc5f67.774721"]]},{"id":"1f77971c.9bb5a9","type":"inject","z":"cb099c1f.9ea6b","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":3820,"wires":[["dd522a21.4bc2c8"]]},{"id":"627cee4b.a2a3c","type":"inject","z":"cb099c1f.9ea6b","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":3860,"wires":[["dd522a21.4bc2c8"]]},{"id":"12fc5f67.774721","type":"debug","z":"cb099c1f.9ea6b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":490,"y":3840,"wires":[]}]

```

---

<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 July 2018 18:58 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/5 "2018-07-19T18:58:22Z")

</div>

Or a function node

```auto
msg.payload = msg.payload ? "Running" : "Stopped"
return msg

```

How many ways would you like? 🙂

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [20 July 2018 05:34 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/6 "2018-07-20T05:34:31Z")

</div>

Im quite new raspberry and also node-red and try,ng to make something. Thanks for your worhly answers. I will try your solution methode immediately.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [23 July 2018 10:27 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/7 "2018-07-23T10:27:20Z")

</div>

Dear cflurin, sorry about my question but dont have enough experince.

How can I make connection with raspberry PI and your designing ? For example I added Raspberry PI but I dont know how can I connect ports and make designing ?

 ![IMG_0139](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/65283c0490a965ed9873cfeccd5182c8b7e146a9.JPG)

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [23 July 2018 12:04 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/8 "2018-07-23T12:04:08Z")

</div>

Let's say the pump input is connected to pin 3 then just wire the `rpi-gpio in` to the `dsm input`. Connecting pin3 to ground = 0, pin3 open = 1

![pump](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/21c9a4e86cb99e5b01a1f9cb66940f01d9c8af15.png)

```auto
[{"id":"a23e80f9.2dfa5","type":"dsm","z":"cb099c1f.9ea6b","name":"pump (forum)","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"running\",\n \"states\": {\n \"stopped\": {\n \"1\": \"running\"\n },\n \"running\": {\n \"0\": \"stopped\"\n }\n },\n \"methods\": {\n \"0\": \"sta.fill='red';\",\n \"1\": \"sta.fill='green';\"\n }\n}\n","x":280,"y":3840,"wires":[["a039ee54.d6bd7"]]},{"id":"a039ee54.d6bd7","type":"debug","z":"cb099c1f.9ea6b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":450,"y":3840,"wires":[]},{"id":"ea7aeb1c.8ba328","type":"rpi-gpio in","z":"cb099c1f.9ea6b","name":"","pin":"3","intype":"tri","debounce":"25","read":false,"x":130,"y":3840,"wires":[["a23e80f9.2dfa5"]]}]

```

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [23 July 2018 12:48 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/9 "2018-07-23T12:48:36Z")

</div>

Thank you very much for your support.  
I will apply this.

Final question is it possible to show it with dashboard screen like notification or any gauge something possible ?

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [31 July 2018 06:11 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/10 "2018-07-31T06:11:15Z")

</div>

```
[{"id":"8a242a1b.b175f8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"b5409d9f.e7cac","type":"dsm","z":"8a242a1b.b175f8","name":"pump (forum)","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"running\",\n \"states\": {\n \"stopped\": {\n \"1\": \"running\"\n },\n \"running\": {\n \"0\": \"stopped\"\n }\n },\n \"methods\": {\n \"0\": \"sta.fill='red';\",\n \"1\": \"sta.fill='green';\"\n }\n}\n","x":380,"y":230,"wires":[["bd1378fc.290c98","471d97a5.537458","9f5a0857.ce2218"]]},{"id":"bd1378fc.290c98","type":"debug","z":"8a242a1b.b175f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":583,"y":230,"wires":[]},{"id":"de2bb761.91f328","type":"rpi-gpio in","z":"8a242a1b.b175f8","name":"Raspberry PI 3","pin":"3","intype":"tri","debounce":"25","read":false,"x":182,"y":291,"wires":[["b5409d9f.e7cac"]]},{"id":"471d97a5.537458","type":"ui_gauge","z":"8a242a1b.b175f8","name":"","group":"1f7d2c43.889e74","order":0,"width":0,"height":0,"gtype":"donut","title":"Montage","label":"units","format":"{{value}}","min":0,"max":"1","colors":["#ff0000","#e6e600","#00ff40"],"seg1":"","seg2":"","x":572,"y":178,"wires":[]},{"id":"5b354f8b.7d822","type":"dsm","z":"8a242a1b.b175f8","name":"pump","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"stopped\",\n \"states\": {\n \"stopped\": {\n \"0\": \"running\"\n },\n \"running\": {\n \"1\": \"stopped\"\n }\n },\n \"methods\": {\n \"1\": \"sta.fill='red';\",\n \"0\": \"sta.fill='green';\"\n }\n}","x":366,"y":344,"wires":[["1ea566f8.2c8f89","ddd83bbe.062518","c840d30e.66876"]]},{"id":"1ea566f8.2c8f89","type":"debug","z":"8a242a1b.b175f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":576,"y":355,"wires":[]},{"id":"ddd83bbe.062518","type":"ui_gauge","z":"8a242a1b.b175f8","name":"","group":"a73d63c0.d5d3b","order":0,"width":0,"height":0,"gtype":"donut","title":"Montage","label":"units","format":"{{value}}","min":"1","max":"0","colors":["#ff0000","#e6e600","#ca3838"],"seg1":"","seg2":"","x":574,"y":412,"wires":[]},{"id":"548bb946.ed0f78","type":"rpi-gpio in","z":"8a242a1b.b175f8","name":"Raspberry PI 3","pin":"3","intype":"tri","debounce":"25","read":false,"x":181,"y":345,"wires":[["5b354f8b.7d822"]]},{"id":"9f5a0857.ce2218","type":"ui_button","z":"8a242a1b.b175f8","name":"","group":"1f7d2c43.889e74","order":0,"width":0,"height":0,"passthru":false,"label":"Everything is OK","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":591,"y":145,"wires":[[]]},{"id":"c840d30e.66876","type":"ui_button","z":"8a242a1b.b175f8","name":"","group":"a73d63c0.d5d3b","order":0,"width":0,"height":0,"passthru":false,"label":"Warning!!!!!!!!!!!!!!!!!!","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":597,"y":310,"wires":[[]]},{"id":"1f7d2c43.889e74","type":"ui_group","z":"","name":"Test 1","tab":"6a7cc0cd.5935e","disp":true,"width":"6","collapse":false},{"id":"a73d63c0.d5d3b","type":"ui_group","z":"","name":"Test 2","tab":"6a7cc0cd.5935e","disp":true,"width":"6","collapse":false},{"id":"6a7cc0cd.5935e","type":"ui_tab","z":"","name":"Monitoring System","icon":"dashboard"}]

```

I did this, Normally no contact green donut seeming and should be **everythings is OK**

but also red donut is active and Warning !!!!!!!! is looking active.

I just want to when everything is ok, green donut and Everything is active.  
when cable connected, green showing passive like grey and Warning is active.

How can I solve this problem ? Thanks for your advice.

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/abe0c4cdf06f1e0806f8b8d25b39ab020d962393.png)

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0fc499a55e31cf5e6568263401ba734d925022e5.png)

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [31 July 2018 08:04 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/11 "2018-07-31T08:04:34Z")

</div>

Let's see whether I understand you.

state 0:

pin 3 closed \> state 0 \> donut `green` and `Everything is OK`

state 1:

pin3 open \> state 1 \> donut `red` and `Warning!!!!!!!!!!!!!!!!!!`

Is it right?

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [31 July 2018 08:40 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/12 "2018-07-31T08:40:47Z")

</div>

Yes this is right, but I want to see both donuts sametime.

While state 0 situation left donut green and everything is OK, right donut default grey, like value 0  
While state 1 situation right donut red and Warning!!!!., left donut default grey, like value 0

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [31 July 2018 11:29 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/13 "2018-07-31T11:29:47Z")

</div>

Ok, I'll have a look but you should consider that you can't set the colour to green when the value is 0 (that is a donut's property; 0 = always grey).

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [31 July 2018 11:40 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/14 "2018-07-31T11:40:42Z")

</div>

Actually the donut is generally used to display a value like temperature (e.g. 0 until 30)  
What we can do is to set the button background.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [31 July 2018 12:43 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/15 "2018-07-31T12:43:59Z")

</div>

So actually question is basic.. Forget rest of them

Please think , 0 ( not connected ) and 1 ( connected ). When connected donut is green, when disconnected donut is red basically.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [31 July 2018 12:57 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/16 "2018-07-31T12:57:01Z")

</div>

You can not set a colour when the value is 0.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [31 July 2018 13:17 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/17 "2018-07-31T13:17:00Z")

</div>

Here is an example only with the buttons:

![pump-dsm2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b2ba01bc9372d105bf2f21f3829dd1666e2171e7.png)

```auto
[{"id":"2805c87d.5001a8","type":"dsm","z":"895bbff8.0e6c4","name":"state right","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"running\",\n \"states\": {\n \"stopped\": {\n \"0\": \"running\"\n },\n \"running\": {\n \"1\": \"stopped\"\n }\n },\n \"methods\": {\n \"onBeforeTransition\": \"msg.pyload = msg.payload.toString();\",\n \"0\": \"sta.fill='green';msg.background='green';msg.label='Everything is OK';\",\n \"1\": \"sta.fill='red';msg.background='grey';msg.label='grey text';\"\n }\n}","x":370,"y":720,"wires":[["e350df56.a272"]]},{"id":"1590ebfe.27c864","type":"rpi-gpio in","z":"895bbff8.0e6c4","name":"Raspberry PI 3","pin":"3","intype":"tri","debounce":"25","read":false,"x":162,"y":721,"wires":[["2805c87d.5001a8","bae279de.e744b8"]]},{"id":"bae279de.e744b8","type":"dsm","z":"895bbff8.0e6c4","name":"state left","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"running\",\n \"states\": {\n \"stopped\": {\n \"0\": \"running\"\n },\n \"running\": {\n \"1\": \"stopped\"\n }\n },\n \"methods\": {\n \"0\": \"sta.fill='green';msg.background='grey';msg.label='grey text';\",\n \"1\": \"sta.fill='red';msg.background='red';msg.label='Warning!';\"\n }\n}","x":370,"y":800,"wires":[["eebed04e.44dab"]]},{"id":"e350df56.a272","type":"ui_button","z":"895bbff8.0e6c4","name":"","group":"c70e5b9f.5344e8","order":2,"width":0,"height":0,"passthru":false,"label":"{{msg.label}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"str","topic":"","x":550,"y":720,"wires":[[]]},{"id":"eebed04e.44dab","type":"ui_button","z":"895bbff8.0e6c4","name":"","group":"2a642b4c.f284b4","order":0,"width":0,"height":0,"passthru":false,"label":"{{msg.label}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"str","topic":"","x":550,"y":800,"wires":[[]]},{"id":"c70e5b9f.5344e8","type":"ui_group","z":"","name":"Test 1","tab":"bd8aa435.42cfb8","order":1,"disp":true,"width":"6","collapse":false},{"id":"2a642b4c.f284b4","type":"ui_group","z":"","name":"Test 2","tab":"bd8aa435.42cfb8","order":2,"disp":true,"width":"6","collapse":false},{"id":"bd8aa435.42cfb8","type":"ui_tab","z":"","name":"Monitoring System","icon":"dashboard"}]

```

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [31 July 2018 13:19 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/18 "2018-07-31T13:19:31Z")

</div>

Yes I know, therefore I created second donut for this.

If one of them value 1 donut is green, other donut is default 0 and no color.

If value changed from 1 to 0, green donut changed color to default and other donut also should change color from default to red. And it sholud say Warning.

I expect this.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [31 July 2018 13:23 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/19 "2018-07-31T13:23:48Z")

</div>

Aha, this should work ...

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [31 July 2018 13:26 UTC](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697/20 "2018-07-31T13:26:10Z")

</div>

I think so, but didnt success it.

[Next page](https://discourse.nodered.org/t/how-can-i-make-logic-1-and-logic-0-graphical-with-node-red-and-rpi-3/1697.md?page=2)
