Solax Inverter - keeping readings visible

Hi all,

I’ve been trying for months to be able to get readings direct from my Solax Inverter. It turns out that no matter what integration or custom integration I use I can not read the inverter locally because it uses a Pocket LAN for it’s network connection. I’m very disappointed by this, but I have been able to generate rest sensors which take the information from the cloud. This is great. However, most of the time they show unknown and when they do show information it might be for less then 30 seconds then they go back to unknown. Is there anyway to just keep them showing the last set of data that they received and then update at the next possible opportunity?

Thanks,

Tom



Just to highlight what I’m saying, the screenshots above demonstrate. All I’d like it to do is stop saying unavailable, is there a way to do this?

Thanks,

Tom

Hi, I have a solax X1 inverter, with a pocket wifi dongle, and I have done it a different way, which should work if you are using a pocket lan dongle.

I have setup dnsmasq to trick solax into sending the data to my Rasberry Pi that home assistant is on.

These are the setting I use:

#Solax Pocket wifi c8:39:64:76:53:1c MXCHIP
dhcp-host=c8:39:64:76:53:1c,10.0.1.8

address=/www.eu.solaxcloud.com/10.0.1.1
address=/mqtt001.solaxcloud.com/10.0.1.1
address=/mqtt002.solaxcloud.com/10.0.1.1

What this does is tells dnsmasq to allocate and IP address of 10.0.1.8 to the wifi dongle using its MAC address as ID, and tells solax inverter that there server are actually my Rpi (ip address 10.0.1.1)
The wifi dongle then publishes its MQTT data to 10.0.1.1

The same process can be used for the LAN dongle.

In home assistant:

binary_sensor:
  - platform: ping
    host: 10.0.1.8
    name: "solax_pocket_wifi"
    count: 2
    scan_interval: 300

automation:
 - alias: solar_check_offline
    description: "checks if received solar mqtt message within last 6 mins"
    trigger:
    - platform: state
      entity_id: binary_sensor.solar_communication
      from: 'on'
      to: 'off'
    condition:
    - condition: time
      after: '05:30:00'
      before: '19:30:00'
    action:
      - service: mqtt.publish
        data:
          topic: "solar/data_update_end_of_day"
          payload: ''


  - alias: solar_resptimesync
    description: "responds to reqsynctime message from solax inverter"
    trigger:
    - platform: mqtt
      topic: "reqsynctime/#"
    action:
      - service: mqtt.publish
        data:
          topic: 'respsynctime/{{ trigger.payload_json.wifisn }}'
          payload: >
            {"month":"{{now().month}}","hour":"{{now().hour}}","year":"{{now().year}}","day":"{{now().day}}","minute":"{{now().minute}}","second":"{{now().second}}"}

sensor:
  - platform: mqtt
    name: "solar_pv1_current"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[0] }}'
    unit_of_measurement: 'A'

  - platform: mqtt
    name: "solar_pv2_current"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[1] }}'
    unit_of_measurement: 'A'

  - platform: mqtt
    name: "solar_pv1_voltage"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[2] }}'
    unit_of_measurement: 'V'

  - platform: mqtt
    name: "solar_pv2_voltage"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[3] }}'
    unit_of_measurement: 'V'

  - platform: mqtt
    name: "solar_grid_current"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[4] }}'
    unit_of_measurement: 'A'

  - platform: mqtt
    name: "solar_grid_voltage"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[5] }}'
    unit_of_measurement: 'V'

  - platform: mqtt
    name: "solar_now"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[6] }}'
    unit_of_measurement: 'W'

  - platform: mqtt
    name: "solar_inverter_temp"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[7] }}'
    unit_of_measurement: '°C'

  - platform: mqtt
    name: "solar_today"
    state_topic: "loc/SWH53A7QPS"
    #value_template: "{{ value_json.data[8] |float(0) }}"
    value_template: '{{ value_json.data[8] }}'
    unit_of_measurement: 'kWh'

  - platform: mqtt
    name: "solar_total"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[9] }}'
    unit_of_measurement: 'kWh'

  - platform: mqtt
    name: "solar_total_mwh"
    state_topic: "loc/SWH53A7QPS"
    #value_template: "{{( value_json.data[9] | float(0) | float / 1000 )| round(2,default = 0) }}"
    value_template: '{{ (value_json.data[9] | float(0) / 1000 )| round(2,default = 0) }}'
    unit_of_measurement: 'mWh'

  - platform: mqtt
    name: "solar_pv1_power"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[11] }}'
    unit_of_measurement: 'W'

  - platform: mqtt
    name: "solar_pv2_power"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[12] }}'
    unit_of_measurement: 'W'

  - platform: mqtt
    name: "solar_gred_frequency"
    state_topic: "loc/SWH53A7QPS"
    value_template: '{{ value_json.data[50] }}'
    unit_of_measurement: 'Hz'

  - platform: mqtt
    name: "solar_status_code"
    state_topic: "loc/SWH53A7QPS"
    value_template: >
      {% if value_json is defined %} 
        {% if value_json.data[68] == 0 %}Wait
        {% elif value_json.data[68] == 1 %}Grid Sync
        {% elif value_json.data[68] == 2 %}Normal
        {% elif value_json.data[68] == 3 %}Lost grid
        {% elif value_json.data[68] == 9 %}Offline
        {% else %}{{ value_json.data[68] }} - Unknown
        {% endif %}
      {% else %}
        Offline
      {% endif %}

The binary_sensor is used to ping the wifi dongle every 5 minutes (300 seconds) to check if there is a connection.

