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

It is not trivial but still possible . Try flow below:

[{"id":"b954bdf6.7ca99","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"de3905bc.b94e48","type":"dsm","z":"b954bdf6.7ca99","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":[["55e0c831.9bfc38","579cadf6.da28c4","61219a50.6c5804"]]},{"id":"55e0c831.9bfc38","type":"debug","z":"b954bdf6.7ca99","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":690,"y":240,"wires":[]},{"id":"26b12a92.7bc486","type":"dsm","z":"b954bdf6.7ca99","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":[["fb78b749.0678b8","78a9a1d1.82666","74564550.acddbc"]]},{"id":"fb78b749.0678b8","type":"debug","z":"b954bdf6.7ca99","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":610,"y":360,"wires":[]},{"id":"579cadf6.da28c4","type":"ui_button","z":"b954bdf6.7ca99","name":"","group":"dae20864.9f1898","order":2,"width":0,"height":0,"passthru":false,"label":"Everything is OK","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":490,"y":60,"wires":[[]]},{"id":"78a9a1d1.82666","type":"ui_button","z":"b954bdf6.7ca99","name":"","group":"27357b0e.7ff314","order":0,"width":0,"height":0,"passthru":false,"label":"Warning!!!!!!!!!!!!!!!!!!","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":597,"y":310,"wires":[[]]},{"id":"55646978.bdf258","type":"inject","z":"b954bdf6.7ca99","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":220,"wires":[["de3905bc.b94e48","26b12a92.7bc486"]]},{"id":"7e533f32.69977","type":"inject","z":"b954bdf6.7ca99","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":300,"wires":[["de3905bc.b94e48","26b12a92.7bc486"]]},{"id":"61219a50.6c5804","type":"function","z":"b954bdf6.7ca99","name":"Set gauge color","func":"if (msg.payload == 1) {\n    msg.ui_control = {\"options\":{\"levelColors\": [\"#00ff00\",\"#00ff00\",\"#808080\"]}}\n} else if (msg.payload == 0) {\n    msg.ui_control = {\"options\":{\"gaugeColor\":\"#00ff00\"}}\n}\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":160,"wires":[["83493f96.278c5","f1adb18f.4a81"]]},{"id":"83493f96.278c5","type":"debug","z":"b954bdf6.7ca99","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":830,"y":120,"wires":[]},{"id":"f1adb18f.4a81","type":"ui_gauge","z":"b954bdf6.7ca99","name":"","group":"dae20864.9f1898","order":1,"width":0,"height":0,"gtype":"donut","title":"Left","label":"units","format":"{{value}}","min":"0","max":"1","colors":["#ffffff","#ffffff","#ffffff"],"seg1":"","seg2":"","x":850,"y":180,"wires":[]},{"id":"74564550.acddbc","type":"function","z":"b954bdf6.7ca99","name":"Set gauge color","func":"if (msg.payload == 1) {\n    msg.ui_control = {\"options\":{\"levelColors\": [\"#ffffff\",\"#ffffff\",\"#ff0000\"]}}\n} \nreturn msg;","outputs":1,"noerr":0,"x":640,"y":420,"wires":[["78b2570d.c92d98","81de412b.ca197"]]},{"id":"78b2570d.c92d98","type":"debug","z":"b954bdf6.7ca99","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":850,"y":380,"wires":[]},{"id":"81de412b.ca197","type":"ui_gauge","z":"b954bdf6.7ca99","name":"","group":"27357b0e.7ff314","order":1,"width":0,"height":0,"gtype":"donut","title":"Right","label":"units","format":"{{value}}","min":"0","max":"1","colors":["#ffffff","#ffffff","#ffffff"],"seg1":"","seg2":"","x":870,"y":440,"wires":[]},{"id":"dae20864.9f1898","type":"ui_group","z":"","name":"Test 1","tab":"a3e07da6.f8a64","order":1,"disp":true,"width":"6","collapse":false},{"id":"27357b0e.7ff314","type":"ui_group","z":"","name":"Test 2","tab":"a3e07da6.f8a64","order":2,"disp":true,"width":"6","collapse":false},{"id":"a3e07da6.f8a64","type":"ui_tab","z":"","name":"Monitoring System","icon":"dashboard"}]

Try this:

[{"id":"2b6c1d8a.560de2","type":"dsm","z":"895bbff8.0e6c4","name":"state right","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        \"onBeforeTransition\": \"msg.payload = msg.payload.toString();\",\n        \"status\": {\n            \"fill\": {\n                \"get\": \"sm.currentState === 'stopped' ? 'red' : 'green'\"\n            },\n            \"shape\": \"dot\",\n            \"text\": {\n                \"get\": \"sm.currentState === 'stopped' ? 'state1' : 'state0'\"\n            }\n        }\n    }\n}\n","x":330,"y":660,"wires":[["aecef770.af0668","55ca9d2a.31a6a4","ef386a1c.699008"]]},{"id":"aecef770.af0668","type":"debug","z":"895bbff8.0e6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":543,"y":660,"wires":[]},{"id":"2f3234b7.75285c","type":"rpi-gpio in","z":"895bbff8.0e6c4","name":"Raspberry PI 3","pin":"3","intype":"tri","debounce":"25","read":false,"x":142,"y":721,"wires":[["2b6c1d8a.560de2","7ce3bed9.29bf3"]]},{"id":"55ca9d2a.31a6a4","type":"ui_gauge","z":"895bbff8.0e6c4","name":"","group":"3b5c2ca9.2fce64","order":0,"width":0,"height":0,"gtype":"donut","title":"Montage","label":"units","format":"{{value}}","min":0,"max":"1","colors":["#00f900","#e6e600","#00ff40"],"seg1":"","seg2":"","x":532,"y":608,"wires":[]},{"id":"7ce3bed9.29bf3","type":"dsm","z":"895bbff8.0e6c4","name":"state left","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        \"onBeforeTransition\": \"msg.payload = msg.payload === 0 ? '1' : '0';\",\n        \"status\": {\n            \"fill\": {\n                \"get\": \"sm.currentState === 'stopped' ? 'red' : 'green'\"\n            },\n            \"shape\": \"dot\",\n            \"text\": {\n                \"get\": \"sm.currentState === 'stopped' ? 'state1' : 'state0'\"\n            }\n        }\n    }\n}","x":330,"y":780,"wires":[["ed0f908c.e2c09","a9654171.14791","56aad3e.06b422c"]]},{"id":"ed0f908c.e2c09","type":"debug","z":"895bbff8.0e6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":536,"y":785,"wires":[]},{"id":"a9654171.14791","type":"ui_gauge","z":"895bbff8.0e6c4","name":"","group":"c22dbd6a.ea0f1","order":1,"width":0,"height":0,"gtype":"donut","title":"Montage","label":"units","format":"{{value}}","min":"0","max":"1","colors":["#ff0000","#e6e600","#ff2600"],"seg1":"","seg2":"","x":534,"y":842,"wires":[]},{"id":"ef386a1c.699008","type":"ui_button","z":"895bbff8.0e6c4","name":"","group":"3b5c2ca9.2fce64","order":0,"width":0,"height":0,"passthru":false,"label":"Everything is OK","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":551,"y":575,"wires":[[]]},{"id":"56aad3e.06b422c","type":"ui_button","z":"895bbff8.0e6c4","name":"","group":"c22dbd6a.ea0f1","order":2,"width":0,"height":0,"passthru":false,"label":"Warning!!!!!!!!!!!!!!!!!!","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":557,"y":740,"wires":[[]]},{"id":"3b5c2ca9.2fce64","type":"ui_group","z":"","name":"Test 1","tab":"8e6943f5.019c6","order":1,"disp":true,"width":"6","collapse":false},{"id":"c22dbd6a.ea0f1","type":"ui_group","z":"","name":"Test 2","tab":"8e6943f5.019c6","order":2,"disp":true,"width":"6","collapse":false},{"id":"8e6943f5.019c6","type":"ui_tab","z":"","name":"Monitoring System","icon":"dashboard"}]

Great! The option settings is a way to go, I didn't know that.

Indeed, this is detailed here: node-red-dashboard/config-fields.md at master Ā· node-red/node-red-dashboard Ā· GitHub

However you found a trivial solution ! Looks like you just changed the payload to string ?

Dear Andrei can we inject this trigging operation Raspberry GPIO.

When I disconnect cable pin 3 will trigging and when I connect cable not tricking

Dear cflurin didnt worked.

Really? it works for me.

ok I will test it again

Hi @wtrk,

It is not possible for me to use / test Raspberry nodes (since I do not have one of these devices). Because of that I have to simulate the GPIO pins. with inject nodes. Of course, you have to remove those inject nodes to test the flow. I could check the latest flow you posted but I need you to edit the post to include 3 backticks before and after the code (otherwise I am unable to import the flow). You could test the latest flow from @cflurin as it is was changed to work as you want.

@cflurin both of donut same time activating and deactivating. I try to make one of them active other one deactive.

When deactive change position deactive to active other donut also should change.

Right! the dsm expects a string "0" or "1" It did work but at start I got an undefined warning.
So first the value is converted to a string.

cflurin flow is working for me...

@wtrk if it still doesn't work for you, delete all yours versions (first do a backup) and import the flow again.

Edit: which dsm version are you using?

my dsm version is 0.7.1

Update to version 0.8.0 using the Manage palette

After update dsm version now it is working. Thank you for yor support.

Given that you use the donuts to show the state you might also use only one donut (@andrei'
s ui_control setting):

[{"id":"de780d41.a9457","type":"dsm","z":"895bbff8.0e6c4","name":"state right","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        \"onBeforeTransition\": \"msg.payload = msg.payload.toString();\",\n        \"0\": [\n            \"msg.ui_control = {'options':{'levelColors': ['#009000','#009000','#009000']}};\",\n            \"msg.background = 'green';\",\n            \"msg.label = 'Everything is OK';\"\n        ],\n        \"1\": [\n            \"msg.ui_control = {'options':{'levelColors': ['#ff0000','#ff0000','#ff0000']}};\",\n            \"msg.background = 'red';\",\n            \"msg.label = 'Warning!';\"\n        ],\n        \"onAfterTransition\": \"msg.payload = '1';\",\n        \"status\": {\n            \"fill\": {\n                \"get\": \"sm.currentState === 'running' ? 'green' : 'red';\"\n            },\n            \"shape\": \"dot\",\n            \"text\": {\n                \"get\": \"sm.currentState\"\n            }\n        }\n    }\n}","x":370,"y":660,"wires":[["9111aef8.91f09","7d8ca3d4.eb9c7c","55206e9a.96d1e"]]},{"id":"9111aef8.91f09","type":"debug","z":"895bbff8.0e6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":590,"y":700,"wires":[]},{"id":"162219b.fb00de6","type":"rpi-gpio in","z":"895bbff8.0e6c4","name":"Raspberry PI 3","pin":"3","intype":"tri","debounce":"25","read":false,"x":160,"y":660,"wires":[["de780d41.a9457"]]},{"id":"7d8ca3d4.eb9c7c","type":"ui_gauge","z":"895bbff8.0e6c4","name":"","group":"3b5c2ca9.2fce64","order":0,"width":0,"height":0,"gtype":"donut","title":"Montage","label":"","format":"","min":0,"max":"1","colors":["#00f900","#e6e600","#00ff40"],"seg1":"","seg2":"","x":580,"y":660,"wires":[]},{"id":"55206e9a.96d1e","type":"ui_button","z":"895bbff8.0e6c4","name":"","group":"3b5c2ca9.2fce64","order":0,"width":0,"height":0,"passthru":false,"label":"{{msg.label}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"str","topic":"","x":570,"y":620,"wires":[[]]},{"id":"3b5c2ca9.2fce64","type":"ui_group","z":"","name":"Test","tab":"8e6943f5.019c6","order":1,"disp":true,"width":"6","collapse":false},{"id":"8e6943f5.019c6","type":"ui_tab","z":"","name":"One Donut","icon":"dashboard"}]

In the ui open the tab one donut

1 Like

Dear @cflurin this is perfect thank you very much..

Hi @wtrk, please use3 backticts (```) before and after the code you are posting so it will display correctly for people to import and test. If possible please edit the earlier post.

OK done it, thank you for all your attention and helps.

1 Like