PV SolaX inverter cloud sensors via API

I have three inverters and the code works fine up to summing all three values. However, the last energy distribution code is not working. My whole code is in sensors.yaml file.

## X1a ##
- platform: rest
  resource: https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=4444444yyyyyyyyyyyy&sn=SWXXXXXXXX
  name: "Solax X1a"
  json_attributes_path: "$.result"
  json_attributes:
    - yieldtoday
    - yieldtotal
    - acpower
    - uploadTime
    - inverterStatus
  value_template: '1'  # dummy value, not used; avoids the "State max length is 255 characters" error
- platform: template
  sensors:
    solax_x1a_today:
      friendly_name: "Solax X1a today"
      value_template: "{{ state_attr('sensor.solax_x1a', 'yieldtoday') }}"
      unit_of_measurement: "KWh"
    solax_x1a_total:
      friendly_name: "Solax X1a total"
      value_template: "{{ state_attr('sensor.solax_x1a', 'yieldtotal') }}"
      unit_of_measurement: "KWh"
    solax_x1a_now:
      friendly_name: "Solax X1a now"
      value_template: "{{ state_attr('sensor.solax_x1a', 'acpower') }}"
      unit_of_measurement: "W"
    solax_x1a_upload_time:
      friendly_name: "Solax X1a upload time"
      value_template: "{{ state_attr('sensor.solax_x1a', 'uploadTime') }}"
    solax_x1a_status:
      friendly_name: "Solax X1 status"
      value_template: >
        {% if state_attr('sensor.solax_x1a', 'inverterStatus') == '100' %}Wait
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '101' %}Check
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '102' %}Normal
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '103' %}Fault
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '104' %}Permanent Fault
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '105' %}Update
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '106' %}EPS Check
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '107' %}EPS
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '108' %}Self-test
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '109' %}Idle
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '110' %}Standby
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '111' %}Pv Wake Up Bat
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '112' %}Gen Check
        {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '113' %}Gen Run
        {% else %}I dont know{% endif %}

## X1b ##
- platform: rest
  resource: https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=4444444yyyyyyyyyyyy&sn=SWXXXXXXXX
  name: "Solax X1b"
  json_attributes_path: "$.result"
  json_attributes:
    - yieldtoday
    - yieldtotal
    - acpower
    - uploadTime
    - inverterStatus
  value_template: '1'  # dummy value, not used; avoids the "State max length is 255 characters" error
- platform: template
  sensors:
    solax_x1b_today:
      friendly_name: "Solax X1b today"
      value_template: "{{ state_attr('sensor.solax_x1b', 'yieldtoday') }}"
      unit_of_measurement: "KWh"
    solax_x1b_total:
      friendly_name: "Solax X1b total"
      value_template: "{{ state_attr('sensor.solax_x1b', 'yieldtotal') }}"
      unit_of_measurement: "KWh"
    solax_x1b_now:
      friendly_name: "Solax X1b now"
      value_template: "{{ state_attr('sensor.solax_x1b', 'acpower') }}"
      unit_of_measurement: "W"
    solax_x1b_upload_time:
      friendly_name: "Solax X1b upload time"
      value_template: "{{ state_attr('sensor.solax_x1b', 'uploadTime') }}"
    solax_x1b_status:
      friendly_name: "Solax X1b status"
      value_template: >
        {% if state_attr('sensor.solax_x1b', 'inverterStatus') == '100' %}Wait
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '101' %}Check
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '102' %}Normal
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '103' %}Fault
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '104' %}Permanent Fault
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '105' %}Update
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '106' %}EPS Check
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '107' %}EPS
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '108' %}Self-test
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '109' %}Idle
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '110' %}Standby
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '111' %}Pv Wake Up Bat
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '112' %}Gen Check
        {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '113' %}Gen Run
        {% else %}I dont know{% endif %}

## X1h ##
- platform: rest
  resource: https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=4444444yyyyyyyyyyyy&sn=SWXXXXXXXX
  name: "Solax X1h"
  json_attributes_path: "$.result"
  json_attributes:
    - yieldtoday
    - yieldtotal
    - acpower
    - uploadTime
    - inverterStatus
  value_template: '1'  # dummy value, not used; avoids the "State max length is 255 characters" error
