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


#1

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 ?


#2

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?


#3

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


#4

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

pump-dsm

Flow

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

#5

Or a function node

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

How many ways would you like? :slight_smile:


#6

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.


#7

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 ?


#8

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

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

#9

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 ?


#10
[{"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.


#11

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?


#12

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


#13

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).


#14

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.


#15

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.


#16

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


#17

Here is an example only with the buttons:

pump-dsm2

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

#18

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.


#19

Aha, this should work ...


#20

I think so, but didnt success it.