Programmatically read data from your Solar Inverter (Voltronic, Axpert, Mppsolar PIP, Voltacon, Effekta etc) and interface with Home Assistant via MQTT - Works with RS232 & USB!

Adjusted the QPIRI buffer size to 102 and now it seems to be functioning correctly.

warwick@linux-server:/opt/ha-inverter-mqtt-agent$ sudo docker exec -it voltronic-mqtt bash -c '/opt/inverter-cli/bin/inverter_poller -d -1'
[sudo] password for warwick:
Tue May  5 16:10:40 2020 INVERTER: Debug set
Tue May  5 16:10:40 2020 INVERTER: Current CRC: 49 C1
Tue May  5 16:10:40 2020 INVERTER: QMOD reply size (5 bytes)
Tue May  5 16:10:40 2020 INVERTER: QMOD: 5 bytes read: (L
Tue May  5 16:10:40 2020 INVERTER: QMOD query finished
Tue May  5 16:10:41 2020 INVERTER: Current CRC: B7 A9
Tue May  5 16:10:44 2020 INVERTER: QPIGS read timeout
Tue May  5 16:10:44 2020 INVERTER: QPIGS reply too short (8 bytes)
Tue May  5 16:10:44 2020 INVERTER: Current CRC: F8 54
Tue May  5 16:10:44 2020 INVERTER: QPIRI reply size (102 bytes)
Tue May  5 16:10:44 2020 INVERTER: QPIRI: 102 bytes read: (230.0 21.7 230.0 50.0 21.7 5000 4000 48.0 51.0 48.2 56.4 54.0 2 10 120 1 2 1 9 01 0 0 54.0 1 1 000
Tue May  5 16:10:44 2020 INVERTER: QPIRI query finished
Tue May  5 16:10:44 2020 INVERTER: Current CRC: B4 DA
Tue May  5 16:10:44 2020 INVERTER: QPIWS reply size (36 bytes)
Tue May  5 16:10:44 2020 INVERTER: QPIWS: 36 bytes read: (00000000000000000000000000000000
Tue May  5 16:10:44 2020 INVERTER: QPIWS query finished
Tue May  5 16:10:49 2020 INVERTER: Current CRC: B7 A9
Tue May  5 16:10:50 2020 INVERTER: QPIGS reply size (110 bytes)
Tue May  5 16:10:50 2020 INVERTER: QPIGS: 110 bytes read: (240.2 50.1 240.2 50.1 0624 0610 015 425 52.70 000 078 0052 0000 056.9 52.79 00001 00010110 00 00 00000 010
Tue May  5 16:10:50 2020 INVERTER: QPIGS query finished
INVERTER: ampfactor from config is 1.00
INVERTER: wattfactor from config is 1.01
{
  "Inverter_mode":3,
  "AC_grid_voltage":240.2,
  "AC_grid_frequency":50.1,
  "AC_out_voltage":240.2,
  "AC_out_frequency":50.1,
  "PV_in_voltage":56.9,
  "PV_in_current":0.0,
  "PV_in_watts":0.0,
  "PV_in_watthour":0.0000,
  "SCC_voltage":52.7900,
  "Load_pct":15,
  "Load_watt":610,
  "Load_watthour":20.3333,
  "Load_va":624,
  "Bus_voltage":425,
  "Heatsink_temperature":52,
  "Battery_capacity":78,
  "Battery_voltage":52.70,
  "Battery_charge_current":0,
  "Battery_discharge_current":1,
  "Load_status_on":1,
  "SCC_charge_on":1,
  "AC_charge_on":0,
  "Battery_recharge_voltage":51.0,
  "Battery_under_voltage":48.2,
  "Battery_bulk_voltage":56.4,
  "Battery_float_voltage":54.0,
  "Max_grid_charge_current":10,
  "Max_charge_current":120,
  "Out_source_priority":2,
  "Charger_source_priority":1,
  "Battery_redischarge_voltage":0.0,
  "Warnings":"00000000000000000000000000000000"
}
Tue May  5 16:10:50 2020 INVERTER: All queries complete, exiting loop.

Is this the correct thing to have done?

@ned-kelly and @Lee1

I just thought I would confirm that I have a Mecer SOL-I-AX-5M with Firmware 73.00e.

1 Like

yes now it looks correct

2 Likes

Hello @ned-kelly,

I was having a look through the shell scripts. Would I simply be able to change your current code

registerTopic () {
    mosquitto_pub \
        -h $MQTT_SERVER \
        -p $MQTT_PORT \
        -u "$MQTT_USERNAME" \
        -P "$MQTT_PASSWORD" \
        -t "$MQTT_TOPIC/sensor/"$MQTT_DEVICENAME"_$1/config" \
        -m "{
            \"name\": \""$MQTT_DEVICENAME"_$1\",
            \"unit_of_measurement\": \"$2\",
            \"state_topic\": \"$MQTT_TOPIC/sensor/"$MQTT_DEVICENAME"_$1\",
            \"icon\": \"mdi:$3\"
        }"
}

to

registerTopic () {
    mosquitto_pub \
        -h $MQTT_SERVER \
        -p $MQTT_PORT \
        -u "$MQTT_USERNAME" \
        -P "$MQTT_PASSWORD" \
        -t "$MQTT_TOPIC/sensor/"$MQTT_DEVICENAME"_$1/config" \
        -m "{
            \"name\": \"$4\",
            \"unique_id\": \""$MQTT_DEVICENAME"_$1\"
            \"unit_of_measurement\": \"$2\",
            \"state_topic\": \"$MQTT_TOPIC/sensor/"$MQTT_DEVICENAME"_$1\",
            \"icon\": \"mdi:$3\"
        }"
}

Then I would add a fourth text to the registerTopics eg:

registerTopic "AC_out_voltage" "V" "power-plug" "AC Output Voltage"
registerTopic "AC_out_frequency" "Hz" "current-ac" "AC Output Frequency"

Maybe I have misunderstood the information on the MQTT Discovery and MQTT sensor.

The main reason I am interested in this is that when using badges it makes life a lot easier if the friendly name has spaces in it as you can then see the full name, otherwise if there are no spaces it chops off the full name and does not apply word wrapping. I am sure I could probably apply the custom entity name to use for the badge in the ui-lovelace.yaml file but it would just be easier to edit in the mqtt shell code. The same goes for users not wanting to use you lovelace default and create their own layouts. Perhaps this could even be done in a configuration file to map you own friendly names to be displayed.

@Lee1, looking through this what may help you increased polling rates could be to use abbreviations for all the mqtt data to minimise the traffic data?

EDIT
Attempted this change and restarted the Docker container but it did not reflect any change to my Home Assistant. Tried to do an update on the MQTT integration but maybe I need to flush the autodiscovery data for changes to be seen. I am not using the Mosquitto Broker add-on through Supervisor as I am still having 502 Bad gateway errors with anything installed through the Supervisor add-ons. They randomly lose connection to Home Assistant. I still need to raise this issue on the forum.

Many thanks as always for the support.

1 Like

Glad you got it sorted - sorry been away from the keyboard the last few days with some issues that’s come up Down Under here :wink:

According to the docs your unique_id should work fine so not sure what’s going on there.

As for the whole discussion about using abbreviations in your MQTT Data, I really don’t think that’s going to make a great difference unless you’re on a wifi connection so slow your SSH connection is not even usable…

In reality, @Lee1’s changes that are speeding up the process, is the running of each mqtt_pub command in parallel in the background… There’s nothing wrong with this logic and it should be fine, as long as there’s a timeout command (set to kill long running processes - say longer than 30 seconds) in front of that, this way if mqtt_pub hangs on the SBC for whatever reason, you wont end up with 1000 processes running…

Hello @ned-kelly,

Do I need to flush the MQTT broker of its cached data to get the change I made to work.

Maybe I need to change more that what I listed in my previous post?

I guess it would probably be easier to just do the change from the Customize.yaml

Regards

Wazza

No need to flush MQTT, however you will need to re-register the sensors in home assistant (so remove them from HA, then let your updated code re-add them).

An alternative is to just restart HA (and it should remove the sensors anyway) then wait for your changes to automatically re-add them back in after a few moments.

@ned-kelly, I did a full restart of the computer with the docker containers and HA and that had no impact with the code adjustments I had made.

I did get the protocols for my BMS today and software that can show me all the data so now I need to see how I can build my own code to read the essentials from the BMS.

The guy also gave me some tweaked setting for the inverter which have helped.

Would it be safe to assume that the code for this inverter project will have the similar fundamentals of reading data from an RS485 device?

I am trying to figure out how the battery percentage is calculated on the Voltronic inverter? If anyone has some insight on this matter it would be appreciated. Perhaps I can calibrate it to be closer to the actual values of the battery as an interim measure while I work on creating the code for reading the data from the BMS.

I can’t be sure without diving into how your BMS works, but i’d be thinking it will be similar - You’re basically just going to need to write something to query the BMS using the protocol spec you got, and then parse the results - If you’re a little shabby with C, you might find some nice Node or Python scripts to interface with the serial connector for your RS323/485 etc…

Let us know how you go!

Hello @ned-kelly, thanks for the encouragement.

I am trying to understand the protocol and how it works. I have done some C# sharp programming and a very small amount of python for the gpio work on raspberry Pi and orange Pi. Did a fair amount of Java back at highschool and first year varsity. I am sure C cannot be too much different. I decompiled the windows form application I was supplied by the battery supplier. He walked me through the software. So I can see some of the data manipulation of the incoming bytes. However the decompiling process means there is very limited retention of the variable definitions to work out what data segments represent the useful values I need to read. Have not had enough of a look at the 23k lines of code but I do think I found segments for the battery current amp hour reading and the total as well as the main battery voltage. I am not going worry about reading the individual cell values. I will just try find the general warning state data and then can always go check it with the windows software. Can add all the extra data in time.

Need to try learn how to build a docker container with this program.

The battery supplier and my friend who supplied the battery to me are both keen for a solution like this.

1 Like

Hi everyone, I managed to instal and config everything exept the lovelace configuration, I want to figure out how to recieve all data first.
Im gueting almost everything, but thers missing the pv current and watts.
My inverter is the EASUN Isolar SMII 5KW

Mon May 11 15:32:03 2020 INVERTER: All queries complete, exiting loop.
root@raspberrypi:/opt/ha-inverter-mqtt-agent/sources/inverter-cli# sudo docker exec -it voltronic-mqtt bash -c ‘/opt/inverter-cli/bin/inverter_poller -d -1’
Mon May 11 15:33:46 2020 INVERTER: Debug set
Mon May 11 15:33:46 2020 INVERTER: Current CRC: 49 C1
Mon May 11 15:33:47 2020 INVERTER: QMOD reply size (5 bytes)
Mon May 11 15:33:47 2020 INVERTER: QMOD: 5 bytes read: (L
Mon May 11 15:33:47 2020 INVERTER: QMOD query finished
Mon May 11 15:33:47 2020 INVERTER: Current CRC: B7 A9
Mon May 11 15:33:47 2020 INVERTER: QPIGS reply size (110 bytes
Mon May 11 15:33:47 2020 INVERTER: QPIGS: 110 bytes read: (233.9 50.0 233.9 50.0 2523 2515 050 367 00.90 000 000 0040 0000 237.3 00.00 00000 00010110 00 00 01661 010
Mon May 11 15:33:47 2020 INVERTER: QPIGS query finished
Mon May 11 15:33:47 2020 INVERTER: Current CRC: F8 54
Mon May 11 15:33:48 2020 INVERTER: QPIRI reply size (102 bytes)
Mon May 11 15:33:48 2020 INVERTER: QPIRI: 102 bytes read: (230.0 21.7 230.0 50.0 21.7 5000 5000 48.0 46.0 42.0 56.4 54.0 0 30 050 0 1 0 9 01 0 0 54.0 0 1 000
Mon May 11 15:33:48 2020 INVERTER: QPIRI query finished
Mon May 11 15:33:48 2020 INVERTER: Current CRC: B4 DA
Mon May 11 15:33:48 2020 INVERTER: QPIWS reply size (36 bytes)
Mon May 11 15:33:48 2020 INVERTER: QPIWS: 36 bytes read: (00000000000000000000001000000000
Mon May 11 15:33:48 2020 INVERTER: QPIWS query finished
INVERTER: ampfactor from config is 1.00
INVERTER: wattfactor from config is 1.01
{
“Inverter_mode”:3,
“AC_grid_voltage”:233.9,
“AC_grid_frequency”:50.0,
“AC_out_voltage”:233.9,
“AC_out_frequency”:50.0,
“PV_in_voltage”:237.3,
“PV_in_current”:0.0,
“PV_in_watts”:0.0,
“PV_in_watthour”:0.0000,
“SCC_voltage”:0.0000,
“Load_pct”:50,
“Load_watt”:2515,
“Load_watthour”:167.6667,
“Load_va”:2523,
“Bus_voltage”:367,
“Heatsink_temperature”:40,
“Battery_capacity”:0,
“Battery_voltage”:0.90,
“Battery_charge_current”:0,
“Battery_discharge_current”:0,
“Load_status_on”:1,
“SCC_charge_on”:1,
“AC_charge_on”:0,
“Battery_recharge_voltage”:46.0,
“Battery_under_voltage”:42.0,
“Battery_bulk_voltage”:56.4,
“Battery_float_voltage”:54.0,
“Max_grid_charge_current”:30,
“Max_charge_current”:50,
“Out_source_priority”:1,
“Charger_source_priority”:0,
“Battery_redischarge_voltage”:2479706551232191660227961640976384.0,
“Warnings”:“00000000000000000000001000000000”


As you can see, QPIGS QMOD QPIRI QPWIS where set and working;

I tried to edit main.cpp file to change the order os results since we can see QPIGS is giving watts in the last part of the reply “01661” but without success. when I save and restart everything Im not getting anything different. What am I doing wrong?
I just started to watch some coding 2 weeks ago so sorry if I said something stupid.

Regards

1 Like

I have HASSIO as a virtualbox on a windows machine. This same machine has watchpower and is connected to the PIP5048GK inverter.
For me it would make more sense to use this machine rather than rpi. can i install this in a docker in hassio? it has portainer, but when i try docker-compose it says command not found. I am a newbie.
If above is not possible, i can install ubuntu with docker in virtual box on the same machine.

Also maybe this is wishful thinking but once setup can i have watchpower and this app both running at the same time as they are on the same machine?

Hello, maybe this is a silly question.

I was having major troubles with the Supervised Hass on Ubuntu with bad gateway on all the addons. I have now installed HassIO on VirtualBox and I added the Docker Image through portainer. What I am confused by on how to go about editing the two config files with this setup. How do I include the customised conf files using portainer.

Any advice would be helpful.

Hello @dopecoder, from what I know is that you cannot access the inverter from two separate programs at the same time as it is essentially a serial port. So you will get errors. I had a remote monitoring device connected via the serial interface and then I was trying to use the USB interface with custom Python code and it kept giving errors. This was because the two devices were fighting for access to the inverter.

Hi @Waz-Cpt, I have done exact same as you. and i an trying to figure the same thing out.

I am getting error on the container log “cat: /etc/inverter/mqtt.json: No such file or directory” and i don’t see inverter directory within /etc. If you have figured out let me know and i will do the same.

Thanks

Hi @dopecoder,

I am just in the process of setting up my raspberry pi with docker and this docker container.

I cannot figure out how to create a custom docker container.

I too looking for a way to get my modified main.cpp file get compiled. Please let me know if you figured it out. I wanted to read battery redischarge voltage data which is appearing at a different position (after one integer data) than in @ned-kelly code so I tried to skip it by adding a dummy variable in main.cpp code based on my assumption and then tried to compile using command “cmake . && make .” (again based on my assumption - I had to install compiler using command “sudo apt-get install build-essential cmake”). After this restarted the container (docker-compose up -d) but no change noticed.

Hi @Waz-Cpt, You will have to login to the container console via portainer UI. I installed vim in the container and then edited the inverter.conf file. In my case the MQTT.json file didnt exist. i manually created that. hope that helps.

1 Like

Hi, have my docker setup, I left the QPRI values default in conf file i have a PIP5048GK connected to a windows box with HASSOS running in a virtualbox.

the container logs show
Connection Refused: not authorised.
Error: Connection refused

when i check the inverter_poller -d all i get is below. it doesn’t show anything beyond ‘Debug set’. It seems like it cant connect to the inverter. any help appreciated. thanks

image

I have watchpower running on the same machine which is connecting to the inverter fine. please note i am not running both at the same time, i have disabled watchpower app and the watchpower background service.

@dopecoder where did you save that Json file?

@ned-kelly, have you had any experience with creating HassIO addons? Would it be worth it maybe looking at making your docker image work with the HassIO addons repositories?

@Waz-Cpt at /etc/inverter

1 Like