- platform: template
  sensors:
    solax_x1h_today:
      friendly_name: "Solax X1h today"
      value_template: "{{ state_attr('sensor.solax_x1h', 'yieldtoday') }}"
      unit_of_measurement: "KWh"
    solax_x1h_total:
      friendly_name: "Solax X1h total"
      value_template: "{{ state_attr('sensor.solax_x1h', 'yieldtotal') }}"
      unit_of_measurement: "KWh"
    solax_x1h_now:
      friendly_name: "Solax X1h now"
      value_template: "{{ state_attr('sensor.solax_x1h', 'acpower') }}"
      unit_of_measurement: "W"
    solax_x1h_upload_time:
      friendly_name: "Solax X1h upload time"
      value_template: "{{ state_attr('sensor.solax_x1h', 'uploadTime') }}"
    solax_x1h_status:
      friendly_name: "Solax X1h status"
      value_template: >
        {% if state_attr('sensor.solax_x1h', 'inverterStatus') == '100' %}Wait
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '101' %}Check
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '102' %}Normal
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '103' %}Fault
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '104' %}Permanent Fault
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '105' %}Update
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '106' %}EPS Check
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '107' %}EPS
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '108' %}Self-test
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '109' %}Idle
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '110' %}Standby
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '111' %}Pv Wake Up Bat
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '112' %}Gen Check
        {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '113' %}Gen Run
        {% else %}I dont know{% endif %}

- platform: template
  sensors:
    solax_today:
      friendly_name: Solax today
      unit_of_measurement: kWh
      value_template: "{{ (states('sensor.solax_x1a_today') | float) + (states('sensor.solax_x1b_today') | float) + (states('sensor.solax_x1h_today') | float)}}"
    solax_now:
      friendly_name: Solax now
      unit_of_measurement: W
      value_template: "{{ (states('sensor.solax_x1a_now') | float) + (states('sensor.solax_x1b_now') | float) + (states('sensor.solax_x1h_now') | float) }}"
    solax_total:
      friendly_name: Solax total
      unit_of_measurement: KWh
      value_template: "{{ (states('sensor.solax_x1a_total') | float) + (states('sensor.solax_x1b_total') | float)  + (states('sensor.solax_x1h_total') | float) }}"
    
- platform: template
  sensors:
    name: test_energy
    state: "{{ states('sensor.solax_total') }}" 
    unit_of_measurement: 'kWh'
    state_class: measurement
    device_class: energy
    attributes:         
      last_reset: '1970-01-01T00:00:00+00:0'

I get the following error:

Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']['device_class']. Got 'energy'
expected dictionary for dictionary value @ data['sensors']['name']. Got 'test_energy'
expected dictionary for dictionary value @ data['sensors']['state']. Got "{{ states('sensor.solax_total') }}"
expected dictionary for dictionary value @ data['sensors']['state_class']. Got 'measurement'
expected dictionary for dictionary value @ data['sensors']['unit_of_measurement']. Got 'kWh'
extra keys not allowed @ data['sensors']['attributes']['last_reset']. Got '1970-01-01T00:00:00+00:0'
required key not provided @ data['sensors']['attributes']['value_template']. Got None. (See ?, line ?). 

Same problem here. Tried your solution but it does not work. Anyone with a possible solution?

This also worked for for me, although I used an interval of 120

I think it depends how many times HA makes contact with the website, there is a maximum of 10.000 connections per Day.
In my configuration.yaml are 5 calls each time, wich make 5x60x24 = 7.200 connections per Day.
So if you have 2 inverters 60 seconds is not enough.

I was getting more concerned about the upload of my data to a third party in the cloud. I have moved on to a complete offline solution whereby I can extract the data from the inverter direct. For this I needed an extra raspberry Pi. Here is how I did it: SolaX inverter Wifi Reverse Proxy setup

1 Like

can you help me with the below?

sensor that you can use in the energy dashboard:

this is the code

