Simple code to get all Data via API direct from you Solax Pocket Wifi 2.0 with firmare 3.003.02.
I found a very interesting post homeassistant-cz, copied the code, reworked it.
Running on
Home Assistant 2022.11.3
Supervisor 2022.10.2
Operating System 9.3
Frontend 20221108.0 - latest
You just need to add code to configuration.yaml, templates.yaml and then add 1 device to the energy dashboard.
add this to configuration.yaml don’t forget to adapt the IP of your solax module amd the password (just read the QR code on the stick)
### Solax REST command online sensor ###
rest:
- authentication: digest
scan_interval: 10
resource: http://###.###.###.####/ # IP of solax module
payload: "optType=ReadRealTimeData&pwd=xxxxxxxxxxx" # replace xxxxxxxxxx with password in whole file
method: POST
headers:
Content-Type: "application/x-www-form-urlencoded"
sensor:
- name: "solax_rest_data"
json_attributes:
- sn
- ver
- type
- Data
- Information
value_template: 'OK' # dummy value, not used; avoids the "State max length is 255 characters" error
add this to templates.yaml
if you don~t use a template.yaml file add the templates to configuration.yaml and add this on top (as mentioned by Trilis29)
do not forget to exchange the “xxxxxxxxx” with the serial number of your device.
- platform: template
sensors:
###Solax
- name: solax
state: >
{% if state_attr('sensor.solax_rest_data', 'sn') == "xxxxxxxxx" %}{{ now() }}
{% else %}{{ (states('sensor.solax')) }}{% endif %}
attributes:
sn: >-
{% if state_attr('sensor.solax_rest_data', 'sn') == "xxxxxxxxx" %}{{ (state_attr('sensor.solax_rest_data', 'sn')) }}
{% else %}{{ (state_attr('sensor.solax', 'sn')) }}{% endif %}
ver: >-
{% if state_attr('sensor.solax_rest_data', 'sn') == "xxxxxxxxx" %}{{ (state_attr('sensor.solax_rest_data', 'ver')) }}
{% else %}{{ (state_attr('sensor.solax', 'ver')) }}{% endif %}
type: >-
{% if state_attr('sensor.solax_rest_data', 'sn') == "xxxxxxxxx" %}{{ (state_attr('sensor.solax_rest_data', 'type')) }}
{% else %}{{ (state_attr('sensor.solax', 'type')) }}{% endif %}
Data: >-
{% if state_attr('sensor.solax_rest_data', 'sn') == "xxxxxxxxx" %}{{ (state_attr('sensor.solax_rest_data', 'Data')) }}
{% else %}{{ (state_attr('sensor.solax', 'Data')) }}{% endif %}
Information: >-
{% if state_attr('sensor.solax_rest_data', 'sn') == "xxxxxxxxx" %}{{ (state_attr('sensor.solax_rest_data', 'Information')) }}
{% else %}{{ (state_attr('sensor.solax', 'Information')) }}{% endif %}
###AC detailed information
- name: "Solax L1 Voltage"
state: "{{ state_attr('sensor.solax', 'Data')[0] | int(default=2300) / 10}}"
unit_of_measurement: "V"
device_class: "voltage"
- name: "Solax L2 Voltage"
state: "{{ state_attr('sensor.solax', 'Data')[1] | int(default=2300) / 10}}"
unit_of_measurement: "V"
device_class: "voltage"
- name: "Solax L3 Voltage"
state: "{{ state_attr('sensor.solax', 'Data')[2] | int(default=2300) / 10 }}"
unit_of_measurement: "V"
device_class: "voltage"
- name: "Solax L1 Current"
state: >
{% if state_attr('sensor.solax', 'Data')[3] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[3] - 65536) | int(default=0) / 10 }}
{% else %}{{ state_attr('sensor.solax', 'Data')[3] | int(default=0) / 10 }}{% endif %}
unit_of_measurement: "A"
device_class: "current"
- name: "Solax L2 Current"
state: >
{% if state_attr('sensor.solax', 'Data')[4] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[4] - 65536) | int(default=0) / 10 }}
{% else %}{{ state_attr('sensor.solax', 'Data')[4] | int(default=0) / 10 }}{% endif %}
unit_of_measurement: "A"
device_class: "current"
- name: "Solax L3 Current"
state: >
{% if state_attr('sensor.solax', 'Data')[5] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[5] - 65536) | int(default=0) / 10 }}
{% else %}{{ state_attr('sensor.solax', 'Data')[5] | int(default=0) / 10 }}{% endif %}
unit_of_measurement: "A"
device_class: "current"
- name: "Solax L1 Power"
state: >
{% if state_attr('sensor.solax', 'Data')[6] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[6] - 65536) | int(default=0) }}
{% else %}{{ state_attr('sensor.solax', 'Data')[6] | int(default=0) }}{% endif %}
unit_of_measurement: "W"
device_class: "power"
- name: "Solax L2 Power"
state: >
{% if state_attr('sensor.solax', 'Data')[7] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[7] - 65536) | int(default=0) }}
{% else %}{{ state_attr('sensor.solax', 'Data')[7] | int(default=0) }}{% endif %}
unit_of_measurement: "W"
device_class: "power"
- name: "Solax L3 Power"
state: >
{% if state_attr('sensor.solax', 'Data')[8] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[8] - 65536) | int(default=0) }}
{% else %}{{ state_attr('sensor.solax', 'Data')[8] | int(default=0) }}{% endif %}
unit_of_measurement: "W"
device_class: "power"
- name: "Solax Total AC Power"
state: >
{% if state_attr('sensor.solax', 'Data')[9] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[9] - 65536) | int(default=0) }}
{% else %}{{ state_attr('sensor.solax', 'Data')[9] | int(default=0) }}{% endif %}
unit_of_measurement: "W"
device_class: "power"
- name: "Solax L1 Frequency"
state: "{{ state_attr('sensor.solax', 'Data')[16] | int(default=5000) / 100}}"
unit_of_measurement: "Hz"
device_class: "frequency"
- name: "Solax L2 Frequency"
state: "{{ state_attr('sensor.solax', 'Data')[17] | int(default=5000) / 100}}"
unit_of_measurement: "Hz"
device_class: "frequency"
- name: "Solax L3 Frequency"
state: "{{ state_attr('sensor.solax', 'Data')[18] | int(default=5000) / 100}}"
unit_of_measurement: "Hz"
device_class: "frequency"
### Solax Summary and statistic sensors ###
- name: "Solax Feed-in Power"
state: >
{% if state_attr('sensor.solax', 'Data')[34] > 32767 %}{{ state_attr('sensor.solax', 'Data')[34] - 65536 }}
{% else %}{{ state_attr('sensor.solax', 'Data')[34] }}{% endif %}
unit_of_measurement: "W"
device_class: "power"
- name: "Solax Consumption"
state: >
{% if state_attr('sensor.solax', 'Data')[47] > 32767 %}{{ state_attr('sensor.solax', 'Data')[47] - 65536 }}
{% else %}{{ state_attr('sensor.solax', 'Data')[47] }}{% endif %}
unit_of_measurement: "W"
device_class: "power"
- name: "Solax Energy total"
state: "{{ ((state_attr('sensor.solax', 'Data')[69] * 65536) + state_attr('sensor.solax', 'Data')[68]) | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
### Today's statistics ###
- name: "Solax Grid out today"
state: "{{ state_attr('sensor.solax', 'Data')[90] | float / 100 }}"
unit_of_measurement: "kWh"
device_class: "energy"
- name: "Solax Grid in today"
state: "{{ state_attr('sensor.solax', 'Data')[92] | float / 100 }}"
unit_of_measurement: "kWh"
device_class: "energy"
- name: "Solax Battery discharge today"
state: "{{ state_attr('sensor.solax', 'Data')[78] | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
- name: "Solax Battery charge today"
state: "{{ state_attr('sensor.solax', 'Data')[79] | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
- name: "Solax Energy today"
state: "{{ state_attr('sensor.solax', 'Data')[82] | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
- name: "Solax Energy incl battery today"
state: "{{ state_attr('sensor.solax', 'Data')[70] | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
### Total values for Energy panel - needs customization in customize.yaml ###
- name: "Solax Solar energy total"
state: "{{ ((state_attr('sensor.solax', 'Data')[81] * 65536) + state_attr('sensor.solax', 'Data')[80]) | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
- name: "Solax Grid out total"
state: "{{ ((state_attr('sensor.solax', 'Data')[87] * 65536) + state_attr('sensor.solax', 'Data')[86]) | float / 100 }}"
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
- name: "Solax Grid in total"
state: "{{ ((state_attr('sensor.solax', 'Data')[89] * 65536) + state_attr('sensor.solax', 'Data')[88]) | float / 100 }}"
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
- name: "Solax Consumption total"
state: "{{ state_attr('sensor.solax', 'Data')[88] | float / 100 }}"
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
- name: "Solax Battery discharge total"
state: "{{ ((state_attr('sensor.solax', 'Data')[75] * 65536) + state_attr('sensor.solax', 'Data')[74]) | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
- name: "Solax Battery charge total"
state: "{{ ((state_attr('sensor.solax', 'Data')[77] * 65536) + state_attr('sensor.solax', 'Data')[76]) | float / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
state_class: total_increasing
### PV detailed information ###
- name: "Solax PV1 Voltage"
state: "{{ state_attr('sensor.solax', 'Data')[10] | int(default=0) / 10}}"
unit_of_measurement: "V"
device_class: "voltage"
- name: "Solax PV2 Voltage"
state: "{{ state_attr('sensor.solax', 'Data')[11] | int(default=0) / 10}}"
unit_of_measurement: "V"
device_class: "voltage"
- name: "Solax PV1 Current"
state: "{{ state_attr('sensor.solax', 'Data')[12] | int(default=0) / 10 }}"
unit_of_measurement: "A"
device_class: "current"
- name: "Solax PV2 Current"
state: "{{ state_attr('sensor.solax', 'Data')[13] | int(default=0) / 10 }}"
unit_of_measurement: "A"
device_class: "current"
- name: "Solax PV1 Power"
state: "{{ state_attr('sensor.solax', 'Data')[14] | int(default=0) }}"
unit_of_measurement: "W"
device_class: "power"
- name: "Solax PV2 Power"
state: "{{ state_attr('sensor.solax', 'Data')[15] | int(default=0) }}"
unit_of_measurement: "W"
device_class: "power"
- name: "Solax Total PV Power"
state: "{{ (states('sensor.solax_pv1_power')|int + states('sensor.solax_pv2_power')|int) }}"
unit_of_measurement: "W"
device_class: "power"
### Battery detailed information ###
- name: "Solax Battery Voltage"
state: "{{ state_attr('sensor.solax', 'Data')[39] | float / 100}}"
unit_of_measurement: "V"
device_class: "voltage"
- name: "Solax Battery Current"
state: >
{% if state_attr('sensor.solax', 'Data')[40] > 32767 %}{{ (state_attr('sensor.solax', 'Data')[40] - 65536) / 100 }}
{% else %}{{ state_attr('sensor.solax', 'Data')[40] / 100 }}{% endif %}
unit_of_measurement: "A"
device_class: "current"
- name: "Solax Battery Power"
state: >
{% if state_attr('sensor.solax', 'Data')[41] > 32767 %}{{ state_attr('sensor.solax', 'Data')[41] - 65536 }}
{% else %}{{ state_attr('sensor.solax', 'Data')[41] }}{% endif %}
unit_of_measurement: "W"
device_class: "power"
- name: "Solax Battery SoC"
state: "{{ state_attr('sensor.solax', 'Data')[103] | int(default=0) }}"
unit_of_measurement: "%"
- name: "Solax Battery Remain Energy"
state: "{{ state_attr('sensor.solax', 'Data')[106] | int(default=0) / 10 }}"
unit_of_measurement: "kWh"
device_class: "energy"
- name: "Solax Battery Temperature"
state: "{{ state_attr('sensor.solax', 'Data')[105] | int(default=0) }}"
unit_of_measurement: "°C"
device_class: "temperature"
- name: "Solax Battery BMS status"
state: >
{% if state_attr('sensor.solax', 'Data')[45] | int == 1 %}OK
{% else %}Fail{% endif %}
unit_of_measurement: "%"
### Invertor modes, states ###
- name: "Solax Battery Operation Mode"
state: >
{% if state_attr('sensor.solax', 'Data')[168] == 0 %}Self Use Mode
{% elif state_attr('sensor.solax', 'Data')[168] == 1 %}Force Time Use
{% elif state_attr('sensor.solax', 'Data')[168] == 2 %}Back Up Mode
{% elif state_attr('sensor.solax', 'Data')[168] == 3 %}Feed-in Priority
{% else %}I dont know{% endif %}
- name: "Solax Inverter Operation Mode"
state: >
{% if state_attr('sensor.solax', 'Data')[19] == 0 %}Waiting
{% elif state_attr('sensor.solax', 'Data')[19] == 1 %}Checking
{% elif state_attr('sensor.solax', 'Data')[19] == 2 %}Normal
{% elif state_attr('sensor.solax', 'Data')[19] == 3 %}Off
{% elif state_attr('sensor.solax', 'Data')[19] == 4 %}Permanent Fault
{% elif state_attr('sensor.solax', 'Data')[19] == 5 %}Updating
{% elif state_attr('sensor.solax', 'Data')[19] == 6 %}EPS Check
{% elif state_attr('sensor.solax', 'Data')[19] == 7 %}EPS Mode
{% elif state_attr('sensor.solax', 'Data')[19] == 8 %}Self Test
{% elif state_attr('sensor.solax', 'Data')[19] == 9 %}Idle
{% elif state_attr('sensor.solax', 'Data')[19] == 10 %}Standby
{% else %}I dont know{% endif %}
### Invertor and management module information ###
- name: "Solax Module SN"
state: "{{ state_attr('sensor.solax', 'sn') }}"
- name: "Solax module fw version"
state: "{{ state_attr('sensor.solax', 'ver') }}"
- name: "Solax type"
state: > # Other Solax invertor type are described in web API manual
{% if state_attr('sensor.solax', 'type') == 14 %}X3-Hybrid G4
{% else %}Other{% endif %}
- name: "Solax Inverter SN"
state: "{{ state_attr('sensor.solax', 'Information')[2] }}"
- name: "Solax Inverter Nominal Power"
state: "{{ state_attr('sensor.solax', 'Information')[0] | float | round(1) }}"
unit_of_measurement: "kW"
### Test parameters ###
- name: "Solax Inverter Temperature inner ?"
state: "{{ state_attr('sensor.solax', 'Data')[46] | int(default=0) }}"
unit_of_measurement: "°C"
device_class: "temperature"
- name: "Solax Inverter Temperature ?"
state: "{{ state_attr('sensor.solax', 'Data')[54] | int(default=0) }}"
unit_of_measurement: "°C"
device_class: "temperature"
do not forget to check configuration before rebooting.
After the reboot add “Solax Solar Energy total” to your energy dashboard as solar production and wait a little bit.
The trick to get the delta of the whole consumption into the energy board is this “state_class: total_increasing”