Hi all,
For anyone that has a Huawei solar system - you know there’s many different integration options including
- MODBUS TCP mode
- ECHONET LITE
- KIOSK MODE
- NORTHBOUND API
- Other custom integrations to get the smart meter data
- Using circuit clamps
The only “easy” option to get return-to-grid and feed-in-from-grid data is the northbound API, but, at least for me, Huawei basically refused to create a northbound API account for. Also, this depends on the cloud and some people don’t like this.
So, if you have a smartlogger 3000 in your setup, i offer my own hacked integration that gets you feed in to grid and return to grid entities that you can use in the energy dashboard. Basically, I reverse engineered the authentication mechanism and grab the statistics from their API.
This is the setup
drop this in /config folder and change your password and ip address of smart logger. this first part extracts the data into a json object
curl -s -o /dev/null 'https://192.168.50.38/action/login' --data-raw 'langlist=0&usrname=admin&string=YOURPASSWORD&vercodeinput=&login=Log+In' --compressed --insecure --cookie-jar /var/tmp/cookies
curl -s 'https://192.168.50.38/js/csrf.jst' --compressed --insecure -b /var/tmp/cookies | grep "tokenObj.value = \"" | awk {'print $3'} | sed s/[\"\;]//g >/var/tmp/huawei.token
TOKEN=`cat /var/tmp/huawei.token`
curl -s "https://192.168.50.38/get_set_page_info.asp?type=88" -H "x-csrf-token: $TOKEN" --compressed --insecure -b /var/tmp/cookies | sed s/\|/\\n/g | awk -F~ '{printf "%s:%f\n", $3, $8}' | grep -v null | tail -n +2 | sed s/\\s/_/g | sed s/\'//g | sed s/\\//_/g | tr '[:upper:]' '[:lower:]' > /var/tmp/huawei.strings
jq -sR '[split("\n")[:-1][] | rtrimstr("\\r") | split (":") | {(.[0]): .[1]} ] | add' /var/tmp/huawei.strings
add this command-line script to your configurations.yaml
command_line:
sensor:
name: "huawei_command_line"
command: "/config/huawei.sh"
json_attributes:
- grid-tied_active_power
- grid-tied_reactive_power
- load_power
- active_power
- reactive_power
- todays_power_supply_from_grid
- current_day_supply_from_grid
- current_day_feed-in_to_grid
- current_day_consumption
- total_power_supply_from_grid
- total_supply_from_grid
- total_feed-in_to_grid
- total_power_consumption
- pv_output_power
- battery_charge_discharge_power
- reactive_pv_power
- reactive_ess_power
- soc
- current-day_charge_capacity
- current-day_discharge_capacity
- total_charge
- total_discharge
- rated_ess_power
value_template: '{{ value_json.huawei }}'
add these sensors
template:
- sensor:
name: huawei_command_grid-tied_active_power
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','grid-tied_active_power') }}"
- sensor:
name: huawei_command_grid-tied_reactive_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','grid-tied_reactive_power') }}"
- sensor:
name: huawei_command_load_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','load_power') }}"
- sensor:
name: huawei_command_active_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','active_power') }}"
- sensor:
name: huawei_command_reactive_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','reactive_power') }}"
- sensor:
name: huawei_command_todays_power_supply_from_grid
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','todays_power_supply_from_grid') }}"
- sensor:
name: huawei_command_current_day_supply_from_grid
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','current_day_supply_from_grid') }}"
- sensor:
name: huawei_command_current_day_feed-in_to_grid
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','current_day_feed-in_to_grid') }}"
- sensor:
name: huawei_command_current_day_consumption
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','current_day_consumption') }}"
- sensor:
name: huawei_command_total_power_supply_from_grid
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','total_power_supply_from_grid') }}"
- sensor:
name: huawei_command_total_supply_from_grid
device_class: energy
unit_of_measurement: "kWh"
state_class: total_increasing
state: "{{ state_attr('sensor.huawei_command_line','total_supply_from_grid') }}"
- sensor:
name: huawei_command_total_feed-in_to_grid
device_class: energy
unit_of_measurement: "kWh"
state_class: total_increasing
state: "{{ state_attr('sensor.huawei_command_line','total_feed-in_to_grid') }}"
- sensor:
name: huawei_command_total_power_consumption
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','total_power_consumption') }}"
- sensor:
name: huawei_command_pv_output_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','pv_output_power') }}"
- sensor:
name: huawei_command_battery_charge_discharge_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','battery_charge_discharge_power') }}"
- sensor:
name: huawei_command_reactive_pv_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','reactive_pv_power') }}"
- sensor:
name: huawei_command_reactive_ess_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','reactive_ess_power') }}"
- sensor:
name: huawei_command_soc
device_class: battery
unit_of_measurement: "%"
state: "{{ state_attr('sensor.huawei_command_line','soc') }}"
- sensor:
name: huawei_command_current-day_charge_capacity
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','current-day_charge_capacity') }}"
- sensor:
name: huawei_command_current-day_discharge_capacity
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','current-day_discharge_capacity') }}"
- sensor:
name: huawei_command_total_charge
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','total_charge') }}"
- sensor:
name: huawei_command_total_discharge
device_class: energy
unit_of_measurement: "kWh"
state: "{{ state_attr('sensor.huawei_command_line','total_discharge') }}"
- sensor:
name: huawei_command_rated_ess_power
device_class: power
unit_of_measurement: "kW"
state: "{{ state_attr('sensor.huawei_command_line','rated_ess_power') }}"
it will expose these new sensors