Energy template - battery input 2 values

I have been trying to find a solution to combine 2 values in a template sensor and still make the outcome available to my energy dashboard.

Situation is that I have a Growatt installation that recently was expanded with batteries. I purchased the 10kWh offering but now I get 2 sensors for battery_energy_in in my Home Assistant application amd only 1 for battery_energy_out and when I use both in the energy dashboard, it requires me to use the out value twice… resulting in an incorrect (double value) there.

image

See the 12 kWh value vs the actual 6.3 kWh value that was loaded into my batteries.

I am trying to create a template now with this but it will not become visible to add to teh energy dashboard and all I read about adding a state_class: to the sensor is no longer supported.

Is there an alternative way?

  - platform: template
    sensors:
      electricity_batteryinject_total:
        friendly_name: 'Batterij input totaal'
        entity_id:
          - sensor.thuis_batterij_lifetime_total_energy_input_1
          - sensor.thuis_batterij_lifetime_total_energy_input_2
        value_template: "{{ (states('sensor.thuis_batterij_lifetime_total_energy_input_1')|float + states('sensor.thuis_batterij_lifetime_total_energy_input_2')|float)| abs | round(2) }}"
        unit_of_measurement: "kWh"
        device_class: energy

If you use the new way of defining a Template Sensor it allows you to specify state_class.

template:
  - sensor:
      - name: "Electricity Batteryinject Total"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        state: >
          {{ (states('sensor.thuis_batterij_lifetime_total_energy_input_1') | float(0) + 
              states('sensor.thuis_batterij_lifetime_total_energy_input_2') | float(0)) 
              | abs | round(2, default=0) }}

Thank you Taras, fantastic! That did the trick… I am going to update all my template sensors now.

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information, refer to guideline 21 in the FAQ.

1 Like