The - alias: solar_resptimesync is an answer to the inverter when it asks the solaxcloud server for time information.

The advantage of this setup is no information leaves my property, and I have 24/7 access to it.
If the solaxcloud server is down home assistant can’t access any solar production data.
I have been using the above setup for a 3 or 4 years now without issue.

Anyways hope this is helpfully.

1 Like

This sounds very good, but I have no idea where to start with that. I’d just like HA to show what the last known reading was rather than switch to unavailable for a start off. I’m following the other threads about Solax integrations but I’m unable to apply their solutions at the moment due to having a pocket LAN. Why they couldn’t just have left the ethernet port on the inverter I do not know.

#Solax Pocket wifi c8:39:64:76:53:1c MXCHIP
dhcp-host=c8:39:64:76:53:1c,10.0.1.8
address=/www.eu.solaxcloud.com/10.0.1.1
address=/mqtt001.solaxcloud.com/10.0.1.1
address=/mqtt002.solaxcloud.com/10.0.1.1

Hi Davo, can this also be achieved within AdGuard? I have an instance running in my home which acts as DNS Server.

Best
Reinhard

Hi, AdGuard is not a DNS server, its an ad blocker.
You will need to setup a DNS server on your home assistant server or other computer you have on your network. Some wifi routers have the ability to redirect traffic. eg: you can put in a domain name and tell it what ip address to send requests to.
I went with dnsmasq because its simple to setup, but I also use BIND for my email/web/data servers which works too, but overkill for this and not as simple to setup.

yes, just use the custom filters for this to work. The only thing you need in Adguard is to redirect the A records: mqtt001.solaxcloud.com and mqtt002.solaxcloud.com to your home assistant (or other mqtt server) IP address.

In Adguard this can be done like this: Filters → DNS rewrites

Add as shown below:

Hi,
I did post a working code.
Feel free to use it

Hello, do you have more information on how to set this up? I have an X1 inverter and a separate X1-AC inverter for battery storage, I’m assuming the same approach will work for both?

What’s listening in the Pi in HA to capture the data? Apologies for all the question’s I’m new to HA.

Hi, the solax pocket wifi sends mqtt messages to solax cloud servers… so you can interrupt this, by using a dns server running on a pi and redirecting the messages to your pi (or other) server running HA.

You will require mosquitto and mosquitto-clients running on the pi to see these mqtt messages and send them to HA. However if you are installing on a new version of piOS (buster) you will need to download mosquitto and compile it as solax (or at least the pocket wifi version 2 i have doesn’t) doesn’t adhere to the mqtt message protocol properly. info on this is here: Local SolaX data | Blue Duck Valley Rd
My original setup used piOS bullseye which worked with the pocket wifi without a problem as the mosquitto broker version was 1.x which didn’t care if the packet identifier was sent to zero.

You will also need a dns server to send the mqtt messages to the pi. I use dnsmasq, and then add the solax redirects in /etc/dnsmasq.conf :

address=/www.eu.solaxcloud.com/10.0.1.1
address=/mqtt001.solaxcloud.com/10.0.1.1
address=/mqtt002.solaxcloud.com/10.0.1.1

this tells the pocket wifi to send its data to ip address 10.0.1.1 (my pi’s ip address)

I also have my pi set up as an access point using hostapd, so its a self contained system with no routers or access to internet needed. I often go overseas for 2 or 3 months at a time so everything gets turned off except the pi, which collects the data from my solar inverter, weather station etc and saves all the data to a influx database, and then I can display the data in HA…

This setup has been running since march 2019 when I get the solar installed without a problem.

Hi a question about redirecting with dnsmasq. Can we split the signal, i mean still sending data to solax cloud and still sending to local server? Because i would like to not loose remote control function, Thanks in advance to everyone

Hi, Yes you can send to both local and cloud. You can tell mosquitto to bridge to the solax cloud, so when a message comes into your sever it will forward to solaxcloud.

edit /etc/mosquitto/mosquitto.conf and your code would look something like this.

connection br-me-to-broker-solaxcloud
address mqtt001.solaxcloud.com:2901
topic loc/SWXXXXXXXX out 0

Replace SWXXXXXXXX with the topic of your solax pocket wifi

When i do this i get a error for being unauthenticated. What did you do?

1684176707: Received CONNACK on connection local.pve.br-me-to-broker-solaxcloud.
1684176707: Connection Refused: not authorised
1684176707: Client local.pve.br-me-to-broker-solaxcloud closed its connection.

What is your code and what port.
There are several messages that get sent back and forth before the inverter sends any data, below is what I had saved, but there might be more:

reqsynctime/SWPEXXXXX {"wifisn":"SWPEXXXXX"}
respsynctime/SWPEXXXXX{"month":"6","hour":"14","year":"2021","day":"7","minute":"16","second":"33"}
Synctime/SWPEXXXXX {"code":"1","message":"setting success"}

reqsynctime/SWPEXXXXX {"wifisn":"SWPEXXXXXX"}
base/up/SWPEXXXXX {"type":2,"wifiSN":"SWPEXXXXX","domain":"mqtt001.solaxcloud.com","port":2901}
respsynctime/SWPEXXXXX 2021-06-07T15:14
Synctime/SWPEXXXXX {"code":"1","message":"setting success"}

so maybe if not all sent it won’t authenticate. Its been a couple of years since I did this as I no long let any data from homeassistant/sensors/solar inverter etc to outside world.

What model pocket wifi module do you have ?

I would be using mosquitto_sub to see what messages are coming from the inverter or tcpdump or similar packet inspection too.