An alarm table from Modbus

I'm pulling in my alarm bits (8 of them) from modbus. Each bit represents a different fault (so there are 8 possible faults). Any combination of these bits may turn on at a time. if I have 2 faults, 2 messages will be displayed. If I have 1 fault, only 1 will be displayed.

Here I have 2 faults.
image

The problem I'm having each bit is its own msg.payload. So I have to combine them into a msg array for the ui-table. Then if no fault, I have to remove that bit from the array so it doesn't show in the ui-table.

below is where I'm at right now.

[{"id":"59f3e1c6.409f8","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"b2b00574.9c0b38","type":"ui_table","z":"59f3e1c6.409f8","group":"37b5f1bd.773eae","name":"","order":1,"width":"6","height":"4","columns":[],"outputs":1,"cts":true,"x":1170,"y":280,"wires":[["96345a40.ecad88"]]},{"id":"96345a40.ecad88","type":"function","z":"59f3e1c6.409f8","name":"add to schedule","func":"var x;\nvar msg1;\n\n\n\nmsg1 = {payload: flow.get(\"fault1\")}; msg1.payload[1] = flow.get(\"fault2\")[0];\n//msg1.payload[0] = flow.get(\"fault1\");\n//msg1.payload[1] = flow.get(\"fault2\");\n//msg1.payload[1] = flow.get(\"fault2\");\n\nreturn msg1; \n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":280,"wires":[["b2b00574.9c0b38","ec1a2fbd.07bf8"]]},{"id":"6b658f0a.879d6","type":"change","z":"59f3e1c6.409f8","name":"construct alarm 2 payload","rules":[{"t":"set","p":"fault2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":420,"wires":[["96345a40.ecad88"]]},{"id":"59065549.56f70c","type":"change","z":"59f3e1c6.409f8","name":"construct alarm 1 payload","rules":[{"t":"set","p":"fault1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":200,"wires":[["96345a40.ecad88","582dbdf1.99e134"]]},{"id":"ec1a2fbd.07bf8","type":"debug","z":"59f3e1c6.409f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1160,"y":220,"wires":[]},{"id":"ab231ba7.903f98","type":"comment","z":"59f3e1c6.409f8","name":"combines all messages","info":"prepare payload of alarms to deliver to table","x":980,"y":320,"wires":[]},{"id":"582dbdf1.99e134","type":"debug","z":"59f3e1c6.409f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":160,"wires":[]},{"id":"2735c37.ffcca3c","type":"switch","z":"59f3e1c6.409f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":380,"wires":[["6b658f0a.879d6"],[]]},{"id":"d3f6eaa.ff1e418","type":"switch","z":"59f3e1c6.409f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":220,"wires":[["59065549.56f70c"],[]]},{"id":"1c809828.7cd998","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"alarm","v":"all_fault","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"fault2","payload":"1","payloadType":"str","x":140,"y":360,"wires":[["2ca744e2.8e662c"]]},{"id":"f11e3bc1.526ce8","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"alarm","v":"all_fault","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"fault2","payload":"0","payloadType":"str","x":130,"y":440,"wires":[["2ca744e2.8e662c"]]},{"id":"206e7f9c.c0e69","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"alarm","v":"all_fault","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"fault1","payload":"1","payloadType":"str","x":130,"y":180,"wires":[["d90a5af8.507868"]]},{"id":"8570b6a8.7bc3c8","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"alarm","v":"all_fault","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"fault1","payload":"0","payloadType":"str","x":130,"y":240,"wires":[["d90a5af8.507868"]]},{"id":"d90a5af8.507868","type":"rbe","z":"59f3e1c6.409f8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":350,"y":220,"wires":[["d3f6eaa.ff1e418"]]},{"id":"2ca744e2.8e662c","type":"rbe","z":"59f3e1c6.409f8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":350,"y":380,"wires":[["2735c37.ffcca3c"]]},{"id":"73c9678e.36c628","type":"comment","z":"59f3e1c6.409f8","name":"alarm 1","info":"","x":70,"y":140,"wires":[]},{"id":"b77f12a.3e75df","type":"comment","z":"59f3e1c6.409f8","name":"alarm 2","info":"","x":90,"y":400,"wires":[]},{"id":"37b5f1bd.773eae","type":"ui_group","name":"1750+ 1 alarms","tab":"78efbcf6.3781f4","order":2,"disp":true,"width":"6","collapse":false},{"id":"78efbcf6.3781f4","type":"ui_tab","name":"Scheduler","icon":"autorenew","order":2,"disabled":false,"hidden":false}]

Hi Traderjoe,

I did something similar recently. I am using a write-file node to make a text/csv file to store the alarmdata.
it is a slightly different way of working with the table. but it worked well for me. this will save you the trouble of combining alarm. Basically you will create a very simple database.

For it to work you just have to fill in the blue circled nodes with a file location on your system:

below is the code:

[{"id":"2dc9f69d.87d3da","type":"ui_table","z":"11610085.feb86f","group":"25192b4d.da7294","name":"","order":1,"width":"6","height":"4","columns":[],"outputs":1,"cts":true,"x":1350,"y":280,"wires":[[]]},{"id":"6b663600.e04968","type":"function","z":"11610085.feb86f","name":"add to schedule","func":"var x;\nvar msg1;\n\n\n\nmsg1 = {payload: flow.get(\"fault1\")}; msg1.payload[1] = flow.get(\"fault2\")[0];\n//msg1.payload[0] = flow.get(\"fault1\");\n//msg1.payload[1] = flow.get(\"fault2\");\n//msg1.payload[1] = flow.get(\"fault2\");\n\nreturn msg1; \n","outputs":1,"noerr":0,"x":980,"y":280,"wires":[["2dc9f69d.87d3da","8f06f382.b0fe2","7529be2e.3b012"]]},{"id":"6b8e885a.d74888","type":"change","z":"11610085.feb86f","name":"construct alarm 2 payload","rules":[{"t":"set","p":"fault2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":420,"wires":[["6b663600.e04968"]]},{"id":"25a85e4b.5c1892","type":"change","z":"11610085.feb86f","name":"construct alarm 1 payload","rules":[{"t":"set","p":"fault1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":220,"wires":[["6b663600.e04968","7c550996.e64008"]]},{"id":"8f06f382.b0fe2","type":"debug","z":"11610085.feb86f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1160,"y":220,"wires":[]},{"id":"3862eb26.5fc444","type":"comment","z":"11610085.feb86f","name":"combines all messages","info":"prepare payload of alarms to deliver to table","x":960,"y":240,"wires":[]},{"id":"7c550996.e64008","type":"debug","z":"11610085.feb86f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1030,"y":160,"wires":[]},{"id":"ed109552.619b28","type":"switch","z":"11610085.feb86f","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":380,"wires":[["6b8e885a.d74888"],[]]},{"id":"ee87ceff.95ad7","type":"switch","z":"11610085.feb86f","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":220,"wires":[["25a85e4b.5c1892"],[]]},{"id":"d9e7fbb5.075bd8","type":"inject","z":"11610085.feb86f","name":"","topic":"fault2","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":360,"wires":[["83a4c197.a77bf"]]},{"id":"ee4699b2.5f2858","type":"inject","z":"11610085.feb86f","name":"","topic":"fault2","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":440,"wires":[["83a4c197.a77bf"]]},{"id":"a15a472e.552338","type":"inject","z":"11610085.feb86f","name":"","topic":"fault1","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":180,"wires":[["48143d3.d206ec4"]]},{"id":"4cb03608.0cee38","type":"inject","z":"11610085.feb86f","name":"","topic":"fault1","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["48143d3.d206ec4"]]},{"id":"48143d3.d206ec4","type":"rbe","z":"11610085.feb86f","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":350,"y":220,"wires":[["ee87ceff.95ad7"]]},{"id":"83a4c197.a77bf","type":"rbe","z":"11610085.feb86f","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":350,"y":380,"wires":[["ed109552.619b28"]]},{"id":"b99c307d.ba46e","type":"comment","z":"11610085.feb86f","name":"alarm 1","info":"","x":70,"y":140,"wires":[]},{"id":"b02afd14.73f89","type":"comment","z":"11610085.feb86f","name":"alarm 2","info":"","x":90,"y":400,"wires":[]},{"id":"7529be2e.3b012","type":"function","z":"11610085.feb86f","name":"add time and date","func":"var date;\nvar string;\nstring = msg.payload;\ndate = new Date();\ndate = (date.getFullYear() + '-' + ('00' + (date.getMonth()+1)).slice(-2) + '-' + ('00' + date.getDate()).slice(-2) + ' ' + ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' + ('00' + date.getSeconds()).slice(-2));\nmsg.payload= date + \";\" + string;\nreturn msg;","outputs":1,"noerr":0,"x":1230,"y":520,"wires":[["4badc191.55f51"]]},{"id":"4badc191.55f51","type":"file","z":"11610085.feb86f","name":"","filename":"C:\\Users\\etc....","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":1460,"y":520,"wires":[[]]},{"id":"e76fe7b3.ef9ec8","type":"comment","z":"11610085.feb86f","name":"Create CSV file","info":"","x":1220,"y":480,"wires":[]},{"id":"80bf8459.7b28b8","type":"inject","z":"11610085.feb86f","name":"","topic":"Testmessage","payload":"TEST","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":970,"y":520,"wires":[["7529be2e.3b012"]]},{"id":"e8111b1f.9a8558","type":"file in","z":"11610085.feb86f","name":"Read alarmlog","filename":"C:\\Users\\etc....","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":1040,"y":660,"wires":[["903e3ffd.a79e5"]]},{"id":"86b4fddc.adf8e","type":"inject","z":"11610085.feb86f","name":"","topic":"","payload":"","payloadType":"date","repeat":"300","crontab":"","once":true,"onceDelay":0.1,"x":830,"y":660,"wires":[["e8111b1f.9a8558"]]},{"id":"903e3ffd.a79e5","type":"csv","z":"11610085.feb86f","name":"","sep":";","hdrin":false,"hdrout":true,"multi":"mult","ret":"\\r\\n","temp":"Datum, alarm","skip":"0","strings":false,"x":1230,"y":660,"wires":[["198a661e.e7d44a","ca471d4c.9de46"]]},{"id":"198a661e.e7d44a","type":"ui_table","z":"11610085.feb86f","group":"76af1500.c8041c","name":"Log","order":11,"width":"15","height":"14","columns":[{"field":"Datum","title":"Datum","width":"50%","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"alarm","title":"alarm","width":"15%","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":0,"cts":false,"x":1430,"y":660,"wires":[]},{"id":"157f5f3a.8104a1","type":"comment","z":"11610085.feb86f","name":"tabl dashboard","info":"It refreshes every 5 minutes\nby editing the interval of the timestamp you\ncan change the refresh rate","x":820,"y":620,"wires":[]},{"id":"819ba911.7d17c8","type":"comment","z":"11610085.feb86f","name":"README","info":"If using LINUX system this node works \n\nif using MS windows use the 'real filepath'\n\nfor testing you could use c:\\desktop or similar folder. You need to have write permits to the folder you are using\n","x":1440,"y":480,"wires":[]},{"id":"ca471d4c.9de46","type":"debug","z":"11610085.feb86f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1410,"y":740,"wires":[]},{"id":"1506225.da923de","type":"file","z":"11610085.feb86f","name":"","filename":"C:\\Users\\etc....","appendNewline":true,"createDir":true,"overwriteFile":"true","encoding":"none","x":1460,"y":560,"wires":[[]]},{"id":"c3b7d12b.0fdbe","type":"inject","z":"11610085.feb86f","name":"","topic":"Delete logbook","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":960,"y":560,"wires":[["1506225.da923de"]]},{"id":"25192b4d.da7294","type":"ui_group","name":"1750+ 1 alarms","tab":"468a22e6.9d9c0c","order":2,"disp":true,"width":"6","collapse":false},{"id":"76af1500.c8041c","type":"ui_group","z":"","name":"Alarmtabel","tab":"636a33c5.96ddbc","order":1,"disp":true,"width":"15","collapse":false},{"id":"468a22e6.9d9c0c","type":"ui_tab","name":"Scheduler","icon":"autorenew","order":2,"disabled":false,"hidden":false},{"id":"636a33c5.96ddbc","type":"ui_tab","z":"","name":"Logboek","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Here's a version of the flow in case you want to study it also

Flow :

[{"id":"8ff28f20.ec1d2","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"dt","v":"$moment().format(\"YYYY-MM-DD HH:mm:ss\")","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Alarm2","payload":"1","payloadType":"str","x":200,"y":380,"wires":[["c6be28b9.52809"]]},{"id":"69bc841d.580b84","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"dt","v":"$moment().format(\"YYYY-MM-DD HH:mm:ss\")","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Alarm2","payload":"0","payloadType":"str","x":200,"y":460,"wires":[["c6be28b9.52809"]]},{"id":"88d58f87.7ec44","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"dt","v":"$moment().format(\"YYYY-MM-DD HH:mm:ss\")","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Alarm1","payload":"1","payloadType":"str","x":210,"y":200,"wires":[["cb7459c7.f6c6f"]]},{"id":"12edea1e.1d44de","type":"inject","z":"59f3e1c6.409f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"dt","v":"$moment().format(\"YYYY-MM-DD HH:mm:ss\")","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Alarm1","payload":"0","payloadType":"str","x":210,"y":260,"wires":[["cb7459c7.f6c6f"]]},{"id":"cb7459c7.f6c6f","type":"rbe","z":"59f3e1c6.409f8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":420,"y":240,"wires":[["40e4d10f.1cb3e8","6be9b4ee.95a3d4"]]},{"id":"c6be28b9.52809","type":"rbe","z":"59f3e1c6.409f8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":410,"y":420,"wires":[["4513e277.589a9c","6be9b4ee.95a3d4"]]},{"id":"1bfecc96.28b54b","type":"comment","z":"59f3e1c6.409f8","name":"alarm 1","info":"","x":140,"y":160,"wires":[]},{"id":"b1fad173.3c2c18","type":"comment","z":"59f3e1c6.409f8","name":"alarm 2","info":"","x":160,"y":420,"wires":[]},{"id":"40e4d10f.1cb3e8","type":"debug","z":"59f3e1c6.409f8","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":180,"wires":[]},{"id":"4513e277.589a9c","type":"debug","z":"59f3e1c6.409f8","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":480,"wires":[]},{"id":"6be9b4ee.95a3d4","type":"function","z":"59f3e1c6.409f8","name":"","func":"let alarms = flow.get(\"Alarms\") || {}\n\n\nif (msg.payload == \"1\") {\n\nlet obj = { \n    alarm : msg.topic,\n    dt: msg.dt,\n    status : \"ALARM\"\n    \n}\n\nalarms[msg.topic] = obj\n\nflow.set(\"Alarms\", alarms)\n\n}\n\nelse {\n    \n    delete alarms[msg.topic]\n   // flow.set(\"Alarms\", alarms)\n    \n}\n\nmsg.payload = Object.values(alarms)\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":340,"wires":[["d4bebd1b.31446"]]},{"id":"d4bebd1b.31446","type":"ui_table","z":"59f3e1c6.409f8","group":"194313aa.9e9cdc","name":"","order":0,"width":"16","height":"3","columns":[],"outputs":0,"cts":false,"x":870,"y":340,"wires":[]},{"id":"194313aa.9e9cdc","type":"ui_group","name":"Default","tab":"5757e8a7.9be318","order":1,"disp":true,"width":"16","collapse":false},{"id":"5757e8a7.9be318","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

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