‘’’’’’## X3 ##

  • platform: rest
    resource: https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=XXXXXXX&sn=XXXXXXX
    name: “Solax X3”
    json_attributes_path: “$.result”
    json_attributes:
    • yieldtoday
    • yieldtotal
    • acpower
    • uploadTime
    • inverterStatus
    • sn
      value_template: ‘1’ # dummy value, not used; avoids the “State max length is 255 characters” error
  • platform: template
    sensors:
    solax_x3_today:
    friendly_name: “Solax X3 today”
    value_template: “{{ state_attr(‘sensor.solax_x3’, ‘yieldtoday’) }}”
    unit_of_measurement: “KWh”
    device_class: energy
    solax_x3_total:
    friendly_name: “Solax X3 total”
    value_template: “{{ state_attr(‘sensor.solax_x3’, ‘yieldtotal’) }}”
    unit_of_measurement: “KWh”
    device_class: energy
    solax_x3_now:
    friendly_name: “Solax X3 now”
    value_template: “{{ state_attr(‘sensor.solax_x3’, ‘acpower’) }}”
    unit_of_measurement: “W”
    device_class: energy
    solax_x3_upload_time:
    friendly_name: “Solax X3 upload time”
    value_template: “{{ state_attr(‘sensor.solax_x3’, ‘uploadTime’) }}”
    solax_x3_status:
    friendly_name: “Solax X3 status”
    value_template: >
    {% if state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘100’ %}Wait
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘101’ %}Check
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘102’ %}Normal
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘103’ %}Fault
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘104’ %}Permanent Fault
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘105’ %}Update
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘106’ %}EPS Check
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘107’ %}EPS
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘108’ %}Self-test
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘109’ %}Idle
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘110’ %}Standby
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘111’ %}Pv Wake Up Bat
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘112’ %}Gen Check
    {% elif state_attr(‘sensor.solax_x3’, ‘inverterStatus’) == ‘113’ %}Gen Run
    {% else %}I dont know{% endif %}
    solax_x3_sn:
    friendly_name: “Solax X3 sn”
    value_template: “{{ state_attr(‘sensor.solax_x3’, ‘sn’) }}”
    template:
    • sensor:
    • name: test_energy
      state: “{{ states(‘sensor.solax_total’) }}”
      unit_of_measurement: ‘kWh’
      state_class: measurement
      device_class: energy
      attributes:
      last_reset: ‘1970-01-01T00:00:00+00:00’
      ‘’’’’’’’

This is the message that we get in the configuration test:

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘template’]. Got [OrderedDict([(‘sensor’, None)]), OrderedDict([(‘name’, ‘test_energy’), (‘state’, “{{ states(‘sensor.solax_total’) }}”), (‘unit_of_measurement’, ‘kWh’), (‘state_class’, ‘measurement’), (‘device_class’, ‘energy’), (‘attributes’, OrderedDict([(‘last_reset’, ‘1970-01-01T00:00:00+00:00’)]))])]. (See ?, line ?).

.
Do you have a idea what we do wrong?

Can you please repost the code in a proper format? (between …)

type or paste code here

I’ve got the API code and tried the URL (at night) but the only thing i’m getting is This sn did not access! is this due to the fact that it´s currently not on or am I doing something wrong?

{
success: false,
exception: "Query success!",
result: "this sn did not access!"
}

In the night my inverter goes in a kind of sleep mode and no data is available or transmitted. So nothing is wrong, just an efficient design.

Thanks for the quick response, I’ll just add it to my configuration than, and see what happens during the day!

Hi I’m new to Home Assistant so it might be that I am doing something wrong. I got the script working and the sensors are showing up on my dashboard. But when I try to add them to my engery page it does not display the sensors in the list.

No problemo, have a look at this solution: PV SolaX inverter cloud sensors via API - #45 by mpietersen

1 Like

Did the 2022.2 update break anybody else’s Energy dashboard? I still get the correct values in my lovelace card and even the template sensor is showing the correct value. But for some reason the energy dashboard doesn’t pick up on the sensor anymore although it’s still configured as a solar input in the energy dashboard settings.

1 Like

I’ve got the same issue you mentioned.

I can’t imagine we are the only two people facing this issue. Anybody else got some tips maybe on how we could get this working again?

Is it also possible to display the output of the individual strings? It is available in Solax Cloud, but I could find it in the documentation.

I get an error trying to add solax to the energy solar configuration:

