SolaX inverter Wifi Reverse Proxy setup

Hey well done! happy to see that you got it working too. Last question: I am using sensor.solax_swfXXXX_total_energy. Just try which one works.

1 Like

New day, new morning! Looks like Solax lost connection after reboot. ifconfig still shows the same as yesterday. However every entitie is unknown in HA except Solax SW********** PV1 Current. Did a couple of reboots, only PV1 shows information. Nginx works as well when I go to the RPI over network. Any suggestions?

inverter unknown

HA logger:

Logger: solax
Source: /usr/local/lib/python3.9/site-packages/solax/init.py:20
First occurred: 12:36:48 (1 occurrences)
Last logged: 12:36:48

Timeout connecting to Solax inverter, waiting 5 to retry.

And another one:

Logger: homeassistant
Source: helpers/entity.py:479
First occurred: 12:35:45 (12 occurrences)
Last logged: 12:41:45

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/solax/sensor.py”, line 105, in async_refresh
sensor.async_schedule_update_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 627, in async_schedule_update_ha_state
self.async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 479, in async_write_ha_state
raise RuntimeError(f"Attribute hass is None for {self}")
RuntimeError: Attribute hass is None for <Entity Solax SW********* PV2 Current>

Try this: SSH into the Pi

curl -X POST http://192.168.2.48/?optType=ReadRealTimeData

Should give something like:

