I have a Solax X1 Hybrid G4 (Solar PV and Battery).
I could not get the Solax Integration working with the required proxy (issues described here: SolaX inverter Wifi Reverse Proxy setup), so I went down the REST API road.
There is lots of advice about on this forum (including Energy dashboard and Solax grid and battery integration, PV SolaX inverter cloud sensors via API). They are long threads that have evovled. So I’ve put this together as a complete worked example, to get it all working with the HA Energy integration, using Solax as the sole source of data.
The end result…
Here is how I did it…
Pre Requisite
You’ll need a Solax Cloud Account, and your API key details.
Create REST Sensor
First create the REST API sensors:
sensor:
- platform: rest
resource: https://www.solaxcloud.com/proxyApp/proxy/api/getRealtimeInfo.do?tokenId=XXX&sn=YYY
name: "Solax"
json_attributes_path: "$.result"
json_attributes:
- yieldtoday
- yieldtotal
- acpower
- uploadTime
- inverterStatus
- feedinpower
- feedinenergy
- consumeenergy
- soc
- batPower
- powerdc1
- batStatus
value_template: 'Active' # dummy value, not used; avoids the "State max length is 255 characters" error
Replace XXX
and YYY
with the tokenId
and SerialNumber
found in the Solax Cloud respectively.
EDIT 12 Dec 2022
For other inverters / configurations you may need to edit the json_attributes
list above, and make corresponding changes to the template below.
To see what your inverter returns point a web browser at the link below (replacing XXX and YYY):
https://www.solaxcloud.com/proxyApp/proxy/api/getRealtimeInfo.do?tokenId=XXX&sn=YYY
Create Template Sensors for Solax…
template:
- sensor:
- name: "Solax Yield Today"
state: "{{ state_attr('sensor.solax', 'yieldtoday') }}"
unit_of_measurement: "kWh"
unique_id: solax_2
icon: mdi:flash
device_class: energy
state_class: total_increasing
- name: "Solax Yield Total"
state: "{{ state_attr('sensor.solax', 'yieldtotal') }}"
unit_of_measurement: "kWh"
unique_id: solax_3
icon: mdi:flash
device_class: energy
state_class: total_increasing
- name: "Solax Inverter Power Total"
unit_of_measurement: "W"
state: "{{ state_attr('sensor.solax', 'acpower') }}"
unique_id: solax_4
icon: mdi:flash
device_class: energy
state_class: measurement
- name: "Solax Upload Time"
state: >
{% set time = state_attr('sensor.solax', 'uploadTime') %}
{{ as_timestamp(time) | timestamp_custom('%I:%M %p') }}
unique_id: solax_5
icon: mdi:clock
- name: "Solax Battery Status"
state: "{{ state_attr('sensor.solax', 'batStatus') }}"
unique_id: solax_6
icon: mdi:battery
- name: "Solax Solar Panel"
state: "{{ state_attr('sensor.solax', 'powerdc1') }}"
unit_of_measurement: "W"
device_class: energy
state_class: measurement
unique_id: solax_7
icon: mdi:solar-power-variant
- name: "Solax Battery Use"
state: "{{ state_attr('sensor.solax', 'batPower') }}"
unit_of_measurement: "W"
device_class: energy
state_class: measurement
unique_id: solax_8
icon: mdi:battery
- name: "Solax Battery Use In"
state: >
{% set attr = state_attr('sensor.solax', 'batPower') %}
{{ attr if is_number(attr) and (attr|float > 0) else 0 }}
unit_of_measurement: "W"
unique_id: solax_9
icon: mdi:battery
- name: "Solax Battery Use Out"
state: >
{% set attr = state_attr('sensor.solax', 'batPower') %}
{{ (0 - attr) if is_number(attr) and (attr|float < 0) else 0 }}
unit_of_measurement: "W"
unique_id: solax_10
icon: mdi:battery
- name: "Solax Battery"
state: "{{ state_attr('sensor.solax', 'soc') }}"
unit_of_measurement: "%"
device_class: battery
state_class: measurement
unique_id: solax_12
icon: mdi:battery
- name: "Solax Grid Power"
state: >
{% set attr = state_attr('sensor.solax', 'feedinpower') %}
{{ (0 - attr) if is_number(attr) else 0 }}
unit_of_measurement: "W"
device_class: energy
state_class: measurement
unique_id: solax_13
icon: mdi:transmission-tower
- name: "Solax Grid Power in"
state: >
{% set attr = state_attr('sensor.solax', 'feedinpower') %}
{{ (0 - attr) if is_number(attr) and (attr|float < 0) else 0 }}
unit_of_measurement: "W"
unique_id: solax_14
icon: mdi:transmission-tower
- name: "Solax Grid Power out"
state: >
{% set attr = state_attr('sensor.solax', 'feedinpower') %}
{{ attr if is_number(attr) and (attr|float > 0) else 0 }}
unit_of_measurement: "W"
unique_id: solax_15
icon: mdi:transmission-tower
- name: "Solax Energy To Grid"
state: "{{ state_attr('sensor.solax', 'feedinenergy') }}"
unit_of_measurement: "kWh"
unique_id: solax_16
icon: mdi:transmission-tower
device_class: energy
state_class: total_increasing
- name: "Solax Energy From Grid"
state: "{{ state_attr('sensor.solax', 'consumeenergy') }}"
unit_of_measurement: "kWh"
unique_id: solax_19
icon: mdi:transmission-tower
device_class: energy
state_class: total_increasing
- name: "Solax Status"
unique_id: solax_20
icon: mdi:solar-power-variant
state: >
{% set attr = state_attr('sensor.solax', 'inverterStatus') %}
{% if attr == '100' %}Wait
{% elif attr == '101' %}Check
{% elif attr == '102' %}Normal
{% elif attr == '103' %}Fault
{% elif attr == '104' %}Permanent Fault
{% elif attr == '105' %}Update
{% elif attr == '106' %}EPS Check
{% elif attr == '107' %}EPS
{% elif attr == '108' %}Self-test
{% elif attr == '109' %}Idle
{% elif attr == '110' %}Standby
{% elif attr == '111' %}Pv Wake Up Bat
{% elif attr == '112' %}Gen Check
{% elif attr == '113' %}Gen Run
{% else %}unknown{% endif %}
- name: Total Home Use
unique_id: home use
state: >
{% set battery = states('sensor.solax_battery_use') %}
{% set grid = states('sensor.solax_grid_power') %}
{% set solar = states('sensor.solar_panel_power') %}
{% set total = 0 - battery|float if is_number(battery) else 0 %}
{% set total = total + (solar|float if is_number(solar) else 0) %}
{% set total = total + (grid|float if is_number(grid) else 0) %}
{{ total }}
state_class: measurement
icon: 'mdi:flash'
unit_of_measurement: W
device_class: power
Notes:
- The
unique_id
allows you to customise the Icon / Name in the HA Frontend. - I’ve added
state_class
in a few places from previous suggestions so that long term statistics are created. - The
Total Home Use
sesnor calculates my home total power consumption from all sources.
PowerCalc
I then used the PowerCalc integration to create energy sensors that can be used in the Energy integration. You’ll need to install this following its instructions (I used HACS).
sensor:
- platform: powercalc
entity_id: sensor.solax_solar_panel
name: Solar Panel
fixed:
power: "{{states('sensor.solax_solar_panel')}}"
- platform: powercalc
entity_id: sensor.solax_battery_use_in
name: Solar Battery In
fixed:
power: "{{states('sensor.solax_battery_use_in')}}"
- platform: powercalc
entity_id: sensor.solax_battery_use_out
name: Solar Battery Out
fixed:
power: "{{states('sensor.solax_battery_use_out')}}"
- platform: powercalc
entity_id: sensor.measured_power
name: Electric Consumption
fixed:
power: "{{states('sensor.measured_power')}}"
Utility Meter
I use Octopus Go for cheap overnight electricity to charge my battery, so I needed a Utility Meter to manage the peak/off peak tariff in the Energy Integration
utility_meter:
daily_grid:
source: sensor.solax_energy_from_grid
name: From Grid
cycle: daily
tariffs:
- peak
- offpeak
This also needed an automation to set the tariff:
alias: Set Electric Tariff
description: "Set Electric Tariff for utility sensor"
trigger:
- platform: time
at: "00:30:00"
variables:
tariff: offpeak
- platform: time
at: "04:30:00"
variables:
tariff: peak
condition: []
action:
- service: select.select_option
target:
entity_id: select.daily_grid
data:
option: "{{ tariff }}"
mode: single
Energy
To set up the HA energy dashboard, use the following sensors…
- Grid Consumption:
sensor.daily_grid_peak
andsensor.daily_grid_offpeak
- Return to Grid:
sensor.solax_energy_to_grid
- Solar Production:
sensor.solar_panel_energy
- Home Battery:
sensor.solar_battery_in_energy
andsensor.solar_battery_out_energy
NB: Once added to the dashboard, it will take an hour or two for data to become visible.
HA Frontend
I used the Power Flow Card integration to give a current snapshot of the output (screenshot above), in the same format as the HA Dashboard. You will need to install the Power Flow Card following its instructions (I used HACS).
type: vertical-stack
cards:
- type: entities
entities:
- entity: sensor.solax_upload_time
name: Last Update
- entity: sensor.solax_status
name: Inverter Status
- type: custom:power-flow-card
entities:
battery:
consumption: sensor.solax_battery_use_out
production: sensor.solax_battery_use_in
battery_charge: sensor.solax_battery
grid:
consumption: sensor.solax_grid_power_in
production: sensor.solax_grid_power_out
solar: sensor.solax_solar_panel
watt_threshold: 1000
Notes
The value in Energy are an approximation, as the Solax reports data to the cloud once every five minutes, so any peaks / dips in use during the 5 minute slots are missed (e.g. boiling a kettle).
I have found in practice my daily figures agree with other data sources withing 5%.
The way round this is to use the local API intergration to get the data rather than REST API (once the issues issues are solved).
I hope you find this useful!
Suggested improvements welcome.