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