Display a boolean state on dashboard

Hello,
I am new to node-red environment but am using it to create a dashboard to show live values collected from a PLC using the contrib-modbus node. i have been able to read my modbus integer registers and display them on the dashboard using text and chart nodes by watching videos and reading posts. I implemented a new flow to read 10 status coils from my PLC. i would like to have a basic text message on the dashboard for each coil that shows "coil on" or "coil off". I am not quite sure how to make this happen and would like to get pointed in the direction of some information that might help me out. how can i share the flow that i have started for this?
thank you,
Rich

Welcome to the forum @richlinares

  1. Highlight the nodes that you want to share.
  2. Ctrl - e (or hamburger menu/export)
  3. Click "compact" (top right) and "Copy to clipboard" (bottom right)
  4. In the forum click the </> button
  5. Paste your code over the top of "type or paste code here" That should leave a line with three back ticks before and after your code.

A screen capture of your dashboard would be good too.
Copy it to your clipboard and simply paste into the forum.

Hello Jbudd
Thanks for the reply. here is my code so far. so what i gather i am doing in storing the value of true/false for my first coil as a variable called SystemAuto in function53. what think i need to do is write an if else statement in function 54 to look at the value of SystemAuto and send either "off" or "on" as the msg payload. the problem i am having, being new to this environment, is how to build the if else statement. i get an error when trying to select my variable and the variable format that i entered does not produce the desired result as seen by the dashboard screenshot.
Thanks for the help,
Rich

[{"id":"a3541dc0a695da9b","type":"inject","z":"32d5778585348ef2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":120,"wires":[["04c3d9ef62408413"]]},{"id":"2099e17663d90d6b","type":"debug","z":"32d5778585348ef2","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":460,"y":100,"wires":[]},{"id":"04c3d9ef62408413","type":"modbus-getter","z":"32d5778585348ef2","name":"","showStatusActivities":false,"showErrors":false,"showWarnings":true,"logIOActivities":false,"unitid":"1","dataType":"Coil","adr":"0","quantity":"10","server":"701a340b0e9a1a28","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":260,"y":120,"wires":[["0393a96ef5550fe1","2099e17663d90d6b"],["6fe27e5cd69f2835"]]},{"id":"0393a96ef5550fe1","type":"modbus-response","z":"32d5778585348ef2","name":"","registerShowMax":20,"x":490,"y":40,"wires":[]},{"id":"6fe27e5cd69f2835","type":"function","z":"32d5778585348ef2","name":"function 53","func":"var coils = msg.payload.data //this line stores the modbus data in a variable called coils\nmsg.payload = { \n    'coil': coils, \n      } \nflow.set(\"SystemAuto\",msg.payload.coil[0]);    \nflow.set(\"Chiller1\",msg.payload.coil[1]);\nflow.set(\"Chiller2\",msg.payload.coil[2]);\nflow.set(\"ExhaustFan\",msg.payload.coil[3]);\nflow.set(\"Burner1\",msg.payload.coil[5]);    \nflow.set(\"Burner2\",msg.payload.coil[6]);\nflow.set(\"Valve1Auto\",msg.payload.coil[7]);\nflow.set(\"Valve2Auto\",msg.payload.coil[8]);\nflow.set(\"Valve3Auto\",msg.payload.coil[9]);\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":220,"wires":[["e42746c0780fefd1","f180f06a7c678711"]]},{"id":"e42746c0780fefd1","type":"debug","z":"32d5778585348ef2","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":460,"y":180,"wires":[]},{"id":"f180f06a7c678711","type":"function","z":"32d5778585348ef2","name":"function 54","func":"//msg = {payload:flow.get(\"SystemAuto\")}; this displays \"true\" or false on dashboard\n//msg = {payload:\"Off\"};\nif (msg.payload.coil[0] = false) {\n    msg = {payload:\"Off\"};\n}\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":280,"wires":[["0ae9642258e9f43a"]]},{"id":"0ae9642258e9f43a","type":"ui_text","z":"32d5778585348ef2","group":"b1fb89191f02e0ed","order":0,"width":0,"height":0,"name":"","label":"System Status","format":"{{msg.payload}}","layout":"row-left","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":460,"y":280,"wires":[]},{"id":"701a340b0e9a1a28","type":"modbus-client","name":"Productivity1000","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"192.168.0.103","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showErrors":false,"showWarnings":true,"showLogs":true},{"id":"b1fb89191f02e0ed","type":"ui_group","name":"System Status","tab":"c97895dbd8241ac7","order":11,"disp":true,"width":"16","collapse":false,"className":""},{"id":"c97895dbd8241ac7","type":"ui_tab","name":"Enerra Plant Dashboard","icon":"dashboard","disabled":false,"hidden":false}]

You can use the value format field and a conditional ternary expession for this
e.g.

[{"id":"0ae9642258e9f43a","type":"ui_text","z":"d1395164b4eec73e","group":"b1fb89191f02e0ed","order":0,"width":0,"height":0,"name":"","label":"System Status","format":"{{msg.payload.coil[0] ? \"On\" : \"Off\"}}","layout":"row-left","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":600,"y":200,"wires":[]},{"id":"6fe27e5cd69f2835","type":"function","z":"d1395164b4eec73e","name":"function 53","func":"var coils = msg.payload.data //this line stores the modbus data in a variable called coils\nmsg.payload = { \n    'coil': coils, \n      } \nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":200,"wires":[["e42746c0780fefd1","0ae9642258e9f43a"]]},{"id":"a3541dc0a695da9b","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload.data","v":"[false,true,false,true,false,true,false,true,false,true]","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":230,"y":200,"wires":[["6fe27e5cd69f2835"]]},{"id":"e42746c0780fefd1","type":"debug","z":"d1395164b4eec73e","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":160,"wires":[]},{"id":"b1fb89191f02e0ed","type":"ui_group","name":"System Status","tab":"c97895dbd8241ac7","order":11,"disp":true,"width":"16","collapse":false,"className":""},{"id":"c97895dbd8241ac7","type":"ui_tab","name":"Enerra Plant Dashboard","icon":"dashboard","disabled":false,"hidden":false}]

You might want to look at flowforge dashboard 2 as the older Angular dashboard is deprecated https://dashboard.flowfuse.com/

Also this function node

var coils = msg.payload.data //this line stores the modbus data in a variable called coils
msg.payload = { 
    'coil': coils, 
      } 
return msg

can be replaced with a change node like this


Or you could omit it entirely and just refer to msg.payload.data

Note that @E1cid has a text widget which displays msg.payload.coil[0], you can pass the identical message to another text widget displaying msg.payload.coil[1] and label "Chiller 1", etc.

Thanks for the tip, i see how that is working. i will attempt to implement as soon as i am back connected to my system

thank you both for the help, i was able to resolve my issue. i was following an example i found and making it work to my needs. so assigning variable names is not necessary i can just reference the examples listed above. in my original example, how would i be able to reference the variable names so they could be used? like for example in an If statement

In your OG function you created context variable, which you can not access in the dashboard nodes, as they are server side and the ui nodes run client side in the browser. If you had set them to msg properties then you could access them using msg.chiller etc.
e.g.
setting

msg.chiller = msg.payload.coil[0];

Then in ui-text node

{{msg.chiller}}

thanks for the explanation, it has all been very helpful.

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