Victron smart shunt to influxdb

This flows allows to gather the mart shunt information from victron, the smart shunt has a 4 pins grove type connector wich is a 3,3V serial line. (dont use the 3,3 volts coming from the supply pin to power anything since it draws very few current). so you ll need a 3.3V serial to usb adapter and do the correct wiring (useful info embedded in the flow). feel free to give some feedback as i m not realy versed in javascript, I just tried my best to make the mapping to be correct against the information givent by victron.

[{"id":"c698f097d14f8b21","type":"tab","label":"victron smart shunt","disabled":false,"info":""},{"id":"0b90034d1278455c","type":"serial in","z":"c698f097d14f8b21","name":"","serial":"ce2ee8cd4a809317","x":190,"y":200,"wires":[["29a1fc9bb88a6c49","983e36f822e8c175"]]},{"id":"05b9c58df8fa3aa8","type":"debug","z":"c698f097d14f8b21","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":320,"wires":[]},{"id":"0d210b272b69285b","type":"comment","z":"c698f097d14f8b21","name":"description","info":"inspired by : \nhttps://www.tarthorst.net/victron-ve-direct/\n\nsmart shunt VE.DIRECT pinout from left to right : \n3.3V | TX | RX | GND\n\ndo not connect 3.3 V and mind the ground loops depending on what you re connecting your device.\n\n\n The checksum is calculated over the entire block, including the line starting with Checksum, and including the newlines.\n\nTo calculate the checksum you have to add up all the ASCII values. The result of that should be a multiple of 256. Or, if you sum it all up in a byte variable, the result should be 0. The checksum character is used to make sure of that. That means that the checksum is not necessarily a printable character.\nmeaning its not even part of the ascii table , \ndue to conversion limitations, we first make the addition in buffer mode then convert to ascii readable caracters\n\nAn example in (Arduino) C++:\n\nbyte calcChecksum(String input) {\n  uint8_t checksum = 0;\n  for (int i = 0; i < input.length(); i++) {\n    checksum += input.charAt(i);\n  }\n  return (checksum);\n}","x":180,"y":100,"wires":[]},{"id":"29a1fc9bb88a6c49","type":"debug","z":"c698f097d14f8b21","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":160,"wires":[]},{"id":"983e36f822e8c175","type":"function","z":"c698f097d14f8b21","name":"devictronize buffer","func":"var msg2={}\n\nmsg2.label = []\nmsg2.value = []\nmsg2.payload=[]\nvar checksum = 0;\nvar mystring = \"\";\nvar myjson ={} ;\nvar label = [] ;\nvar value = [];\nvar mylines = \"\"\n//addition of all the buffer\nfor (i = 0; i < msg.payload.length; i++) {\n    checksum += msg.payload[i]; \n  }\n//modulo 256 shall give 0\nif (checksum % 256 === 0) {\n    //ASCIIfication\n    for (i = 0; i < msg.payload.length; i++) {\n       \n    mystring += String.fromCharCode(msg.payload[i]);\n    }\n    //mylines = mystring.toString().split('\\r').join(\"\\\")\n    // Split in lines\n    mylines = mystring.toString().split(\"\\r\\n\")\n    \n    \n    // find labels and values (tab separator)\n    for (i = 0; i < mylines.length; i++) {\n    templine = mylines[i].split(\"\\t\")\n    value = templine.pop()\n    label = templine.pop()\n    mytuple = {[label]: value }\n    myjson = { ...myjson, ...mytuple}\n    }\n}\nmsg.payload = [] ;\nvar myjsonindex = Object.keys(myjson)[1]\nif (myjsonindex === \"PID\") {\nmsg2.payload[1] =  {\n    \"ProductID\" : myjson.PID ,\n    \"Firmware Rev\" : myjson.FW,\n    \"Alarm\": myjson.Alarm ,\n    \"Alarm Reason\": myjson.AR,\n    \"Device Name\" : myjson.BMV\n    \n} //tags\nflow.set(\"tags\", msg2.payload[1] )\nmsg2.payload[0] = {\n    \"Voltage\":parseFloat(myjson.V),\n    \"Current\":parseFloat(myjson.I),\n    \"Power\":parseFloat(myjson.P),\n    \"State of charge\":parseFloat(myjson.SOC),\n    \"Time-to-go\" :parseFloat(myjson.TTG),\n    \"Auxilary voltage\" : parseFloat(myjson.VS),\n    \"Consumed Amp Hours\" : parseFloat(myjson.CE)\n}  //fields:\n\n}\nif (myjsonindex === \"H1\"){\n    msg2.payload[0] = {\n\"mAh Depth of the deepest discharge\":\tparseFloat(myjson.H1) ,\n\"mAh Depth of the last discharge\"\t:\t\t\t\t\tparseFloat(myjson.H2), \n\"mAh Depth of the average discharge\":\t\t\t\t\tparseFloat(myjson.H3) ,\n\"Number of charge cycles\"\t\t\t:\t\t\t\t\tparseFloat(myjson.H4) ,\t\t\t\t\t\n\"Number of full discharges\"          :                 parseFloat(myjson.H5) ,\n\"mAh Cumulative Amp Hours drawn\"\t:\t\t\t\t\tparseFloat(myjson.H6) ,\n\"mV Minimum main (battery) voltage\"\t:\t\t\t\tparseFloat(myjson.H7) ,\n\"mV Maximum main (battery) voltage\"\t:\t\t\t\tparseFloat(myjson.H8) ,\n\"Seconds Number of seconds since last full charge\":parseFloat(myjson.H9) ,\n\"Number of automatic synchronizations\":\t\t\t\tparseFloat(myjson.H10),\n\"Number of low main voltage alarms\"\t:\t\t\t\tparseFloat(myjson.H11),\n\"Number of high main voltage alarms\":\t\t\t\t\tparseFloat(myjson.H12),\n//\"Number of low auxiliary voltage alarms\":\t\t\t\tmyjson.H13,\n//\"Number of high auxiliary voltage alarms\":\t\t\tmyjson.H14,\n\"mV Minimum auxiliary (battery) voltage\":\t\t\t\tparseFloat(myjson.H15),\n\"mV Maximum auxiliary (battery) voltage\":\t\t\t\tparseFloat(myjson.H16),\n\"0.01 kWh Amount of discharged energy\"\t:\t\t\tparseFloat(myjson.H17),\n\"0.01 kWh Amount of charged energy\"\t\t:\t\t\tparseFloat(myjson.H18)\n}\n msg2.payload[1] = flow.get(\"tags\")\n}\nreturn msg2;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":380,"wires":[["05b9c58df8fa3aa8","74a810d2b3bea829"]]},{"id":"ce56b6968d975598","type":"comment","z":"c698f097d14f8b21","name":"protocol","info":"V       mV   Main (battery) voltage • • • •\nVS      mV   Auxiliary (starter) voltage • •\nVM      mV   Mid-point voltage of the battery bank •\nDM      ‰   Mid-point deviation of the battery bank •\nVPV     mV  Panel voltage •\nPPV     W   Panel power •\nI       mA  Battery current • • •2\nIL      mA  Load current •3\nLOAD        Load output state (ON/OFF) •4\nT       °C5 Battery temperature \n\n\nP W Instantaneous power •\nCE mAh6 Consumed Amp Hours • •\nSOC ‰6 State-of-charge • •\nTTG Minutes6, 7 Time-to-go • •\nAlarm Alarm condition active • •\nRelay Relay state • • •8\nAR Alarm reason • • •\nH1 mAh Depth of the deepest discharge • •\nH2 mAh Depth of the last discharge • •\nH3 mAh Depth of the average discharge • •\nH4 Number of charge cycles • •\nH5 Number of full discharges • •\nH6 mAh Cumulative Amp Hours drawn • •\nH7 mV Minimum main (battery) voltage • •\nH8 mV Maximum main (battery) voltage • •\nH9 Seconds Number of seconds since last full charge • •\nH10 Number of automatic synchronizations • •\nH11 Number of low main voltage alarms • •\nH12 Number of high main voltage alarms • •\nH13 Number of low auxiliary voltage alarms •\nH14 Number of high auxiliary voltage alarms •\nH15 mV Minimum auxiliary (battery) voltage • •\nH16 mV Maximum auxiliary (battery) voltage • •\nH17 0.01 kWh Amount of discharged energy •\nH18 0.01 kWh Amount of charged energy •\nH19 0.01 kWh Yield total (user resettable counter) •\nH20 0.01 kWh Yield today •\nH21 W Maximum power today •\nH22 0.01 kWh Yield yesterday •\nH23 W Maximum power yesterday •\nERR Error code •\nCS State of operation • •\nBMV Model description (deprecated) • •\nFW Firmware version • • • •\nPID Product ID • • •\nSER# Serial number • •\nHSDS Day sequence number (0..364) •9\nMODE Device mode •\nAC_OUT_V 0.01 V AC output voltage •\nAC_OUT_I 0.1 A AC output current •\nWARN Warning reason •","x":310,"y":100,"wires":[]},{"id":"74a810d2b3bea829","type":"influxdb out","z":"c698f097d14f8b21","influxdb":"56b679b2.97dca8","name":"","measurement":"SmartShunt","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":770,"y":400,"wires":[]},{"id":"38d33a7a0d2c4373","type":"debug","z":"c698f097d14f8b21","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":560,"wires":[]},{"id":"ce2ee8cd4a809317","type":"serial-port","serialport":"/dev/ttyVICTRON","serialbaud":"19200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"100","bin":"bin","out":"interbyte","addchar":"","responsetimeout":"10000"},{"id":"56b679b2.97dca8","type":"influxdb","hostname":"blacknuc.lan","port":"8086","protocol":"http","database":"conso","name":"","usetls":false,"tls":"","influxdbVersion":"1.x","url":"","rejectUnauthorized":false}]

Flow Info

Created 3 years, 7 months ago
Rating: 5 1

Owner

Actions

Rate:

Node Types

Core
  • comment (x2)
  • debug (x3)
  • function (x1)
Other
  • influxdb (x1)
  • influxdb out (x1)
  • serial in (x1)
  • serial-port (x1)
  • tab (x1)

Tags

  • victron
  • smartshunt
  • shunt
  • current
  • battery
  • monitor
  • LIFEPO
  • LIFEPO4
  • LITHIUM
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option