Building a real-time power monitoring dashboard

Building a real-time power monitoring dashboard

Like so many other people in South Africa, the unreliability of our power grid have forced me into taking the plunge and investing in an inverter with a lithium backup battery.

TL;DR

I used a raspberrypi to retrieve modbus data from the SunSynk inverter via a custom RS485 RJ45 to USB cable, logged the data into a MySQL table via a Nodejs app, and then used Grafana to display the data in a custom dashboard.

The details

After many weeks of research, I decided to go with a Sunsynk inverter, mainly due to its IP65 weatherproof rating as well as the fact that it has a great mobile app with tons of useful data in it.

For a battery, I eventually went with a BlueNova unit, simply because that was the option I have seen in action before.

For both inverter and battery, I went with 5kw, as that is enough for my home use. I am not intending to run heavy appliances (geysers and stove) through the inverter, so mainly lights, electronics and the occasional boiling of the kettle or running the microwave or air fryer.

After purchasing the BlueNova battery I was informed that its canbus protocol is not compatible with Sunsynk inverters. To solve this I needed to buy a BMAC module, which acts as a gateway, converting the BlueNova canbus protocol into something that the Sunsynk (& other inverter models) can understand.

Well, it’s a long story, but turns out that BlueNova’s BMAC unit is actually a waste of money, as it does not work properly, well mine at least (I suspect I was given a faulty second hand unit). My unit keeps losing its connection with the SunSynk inverter after a few minutes. Once it is rebooted it re-established the connection for a minute or two. BlueNova’s technical support was equally useless, with each query being lost in translation, and no helpful assistance forthcoming. Luckily I found a way to connect the BlueNova battery directly to the SunSynk inverter, by configuring the dip switches on the battery to use a different protocol, and by using specific cable pinouts to connect the two via a direct canbus connection over a RJ45 connection. This means the SunSynk inverter can now read the battery values directlywithout the need for the BMAC unit inbetween. First challenge overcome.

The next challenge was to find a way to pull stats out of the inverter. The SunSynk has a wifi dongle installed, and I was hoping that I could somehow access this and pull the data via a built-in Rest API. Sadly no such luck. SunSynk uploads the power statistics to their own cloud service (probably in China) from where their mobile app pulls it. This means there is a delay between values changing and it appearing in SunSynk’s mobile app. The app also only updates its values every five minutes, and there is no way to reduce this update interval.

So this was a no-go on multiple fronts, so the only course of action left was to find a way to pull stats directly out of the inverter. Luckily most modern hybrid inverters come with an RS485 port and use a standard Modbus protocol. I decided to use a raspberry pi 4B to access the inverter’s RS485 port. The raspberry pi also has an ethernet connection, allowing me to remotely access it.

For RS485 to USB I bought. one of these units from robotics.org in Stellenbosch. It took a while to figure out the correct cable layout (Thanks to Joseph Rautenbach for making a working cable). Once the cable was working I moved on to getting data out of the inverter.

I used the python modbus-cli library to access Modbus values over the USB serial interface. The modbus-cli interface allows you to fetch multiple values in one call. Figuring out which values to fetch was sorted by digging through kellerza’s Home Assistant python library. Luckily this library contains all the key Sunsynk modbus parameters, and it contains virtually all the values I needed for my dashboard. Luckily I could calculate the missing values from the ones supplied.

Now that I had access to the raw data it was simply a case of putting it all together. I created a node app that probes the required modbus parameters every ten seconds, and then store these in a MySQL database. To make the management of both the Node app and MySQL DB simpler, I installed both inside Docker containers, running directly on the raspberrypi.

I then created another Docker image running Grafana. Grafana is a very powerful dashboarding platform, and it is really easy to visualise any sort of data. I spent a lot of time working out the best way to visualise my stats, and below is the final version I ended up with (for now). This dashboard is close to real-time, as the values are updated every ten seconds.

The final challenge was to add push notifications to my phone so I (and others) can get real-time notifications when the power fails or is restored. To do this I used a PushBullet API subscription to send the push notifications. This is easy & elegant and works without any hassle. In future I will also be adding notifications to alert on low voltage, high load, etc.

Credit goes to Joseph Rautenbach for assistance in getting the data access to the SunSynk inverter working, and to Johann Kellerman for identifying the modbus parameter data coming out of the RS485 cable.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.