How to attach the Hoymiles HiBattery AC 1920

Hi,

I finally made it work.

There are two ways:

  • either send your power measurement to uni-meter and attach it to the battery via the Shelly energy meter emulation. This did not work for me, no idea why.

  • send the target power via MQTT to the battery. This works just fine.

My primary problem was, that the MQTT data wasn’t automatically discovered by HA.
Maybe someone can improve the handling of the hoymiles battery?

I added this as a new package to HA:

mqtt:
  sensor:
    - name: "msa_battery_soc"
      unique_id: msa_battery_soc
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "%"
      device_class: battery
      state_class: measurement
      value_template: "{{ value_json.soc }}"

    - name: "msa_battery_power"
      unique_id: msa_battery_power
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.bat_p }}"

    - name: "msa_grid_power"
      unique_id: msa_grid_power
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.sys_grid_p }}"

    - name: "msa_pv_power"
      unique_id: msa_pv_power
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.sys_pv_p }}"

    - name: "msa_pv2_power"
      unique_id: msa_pv2_power
      state_topic: "homeassistant/sensor/MSA-280425=440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.sys_pv2_p }}"

    - name: "msa_load_power"
      unique_id: msa_load_power
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.sys_load_p }}"

    - name: "msa_system_battery_power"
      unique_id: msa_system_battery_power
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.sys_bat_p }}"

    - name: "msa_plug_power"
      unique_id: msa_plug_power
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.sys_plug_p }}"

    - name: "msa_eps_power"
      unique_id: msa_eps_power
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      value_template: "{{ value_json.sys_eps_p }}"

   - name: "msa_system_soc"
     unique_id: msa_system_soc
     state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
     unit_of_measurement: "%"
     device_class: battery
     state_class: measurement
     value_template: "{{ value_json.sys_soc }}"

    - name: "msa_battery_status"
      unique_id: msa_battery_status
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      value_template: "{{ value_json.bat_sts }}"  
      
  binary_sensor:
    - name: "msa_heating"
      unique_id: msa_heating
      state_topic: "homeassistant/sensor/MSA-280425440006/quick/state"
      payload_on: "true"
      payload_off: "false"
      value_template: "{{ value_json.heat }}"

template:
  - sensor:
      - name: "Charged Energy"
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total_increasing
        state: >
          {% set p = states('sensor.msa_battery_power') | float(0) %}
          {% set t1 = as_timestamp(now()) %}
          {% set t0 = states.sensor.msa_akku_ladeenergie.last_updated.timestamp() %}
          {% set dt = t1 - t0 %}
          {% if p < 0 %}
            {{ (-p) * (dt/3600) }}
          {% else %}
            0
          {% endif %}

      - name: "Discharged Energy"
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total_increasing
        state: >
          {% set p = states('sensor.msa_battery_power') | float(0) %}
          {% set t1 = as_timestamp(now()) %}
          {% set t0 = states.sensor.msa_akku_entladeenergie.last_updated.timestamp() %}
          {% set dt = t1 - t0 %}
          {% if p > 0 %}
            {{ p * (dt/3600) }}
          {% else %}
            0
          {% endif %}

The templates are for accumulating the power over time.
The mqtt sensors fetch the data from mqtt. Might be I already deleted some. The “system” sensors are probably meant if you have more than one of these batteries.
You can discover this data using MQTT Explorer.

And then I added an automation that calculates the data to send to the battery.

alias: Battery Control
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.tasmota_emh_power
  - trigger: state
    entity_id:
      - sensor.msa_battery_power
conditions: []
actions:
  - choose: []
    default:
      - data:
          value: >-
            {{ states('sensor.tasmota_emh_power') | float(0) + states('sensor.msa_battery_power') | float(0) -5 }}
        action: number.set_value
        target:
          entity_id: number.msa_280425440006
mode: single

May this be helpful to someone.

JPT

I had to fix the automation to

alias: Akku Steuerung
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.tasmota_emh_power
  - trigger: state
    entity_id:
      - sensor.mq_sen_akku_leistung
conditions: []
actions:
  - choose: []
    default:
      - data:
          value: >-
            {{ [
              states('sensor.calc_sen_netz_leistung') | float(0) +
              states('sensor.mq_sen_akku_leistung') | float(0),
              800
            ] | min }}
        action: number.set_value
        metadata: {}
        target:
          entity_id: number.msa_<serial>
mode: single

You have to limit the power set because the battery discards values greater than the max power completely and goes to 0W. this does not make much sense, but that’s how it is.
If your PV got more than 800 W you probably should limit to -800 W at the other end, too.
If you want your battery to deliver more power, set in the the mobile app, then change here.

There are additional MQTT sensors I missed in my first post.

The AI told me, to create them like this, have the real data in the attributes

mqtt:
  sensor:
    - name: "MQ SEN Akku Device JSON"
      state_topic: "homeassistant/sensor/MSA-<serialno>/device/state"
      value_template: "{{ now().timestamp() | int }}"
      json_attributes_topic: "homeassistant/sensor/MSA-<serialno>/device/state"
      json_attributes_template: "{{ value | from_json }}"

    - name: "MQ SEN Akku System JSON"
      state_topic: "homeassistant/sensor/MSA-<serialno>/system/state"
      value_template: "{{ now().timestamp() | int }}"
      json_attributes_topic: "homeassistant/sensor/MSA-<serialno>/system/state"
      json_attributes_template: "{{ value | from_json }}"

    - name: "MQ SEN Akku Quick JSON"
      state_topic: "homeassistant/sensor/MSA-<serialno>/quick/state"
      value_template: "{{ now().timestamp() | int }}"
      json_attributes_topic: "homeassistant/sensor/MSA-<serialno>/quick/state"
      json_attributes_template: "{{ value | from_json }}"

But this works rarely. No idea why. So create your sensors as descibed in the initial post but be sure to use all three messages from MQTT

Hi JPT123,

I was able to connect via uni-meter. The key factor was to fix the mac address in the uni-meter config file. Then check your values in the web page (usually port 80). Feel free to share uni-meter config file.

I hope it helps

Best,