Battery BMS power usage template for Home Energy management

Hi
I have a DalyBMS and I tried (without success) to add power usage of battery for the animation of a home battery as part of the energy distribution for Home Energy management. in homeassistant

‘platform: template
sensors:
power_watts:
friendly_name: “Battery Power Watts”
unit_of_measurement: ‘W’
value_template: >
{% set V = state_attr(‘sensor.battery_voltage’, ‘V’) %}
{% set A = state_attr(‘sensor.battery_current’, ‘A’) %}
{{ A * V }}’

‘sensor:
platform: integration
source: sensor.power_watts
name: battery_energy_spent
unit_prefix: k
round: 2’
A friend told me
"Your template seems wrong. It should be something like this
{{ states('sensor.battery_voltage')|float * states('sensor.battery_current')|float }}"

I tried … no luck
So please help me a little
Thank you

Hi,

im not quite sure if this helps you out but I recently integrated my fronius battery to home assistant.
I had to take the battery power flow split it up in 2 entities

  • positive for charging
  • negative for discharging

And then use riemann sum to convert the real time usage (W) into a total value used by home assistant energy dashboard (kWh)

Here the Code from my configuration.yaml:

#splitting up charging and discharging
template:
  - sensor:
      - name: "Battery Power Charging"
        unit_of_measurement: W
        device_class: energy
        state: "{{ max(0, 0 - states('sensor.power_battery_fronius_power_flow_0_froniusgen24_home') | float(default=0)) }}"
      - name: "Battery Power Discharging"
        unit_of_measurement: W
        device_class: energy
        state: "{{ max(0, states('sensor.power_battery_fronius_power_flow_0_froniusgen24_home') | float(default=0)) }}"

#riemann sum
sensor:
    - platform: integration
      source: sensor.battery_power_charging
      name: "Total Battery Energy Charged"
      unit_prefix: k
      method: left
    - platform: integration
      source: sensor.battery_power_discharging
      name: "Total Battery Energy Discharged"
      unit_prefix: k
      method: left
    - platform: integration
      source: sensor.power_photovoltaics
      name: "Total Photovoltaics Energy"
      unit_prefix: k
      method: left

Thank you!