Another Huawei solar integration option

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

1 Like

Hello @mayberryjp

great work - does it work stable for you?

I have buyed a Smartlogger 3000 A01 EU for my Huawei inverters (3 as a cascade with one Luna battery) while Iam planed to add one or two Huawei inverters. But I use HomeAssistant and search for a smart way to integrate my inverters and battery in HA.
So I hope your solution will work when I will try to use it.

#mayberryjp
Can you help me?
I tried you hack, and return json with { “00” 0.0000 }

And in cookies file not found Token, just:
#HttpOnly_192.168.0.10 FALSE / TRUE 0 -webserver-session-0 ::webs.session::3b340fc640496703faa9ee78ebb9b85c

It’s a SmartLOgger 3000 ? My code still works for me above. Maybe you need to upgrade the smartlogger to the latest version? If you’ve done all that, then run each command one by one and paste the output. Also verify the username and password is correct

Hi! Just used your mod and it worked perfectly!
Now I have 2 questions. 1st, can I somehow add a sensor for current PV energy yeld?
Second, I have 3 inverters connected via modbus to the system. Is there a possibility, to get values from each inverter, or not?

#1 - it should be in there. huawei_command_active_power
#2 - not sure - log into your smart logger and see if it’s in your user interface for the smart logger. check this page → replace the url with your own IP: https://192.168.50.38/get_set_page_info.asp?type=88

if it’s there it’s just a matter of adding more to the yaml file

note - you may need to turn off the script while trying to log in. otherwise your log in and HA login will compete with each other

i’ve moved this to a docker capable container with mqtt now. it’s a better implementation. there’s a dockerfile for building an image and a docker compose file also in the repo

you can set 6 environment variables

HUAWEI_HOST
HUAWEI_PASSWORD
HUAWEI_USERNAME
MQTT_HOST
MQTT_PASSWORD
MQTT_USERNAME

Hi @mayberryjp I’m able to get the information with the commands line by line in SSH. But when creating the huawei.sh and adding the data to configuration.yaml, the sensors don’t fill in data.
I also saw about your new method via docker. Do you have instruction on how to build the image? Or are you able to convert this into a HomeAssistant add-on?

afbeelding

Go here
i don’t really like the HA add ons - its a lot of work and rules without much upside

look at the file named dockerfile

in Portainer, go to your docker host, go to images, build a new image

give the build a name. paste the contents of dockerfile in the build.

suggested image name → huawei_smart_logger_docker:v1.0.10

when its finished, go to stacks, add stack

give it a name - suggested name is huawei_smart_logger_docker

paste the contents of the file “compose”

compose has some example environment variables. you’ll want to set all of the environment variables below

HUAWEI_HOST=https://192.168.50.38
HUAWEI_PASSWORD=
HUAWEI_USERNAME=admin
MQTT_HOS =192.168.x.x
MQTT_PASSWORD=
MQTT_USERNAME= 

this shold take about 5 minutes in total to get up and running

can view the logs to see any errors

i only use portainer so not sure how to use docker from command line - but im sure if you’re familiar with the command line then you can figure it out based on the dockerfile and compose

if anyone is using this - i pushed a new update to increase reliability of sensor delivery on mqtt. there’s a new dockerfile and compose in the repo

Cool thanks for the reply, I will first need to move our HA to a Proxmox host and it’s own VM. Will give me the ability to run multiple VM’s on the Intel NUC host.