Sending HTML table as CSV via E-Mail event based

Hi guys,

I have a new project.

In this project, I collect the error messages of my system. I collect these with date, time, error level and description in a html-table to visualisate it on the dashboard.

[{"id":"dee16cb5.6b8b78","type":"inject","z":"23fe5c34.38f08c","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":370,"y":1360,"wires":[["13c6c2df.2695ad"]]},{"id":"f3d33b11.fd6e18","type":"inject","z":"23fe5c34.38f08c","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":371.0187530517578,"y":1485.4249877929688,"wires":[["13c6c2df.2695ad"]]},{"id":"71f0cb5a.2fb47c","type":"change","z":"23fe5c34.38f08c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"msg\":\"Emergency stop unlocked\",\"confirm\":\"3\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1400,"wires":[["ae9f05ea.4b0978"]]},{"id":"13c6c2df.2695ad","type":"switch","z":"23fe5c34.38f08c","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":1440,"wires":[["71f0cb5a.2fb47c"],["1100a1a1.c82106"]]},{"id":"1100a1a1.c82106","type":"change","z":"23fe5c34.38f08c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"msg\":\"Emergency stop actuated\",\"confirm\":\"3\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":1480,"wires":[["ae9f05ea.4b0978"]]},{"id":"ae9f05ea.4b0978","type":"function","z":"23fe5c34.38f08c","name":"add ts","func":"function addZero(i) {\n    if(i<10){\n        i=\"0\" + i;\n    }\n    return i;\n}\njs_obj      = msg.payload;\n\nvar d       = new Date();\nvar jstime  = d.getTime();\nvar time    = (addZero(d.getHours())) + \":\" + addZero(d.getMinutes()) + \":\" + addZero(d.getSeconds()); \nvar date    = d.getDate() + \".\" + \"0\" + (d.getMonth()+1) + \".\" + (d.getFullYear());\n\njs_obj.timestamp = jstime;\njs_obj.timedate  = time + ' ' + date ;\n\nmsg.payload = js_obj ;\n\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":810,"y":1440,"wires":[["eda77b4b.c7fcb"]]},{"id":"eda77b4b.c7fcb","type":"function","z":"23fe5c34.38f08c","name":"Cr/Upd msg_events","func":"var msg_obj       = msg.payload ;\nvar arr_msgs = flow.get(\"msg_events\", 'memoryOnly');\n\nif (arr_msgs===undefined ) {\n    // Create an empty array if it does not exist yet\n    arr_msgs = [];\n    //arr_msgs.push(msg_obj) ; \n        if (msg_obj !== \"1\") {\n            arr_msgs.push(msg_obj);\n            flow.set(\"msg_events\",arr_msgs, 'memoryOnly');\n        }\n    \n//    return msg ;\n\n} else {\n        // This is a new user, save and return in the first port\n        if (msg_obj !== \"1\") {\n            arr_msgs.push(msg_obj);\n            flow.set(\"msg_events\",arr_msgs, 'memoryOnly');\n        }\n} \nmsg.payload = flow.get(\"msg_events\", 'memoryOnly');\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":1440,"wires":[["33008200.b08dce"]]},{"id":"33008200.b08dce","type":"change","z":"23fe5c34.38f08c","name":"sort","rules":[{"t":"set","p":"payload","pt":"msg","to":"($sort(payload,function($l , $r){$l.timestamp < $r.timestamp }) )","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":1440,"wires":[["de34d4cd.b86e48"]]},{"id":"de34d4cd.b86e48","type":"change","z":"23fe5c34.38f08c","name":"","rules":[{"t":"set","p":"sprache","pt":"msg","to":"sprache","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1310,"y":1440,"wires":[["aac17959.9eded8"]]},{"id":"aac17959.9eded8","type":"function","z":"23fe5c34.38f08c","name":"topic & 20","func":"var arr = msg.payload ;\nvar i   = 10;\nif(typeof arr === undefined) {\n    return msg;\n} else {\n    if(msg.sprache==\"deutsch\"){\n    msg.payload = arr.slice(0, 30);    \n    msg.topic = 'Alarm Historie';\n    msg.meldung = 'Störung';\n    msg.zustand = 'Fehler Level';\n    msg.datum='Datum';\n    }\n    else{\n    msg.payload = arr.slice(0, 30);    \n    msg.topic = 'Alarm History';\n    msg.meldung = 'Failure';\n    msg.zustand = 'Failure Level';\n    msg.datum='Date';\n        \n    }\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1530,"y":1440,"wires":[["6dc7931a.9f3344"]]},{"id":"6dc7931a.9f3344","type":"template","z":"23fe5c34.38f08c","name":"html","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<font size=\"5\" color=\"black\">\n<table border=\"1\" cellpadding=\"1\">\n    <col width=\"400\">\n    <col width=\"250\">\n    <col width=\"200\">\n    \n    <thead>\n        <tr bgcolor=#A4A4A4>\n            <th colspan=\"3\" bgcolor=#A4A4A4 align=\"center\">{{topic}}</th>\n        </tr>\n    </thead>\n    \n    \n    <tr bgcolor=#D8D8D8>\n        <th bgcolor=#D8D8D8>{{meldung}}</th>\n        <th bgcolor=#D8D8D8 align=\"center\">{{zustand}}</th>\n        <th bgcolor=#D8D8D8>{{datum}}</th>\n    </tr>\n    \n    {{#payload}}\n        <tr class=\"\" bgcolor=#FFFFFF>\n            <td>{{msg}}</td>            \n            <td align=\"center\">{{confirm}}</td>\n            <td>{{timedate}}</td>\n        </tr>\n    {{/payload}}\n</table>\n</font>","output":"str","x":1720,"y":1420,"wires":[["18d5c3fb.c01b04","6adb4194.3aaa88"]]},{"id":"18d5c3fb.c01b04","type":"ui_template","z":"23fe5c34.38f08c","group":"d0b64090.947688","name":"Scrolling Messages","order":0,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\" height=\"400\" style=\"height: 950px;\"></div>\n<!--\n<style>\n    #Alarm_Historie_Fehlermeldungen,\n    #Alarm_Historie_Fehlermeldungen .nr-dashboard-spacer{\n        background: rgba(0,0,0,0);\n        border:rgba(0,0,0,0);\n        color:rgba(0,0,0,0);\n    }\n</style>\n-->\n<style>\n    #Alarm_Historie_Fehlermeldungen,\n    #Alarm_Historie_Fehlermeldungen_cards {\n        background:rgba(1,1,1,0);\n        border: none;\n        color: rgba(1,1,1,0);\n    }\n</style>\n<style>\n    #Alarm_Historie_Fehlermeldungen,\n    #Alarm_Historie_Fehlermeldungen md-card {\n        background: rgba(255,255,255,0);\n        border:none;\n        color: rgba(1,1,1,0);\n    }\n</style>\n<style>\n    #Alarm_Historie_Fehlermeldungen,\n    #Alarm_Historie_Fehlermeldungen .nr-dashboard-spacer {\n        background:rgba(1,1,1,0);\n        color:rgba(1,1,1,0);\n        border:none;\n    }\n</style>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":1910,"y":1260,"wires":[[]]},{"id":"2f3a0aff.e896a6","type":"inject","z":"23fe5c34.38f08c","name":"","repeat":"","crontab":"","once":false,"onceDelay":"0.1","topic":"","payload":"1","payloadType":"str","x":1040,"y":1380,"wires":[["34fa711.97b660e"]]},{"id":"34fa711.97b660e","type":"function","z":"23fe5c34.38f08c","name":"zap msg_events flow context","func":"var cfg = undefined ;\nflow.set('msg_events', cfg, 'memoryOnly');\n\nreturn msg;","outputs":1,"noerr":0,"x":1330,"y":1380,"wires":[[]]},{"id":"6adb4194.3aaa88","type":"csv","z":"23fe5c34.38f08c","name":"","sep":",","hdrin":false,"hdrout":"all","multi":"one","ret":"\\n","temp":"Timestamp,payload","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":1890,"y":1500,"wires":[["a51afc94.64354"]]},{"id":"a51afc94.64354","type":"debug","z":"23fe5c34.38f08c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2060,"y":1540,"wires":[]},{"id":"d0b64090.947688","type":"ui_group","name":"Fehlermeldungen 3","tab":"3c30c699.a6000a","order":3,"disp":false,"width":"15","collapse":false},{"id":"3c30c699.a6000a","type":"ui_tab","name":"Alarm Historie","icon":"dashboard","order":4}]

Now I want to send this table eventbased (button) to me via e-mail as a CSV file.

Do either of you have any idea how this works? :slight_smile:

Many thanks in advance

Georg

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