Hi,
I’ve just installed a battery back up system with a few solar panels in my home which I’m trying to integrate into home assistant. I’m having trouble getting the energy tab to accept my sensors for energy into and out of the battery.
My set up:
I have a Shelly EM monitoring the mains into my home - working great
I have a Bluetti AC500 hybrid inverter system, and I’m using a 3rd party integration to extract data from the inverter and present it to HA as MQTT topics. I’ve got (all measured as power in watts): Solar power in, AC power in, AC power out.
It is my understanding that the Energy monitor in HA is based around an AC coupled system which is grid attached, so I have tried to isolate just the charge/discharge of the battery its self - basically excluding power passed straight through the AC500, either from solar or grid.
I have created the following templated sensors in Yaml:
template:
- sensor:
- name: "AC500 Battery Power In"
unique_id: ac500_battery_power_in
unit_of_measurement: "W"
state: >-
{% if (states('sensor.ac500_ac_input_power')|float(0)) + (states('sensor.ac500_dc_input_power')|float(0)) > (states('sensor.ac500_ac_output_power')|float(0)) %}
{{ (states('sensor.ac500_ac_input_power')|float(0)) + (states('sensor.ac500_dc_input_power')|float(0)) - (states('sensor.ac500_ac_output_power')|float(0)) }}
{% else %}
{{ '0'|float(0)}}
{% endif %}
- sensor:
- name: "AC500 Battery Power Out"
unique_id: ac500_battery_power_out
unit_of_measurement: "W"
state: >-
{% if (states('sensor.ac500_ac_input_power')|float(0)) + (states('sensor.ac500_dc_input_power')|float(0)) < (states('sensor.ac500_ac_output_power')|float(0)) %}
{{ (states('sensor.ac500_ac_output_power')|float(0)) - ((states('sensor.ac500_ac_input_power')|float(0)) + (states('sensor.ac500_dc_input_power')|float(0))) }}
{% else %}
{{ '0'|float(0)}}
{% endif %}
This gives me the power into and out of the battery in watts. I’ve used the Riemann sum integral helper to turn these into cumulative power, and then templated the output again to give it the proper attributes (according to the documentation: https://www.home-assistant.io/docs/energy/faq/#troubleshooting-missing-entities.
More yaml to do that (under the same template block above):
- sensor:
- name: "AC500 Energy In (Template)"
unique_id: ac500_energy_in_template
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
state: "{{ states('sensor.ac500_energy_in')|float(0) }}"
- sensor:
- name: "AC500 Energy Out (Template)"
unique_id: ac500_energy_out_template
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
state: "{{ states('sensor.ac500_energy_out')|float(0) }}"
This appears to have worked:
The entities appear on my dashboard and give me sensible numbers. As you can see, they have all the attributes which mean they should be accepted by the energy tab. But they do not show up on the list of sensors when I try to add them.
The power sensor and the output from the Riemann sum integral helpers are both available to add as “energy going into the battery” and “energy going out of the battery” in the energy config, but when I do I get a warning:
Unexpected device class
The following entities do not have the expected device class:
* sensor.ac500_energy_in
* sensor.ac500_energy_out
And the values always show up as 0KWh in the graphs and totals.
Additionally, the templated sensors have no history recorded by HA. The output from the integrators (the input to the templates above) are recording histories just fine, but appear to have the wrong device class.
I’m stumped as to why these sensors I’ve templated won’t show up in the list of available sensors. Does anyone know what I’m doing wrong?
Thanks!