Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103220

Utility_meter from template adds value on restart

$
0
0

Hi All,

I have a utility_meter which is configured with a template sensor as source.
The template sensor sums up the “total_consumption” attribute of the three sensors from a Shelly 3PM.
(So the template sensor sumps up 3 kWh values).

The issue I have is that whenever I restart home assistant, it seems the value of my template sensor is added again to the utility_meter…

As an example my template sensor has a state of 5.
I restart HA - after this my utility_meter has a value of 5, too.
I restart HA again - my utility_meter has a value of 10.
I restart HA again - my utility_meter has a value of 15…etc.
(Of course the adding depents on the template sensor value after restart - but for simplicity I assumed in the example it is always 5 :slight_smile: )

I already tried to set an offset of 2 minutes for the utility_meter (because I thought maybe the template is 0 after restart and then updates to its actual value which causes the utility_meter to add the value), but it seems the offset does not affect an initialization after restart…

Here is my configuration running on Home Assistant 2022.5.1

utility_meter:

  shelly_zaehler_waermepumpe_daily_consumption_total:
    name: shelly_zaehler_waermepumpe_daily_consumption_total
    source: sensor.shelly_zaehler_waermepumpe_energy_consumption_total
    cycle: daily

template:

  - sensor:
  
      - name: shelly_zaehler_waermepumpe_energy_consumption_total
        unique_id: shelly_zaehler_waermepumpe_energy_consumption_total
        state: >-
	  {% set s = 0 | float %}
	  {% set s = s + state_attr('sensor.shelly_zaehler_waermepumpe_current_consumption','total_consumption') | regex_replace('(^[0-9]+[.]*[0-9]*)( kWh$)','\\1') | float %}
	  {% set s = s + state_attr('sensor.shelly_zaehler_waermepumpe_current_consumption_2','total_consumption') | regex_replace('(^[0-9]+[.]*[0-9]*)( kWh$)','\\1') | float %}
	  {% set s = s + state_attr('sensor.shelly_zaehler_waermepumpe_current_consumption_3','total_consumption') | regex_replace('(^[0-9]+[.]*[0-9]*)( kWh$)','\\1') | float %}   
	  {{ s | float | round(2) }}
        availability: >-
          {{ states('sensor.shelly_zaehler_waermepumpe_current_consumption') not in ['unknown','unavailable'] and states('sensor.shelly_zaehler_waermepumpe_current_consumption_2') not in ['unknown','unavailable'] and states('sensor.shelly_zaehler_waermepumpe_current_consumption_3') not in  ['unknown','unavailable'] }}
        device_class: energy
        unit_of_measurement: kWh
        icon: mdi:meter-electric-outline

Thanks for any help :slight_smile:

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103220

Trending Articles