{"type":"X1-Boost-Air-Mini","SN":"SWFXXXX","ver":"2.033.20","Data":[0.5,0.0,322.6,0.0,0.8,235.4,149,32,1.8,4370.9,0,188,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00,0.00,0,0,0,0,0,0,0,49.99,0,0,0,0,0,0,0,0,0,0.00,0,0,0,0,0.00,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"Information":[3.000,4,"X1-Boost-Air-Mini","XAG302F6095194",1,3.31,2.09,1.16,0.00]}

This does work as well. Still dont get my data in HA except PV1 current.

{"type":"X1-Boost-Air-Mini","SN":"SW********","ver":"2.033.20","Data":[0.8,0.0,1 25.0,0.0,0.6,230.0,92,33,0.6,1326.6,0,102,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0.00,0.00,0,0,0,0,0,0,0,50.01,0,0,0,0,0,0,0,0,0,0.00,0,0,0,0 ,0.00,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ,"Information":[1.500,4,"X1-Boost-Air-Mini","XMT152FB124021",1,1.17,0.00,1.14,0.

Update: Did a HA update and it’s working again. For now. I’ll keep you posted :slight_smile:

@Doublet Yesterday I tried to take out the Raspberry i’m using as a reverse proxy. It works, maybe you should take a look at it as well :slight_smile: link

1 Like

Hey Guys,

I’ve got this reversed proxy working, but as my wifi pocket is in my inverter it only works at day time. But I get a lot of errors when it’s off. Is there a way around this?

Same observation here, I just ignore the error messages.

Hello,

I don´t have a rasberry, I have HomeAssistance through a Virtual Machine. How should I do to connect my inverter to HomeAssistant them?

If I get to the inverter through 5.8.8.8 it seems that I have the Static IP address: 192.168.1.168 assigned to the inverter

and then I cannot access through my WIFI to that IP address (192.168.1.168 which is the inverter) neither though http://inverterip//.

and I cannot see the IP address of the inverter in my WIFI network

So, If I don´t connect my inverter (Solax Power X1) to my WIFI network, how can I connected to my HomeAssistant?

Thank you very much

For the reverse proxy setup, you need an additional Pi next to the device where HA is running. This additional Pi is making a connection over WiFi with the solax inverter. HA is connecting to this Pi over the LAN network,

Hi, I have a solax X1 inverter, with a pocket wifi dongle, and I have done it a different way, no revervse poxy setup or nginx etc, and is all run on 1 rasberry pi.

I have setup hostapd on the pi’s wifi adapter.

#/etc/hostapd/hostapd.conf
interface=wlan0
#driver=nl80211
ssid=sensor_ap
hw_mode=g
channel=11
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=xxxxxx
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

country_code=AU

Hostapd is setting up the r-pi wifi adapter as an access point. I then went into the solax wifi dongle by connecting to 5.8.8.8, and told it the wifi AP to use is sensor_ap.

I setup dnsmasq to trick solax into sending the data to my Rasberry Pi that home assistant is on when the wifi dongle sends DNS requests.

These are the setting I use for dnsmasq:

#/etc/dnsmasq.conf

#Solax Pocket wifi MAC addess - 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 their servers are actually my r-pi (ip address 10.0.1.1)
The wifi dongle then publishes its MQTT data to 10.0.1.1

You can also tell it to use the r-pi as your ntp (network time server) for all sensors/switchers like sonoff’s by adding the following:

address=/pool.ntp.org/10.0.1.1

The same process can be used for the LAN dongle, but the router it connects too needs to have DNS setting updated to point to r-pi…

In home assistant configuration.yaml:

binary_sensor:
  - platform: ping
    host: 10.0.1.8
    name: "solax_pocket_wifi"
    count: 2
    scan_interval: 300
  - platform: template
    sensors:
      solar_communication:
        friendly_name: "Solar Communication"
        value_template: >-
           {{ now().strftime( states('sensor.solar_last_update')) > (now()|as_timestamp - (6*60))|timestamp_custom('%H:%M') }}


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: "solax_inverter"
          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}}"}

  - alias: solax_inverter_status
    description: "sets all sensors to zero, except solar_today and solar total"
    trigger:
    - platform: mqtt
      topic: "solax_inverter"
    action:
      - service: mqtt.publish
        data:
          topic: 'loc/SWH53A7QPS'
          retain: true
          payload: >
            {"data":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,{{ states('sensor.solar_today') }},{{ states('sensor.solar_total') }},0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00,0.00,0,0,0,0,0,0,0,0.0,0,0,0,0,0,0,0,0,0,0.00,0,0,0,0,0.00,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}


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 check when the last mqtt message came from inverter, and if longer than 6 mins inverter is offline, and sets inverter status to offline and re-sets all data to zero except today and total kWh. You can also do this with a ping binary sensor, and then have an automation check if it is on or off

automation:
  - alias: solar_check_offline
    description: "checks if solax pocket wifi is up"
    trigger:
    - platform: state
      entity_id: binary_sensor.solax_pocket_wifi
      from: 'on'
      to: 'off'
    condition:
    - condition: time
      after: '06:00:00'
      before: '19:30:00'
    action:
      - service: mqtt.publish
        data:
          topic: "solax_inverter"
          payload: ''

The automation - alias: solar_resptimesync gives 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 using the API.
I have been using the above setup for 3 or 4 years now without issue.

Anyways hope this is helpfully.

6 Likes

I am getting a Solax X1 installed at the end of this month so have been watching these threads.

Instead of setting up hostapd etc, could you not just rewrite the DNS with AdGuard Home (or PiHole) and put it on the normal/NoT wifi?

You can use any dns lookup server you like, as long as it points to home assistant.
However for me I turn off all wifi routers at night (well actually most of the time as I use my phone to check emails etc) or when I go away so by using the r-pi home assistant is on, its all a self contained ecosystem, all that needs to be on is the r-pi.
And you can also use the pi access point for any other sensors, switches etc to connect to home assistant.

And this is the info I collect. Its all stored in an influx db, and I use apex chart card to display graphs. I don’t use any other add-on like node-red and grafana.

3 Likes

Hi I did everything as described. I can connect via Browser to the inverter (see image), but when I try to add it to HA, I get a “connection failed” error. Could this be because my Pocket WIFI dongle runs on Firmware Version 3.00…? Is it save do downgrade to 2.33…?

EDIT:

curl -X POST http://MY_RPI_IP/?optType=ReadRealTimeData

Just gives me a “502 Bad request”

OK, just in case anybody else is struggeling with the Pocket Wifi with Firmware ver3.001.02 - here is my solution:

Downgrade is not possible. The Firmware check fails with all firmwares 2.xx i have tried. So I ended up creating two commandline Sensors for the most basic readings I need, which are “Lifetime Energy” (for the Energy Dashboard) and “Current AC Power”.

- platform: command_line
  name: Solax Wechselrichter Total Energie
  command: "curl -d 'optType=ReadRealTimeData&pwd=SX.....' -X POST http://MY_RPI_IP"
  value_template: "{{ value_json.Data[19] | int * 100 }}"
  unit_of_measurement: "Wh"
  command_timeout: 10
  scan_interval: 300

- platform: command_line
  name: Solax Wechselrichter AC Leistung
  command: "curl -d 'optType=ReadRealTimeData&pwd=SX.....' -X POST http://MY_RPI_IP"
  value_template: "{{ ( value_json.Data[6] + value_json.Data[7] + value_json.Data[8] ) | int * 1 }}"
  unit_of_measurement: "W"
  command_timeout: 10
  scan_interval: 30

The solution is by far not perfect but it works for me at the moment. To bring the “Lifetime Energy” - Sensor into the Energy Dashboard a second Sensor needs to be created:

template:
  - sensor:
      - name: Solax Total Energy
        state: "{{ states('sensor.solax_wechselrichter_total_energie') }}"
        unit_of_measurement: Wh
        device_class: energy
        state_class: total_increasing
1 Like

I was able to downgrade with the firmware in the link. Did need a couple of tries/reboots if I remember correct.

Not sure if my dongle was shipped with a lower firmware. Edit: it was 2.034.03

Hi, thank you for a detailed tutorial. I have everything working just as you say - right up to the point ‘Time to notify HA’ . I cannot get any Solax info in HA. I have a separate sensors.yaml file where I added the sensor details:

  - platform: solax
    ip_address: MYPIIPADDRESS

Now I think I need to add the HA Integration but what IP Address, Port and Password do I need? I have tried all the options I can think of.
Any help much appreciated :slight_smile:

Best way is to give the RPI a fixed IP address, in my case 192.168.2.48. This is the ip_address I use in the HA integration

Thanks. Yes, I have given my pi a static IP of 192.168.68.121. Am I right o be using the HA Solax Integration?
For configuration, I am using my static IP, Port 80 and the dongle password. This will not connect.

yes you should use the HA solax integration with the RPI ip_address

Yes, this is what I am using, but no connection :frowning: . Do I have to use Port 80 or could I try something different?