statistics_not_defined
* sensor.test_energy`

No clue what it means.

I followed the instructions with minor modifications. This works for X1-booster and I have the PV yield showing up on the energy dashboard. As I am new to HA it took a bit of digging through posts. My setup described below. Hope this is of help to anyone struggling with the dashboard integration. Thanks to @Doublet and @heldopsokken.

The configuration is split in 3 parts:

  1. configuration.yaml
sensor: !include_dir_merge_list sensor/
template: !include_dir_merge_list template/
  1. solax.yaml
    Grab data via api, “PV now”, “PV today”, “PV total” are in preparation of a second system I am planning to get this year so I can sum up easily.
- platform: rest
  resource: https://www.eu.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=A&sn=B
  name: "Solax Garage"
  json_attributes_path: "$.result"
  json_attributes:
    - yieldtoday
    - yieldtotal
    - acpower
    - uploadTime
    - inverterStatus
  value_template: "1" # dummy value; not used; avoids error
- platform: template
  sensors:
    solax_garage_today:
      friendly_name: "Solax Garage today"
      value_template: "{{ state_attr('sensor.solax_garage', 'yieldtoday') }}"
      unit_of_measurement: "kWh"
    solax_garage_total:
      friendly_name: "Solax Garage total"
      value_template: "{{ state_attr('sensor.solax_garage', 'yieldtotal') }}"
      unit_of_measurement: "kWh"
    solax_garage_now:
      friendly_name: "Solax Garage now"
      value_template: "{{ state_attr('sensor.solax_garage', 'acpower') }}"
      unit_of_measurement: "W"
    solax_garage_upload_time:
      friendly_name: "Solax Garage upload time"
      value_template: "{{ state_attr('sensor.solax_garage', 'uploadTime') }}"
    solax_garage_status:
      friendly_name: "Solax Garage status"
      value_template: >
        {% if state_attr('sensor.solax_garage', 'inverterStatus') == '100' %}Wait
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '101' %}Check
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '102' %}Normal
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '103' %}Fault
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '104' %}Permanent Fault
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '105' %}Update
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '106' %}EPS Check
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '107' %}EPS
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '108' %}Self-test
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '109' %}Idle
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '110' %}Standby
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '111' %}Pv Wake Up Bat
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '112' %}Gen Check
        {% elif state_attr('sensor.solax_garage', 'inverterStatus') == '113' %}Gen Run
        {% else %}I dont know{% endif %}
    solax_now:
      friendly_name: "PV now"
      unit_of_measurement: "W"
      value_template: "{{ (states('sensor.solax_garage_now') | float) }}"
    solax_today:
      friendly_name: "PV today"
      unit_of_measurement: "kWh"
      value_template: "{{ (states('sensor.solax_garage_today') | float) }}"
    solax_total:
      friendly_name: "PV total"
      unit_of_measurement: "kWh"
      value_template: "{{ (states('sensor.solax_garage_total') | float) }}"
  1. pv_sensors.yaml
    For “device_class: energy” the “state_class” needs to be “total_increasing” as described here Energy Dashboard doesn't work - #5 by francisp
- sensor:
    - name: PV yield (Now)
      state: "{{ states('sensor.solax_now') | float }}"
      unit_of_measurement: "W"
      state_class: total_increasing
      device_class: energy
      attributes:         
        last_reset: '1970-01-01T00:00:00+00:00'
- sensor:
    - name: PV yield (Today)
      state: "{{ states('sensor.solax_today') | float }}"
      unit_of_measurement: "kWh"
      state_class: total_increasing
      device_class: energy
      attributes:         
        last_reset: '1970-01-01T00:00:00+00:00'
- sensor:
    - name: PV yield (Total)
      state: "{{ states('sensor.solax_total') | float }}"
      unit_of_measurement: "kWh"
      state_class: total_increasing
      device_class: energy
      attributes:         
        last_reset: '1970-01-01T00:00:00+00:00'
3 Likes

Thanks @schnetf changing the sensor state_class did the trick for me as well!!!

Yes you can. I have only one string, so i tested it with the attribute “powerdc1” there are also powerd2/3/4 values, check which one is filled for you.

You need to add “powerdc1” and “powerdc2” to the JSON json_attributes and add add a template sensor for it:

    solax_x1_now_string1:
      friendly_name: "Solax X1 now String1"
      value_template: "{{ state_attr('sensor.solax_x1', 'powerdc1') }}"
      unit_of_measurement: "W"

Keep in mind that is is the “Raw” pv watt and nog excactly what is feeding in to you house. But at least now you can see the data.