Email realtime Smappee usage periodically as CSV

Email realtime Smappee usage periodically as CSV

Collects realtime electricity/gas/water Smappee usage, saves it to CSV, and emails that CSV periodically.

[{"id":"2fbd5773.e2a5e8","type":"comment","z":"8087c031.70117","name":"Log realtime data to CSV file","info":"","x":280,"y":100,"wires":[]},{"id":"de74e58f.f903f8","type":"file","z":"8087c031.70117","name":"Log","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","x":550,"y":220,"wires":[]},{"id":"7c1293ed.07118c","type":"function","z":"8087c031.70117","name":"Format CSV","func":"const file = flow.get('smappee-log-file')\nconst delimiter = flow.get('smappee-csv-delimiter')\n\nconst datetime = new Date().toISOString()\nconst power = msg.payload.totalPower\nconst exportEnergy = msg.payload.totalExportEnergy\nconst importEnergy = msg.payload.totalImportEnergy\n\nreturn {\n    filename: `${file}`,\n    payload: `${datetime}${delimiter}${power}${delimiter}${exportEnergy}${delimiter}${importEnergy}`\n};","outputs":1,"noerr":0,"x":390,"y":220,"wires":[["de74e58f.f903f8"]]},{"id":"40dbbed9.933a8","type":"realtime","z":"8087c031.70117","name":"Realtime","device":"","x":220,"y":220,"wires":[["7c1293ed.07118c"]]},{"id":"f5e4c1a4.8def3","type":"e-mail","z":"8087c031.70117","server":"smtp.gmail.com","port":"465","secure":true,"name":"","dname":"Email","x":550,"y":280,"wires":[]},{"id":"2f9c1ef2.67e1a2","type":"function","z":"8087c031.70117","name":"Format email","func":"const date = new Date(msg.payload)\n\nreturn {\n    to: 'youremail',\n    topic: date.toISOString() + ' Log file as attachment',\n    attachments: [{\n        path: flow.get('smappee-log-file')\n    }],\n    payload: '<h1>Test message</h1><p>Lorem ipsum dolor sit amet</p>'\n};","outputs":1,"noerr":0,"x":390,"y":280,"wires":[["f5e4c1a4.8def3"]]},{"id":"b046e9f.a374f18","type":"function","z":"8087c031.70117","name":"Set variables","func":"const file = '/Users/youruser/Downloads/Smappee/Test.csv'\nconst delimiter = ','\n\nflow.set('smappee-log-file', file)\nflow.set('smappee-csv-delimiter', delimiter)\n\nreturn {}","outputs":1,"noerr":0,"x":390,"y":160,"wires":[[]]},{"id":"d5f72c72.433b6","type":"inject","z":"8087c031.70117","name":"Auto start","topic":"Auto start","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":220,"y":160,"wires":[["b046e9f.a374f18"]]},{"id":"d7f0902a.32a2","type":"inject","z":"8087c031.70117","name":"Weekly","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 12 * * 1","once":false,"x":220,"y":280,"wires":[["2f9c1ef2.67e1a2"]]}]
levismappee

Flow Info

created 3 months, 3 weeks ago

Node Types

Core
  • comment (x1)
  • e-mail (x1)
  • file (x1)
  • function (x3)
  • inject (x2)
Other
  • realtime (x1)

Tags

  • smappee
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option