Issue with Utility Meter after rebooting

Hi All,

I am experiencing some issues with my utility meters.
I created a template sensor that counts all my measured plugs, so I can see the daily usage of all my devices.
This sensor is used with my daily, weekly, monthly and yearly utility meters.

However, when I restart my HA (happens often ), after the restart the utility meter is now longer displaying the corrent value (it is always higher then the actual power usage).
I tested this by restarting HA today, and can see the following:
utility

This screenshot was taken right after the reload, and as you can see, the difference between “Power Consumption Total” and Daily Energy Usage" is rather large.

Does any of you have an idea what might be causing this ?

Thanks in advance !

1 Like

Exactly the same issue with my sonoff pow sensors, flashed with tasmota. I believe that the problem was described a few times, but with no actual resolution till now.

I`m planning to open an issue in Utility meter GitHub. Two weeks ago I’ve write in a thread Daily energy monitoring about the same problem, but the solution doesn’t help me. Still waiting for help.

Sounds good. Please keep me posted.
Regards

Its happening the same to me, is there any solution for this? after rebooting HA, utility meter doesnt retain last value, it seems its getting last data directly from sensor.

1 Like

+1, same for me.

1 Like

Gents, after some research i changed my sensor value_template to string ( before was float), but my total power consumption still getting high values after reboot.

my workaround was getting current power (watts) and send this to integration template, this template calculates energy consumption (kWh or Wh) creating other sensor.
Then i send this value after integration sensor to utility_meter. as the sensor is always getting current value and not stored kWh from cloud or whatever, it doesnt get anything you dont want.
thats my config.

this sums 2 clamp meters and gives me total current power:

sensor:
  - platform: template
    sensors:
      total_current_power_consumption:
        unit_of_measurement: W
        value_template: "{{ ((states('sensor.shelly_shem_c7f978_1_current_consumption') | float) + (states('sensor.shelly_shem_c7f978_2_current_consumption') | float)) | round(1) | string() }}"
        entity_id:
          - sensor.shelly_shem_c7f978_1_current_consumption
          - sensor.shelly_shem_c7f978_2_current_consumption

then i use integration to give me energy consumption as a sensor:

  - platform: integration
    source: sensor.total_current_power_consumption
    name: energy_consumed
    unit_prefix: k
    round: 1

then i use integration sensor on utility_meter creating 2 sensors, monthly and daily energy consumed:

utility_meter:
  daily_energy_consumption:
    source: sensor.energy_consumed
    cycle: daily
    net_consumption: true
  monthly_energy_consumption:
    source: sensor.energy_consumed
    cycle: monthly
    offset:
      days: 15
    net_consumption: true

if you have solar, your consumption will be negative while generating energy, the net_consumption allows utility meter to account negative values.

I open an issue today. You can find it here: https://github.com/home-assistant/core/issues/38710

I have similar (?) issues. Although I was able to limit them to only happening when I restart Hass when there is no sun (i.e. solar panel sensors are unavailable)

I switched to a different custom component for my Omnik converter which was already an improvement https://github.com/robbinjanssen/home-assistant-omnik-inverter. The previous one didn’t have no memory whatsoever, so after any reset the solar sensors started unavailable and screwed up the utility meter. https://github.com/heinoldenhuis/home_assistant_omnik_solar

I also have the suspect that at boot some sensor maybe unavailable until after utility meter has started… But if it is the case it would be needed a delay at boot that prevent utility meter to refer to unavailable sensors readings.

Did this help solve your problem? I’m solving about the same problem, my code is:

sensor:
  - platform: template
    sensors:
      energy_consumption_total:
        friendly_name: Energy Consumption Total
        icon_template: mdi:flash
        unit_of_measurement: kWh
        value_template: "{{ states('sensor.shelly_shem_3_40f52001972c_1_total_consumption')|float + states('sensor.shelly_shem_3_40f52001972c_2_total_consumption')|float + states('sensor.shelly_shem_3_40f52001972c_3_total_consumption')|float}}"
      # výpočet spotřeby v čase a Kč
      energy_cost_total_daily:
        friendly_name: Energy Cost Total Daily
        icon_template: mdi:cash
        unit_of_measurement: Kč
        value_template: "{{ (states('sensor.energy_consumption_total_daily')| float * 6) | round(2) }}"
      energy_cost_total_monthly:
        friendly_name: Energy Cost Total Monthly
        icon_template: mdi:cash
        unit_of_measurement: Kč
        value_template: "{{ (states('sensor.energy_consumption_total_monthly')| float * 6) | round(2) }}"
      energy_cost_total_yearly:
        friendly_name: Energy Cost Total Yearly
        icon_template: mdi:cash
        unit_of_measurement: Kč
        value_template: "{{ (states('sensor.energy_consumption_total_yearly')| float * 6) | round(2) }}"

utility_meter:
  energy_consumption_total_daily:
    source: sensor.energy_consumption_total
    cycle: daily
  energy_consumption_total_monthly:
    source: sensor.energy_consumption_total
    cycle: monthly
  energy_consumption_total_yearly:
    source: sensor.energy_consumption_total
    cycle: yearly

Hi,

I am using Shelly 3EM through MQTT, and finally I have used following code to clear out the problem of getting unavalaible / unknown state of total power meter converted to 0 on restart:

sensor:
  - platform: template
    sensors:
      energy_consumption:
        friendly_name: "Total energy consumption"
        unit_of_measurement: kWh
        value_template: "{{ (states('sensor.shelly_3em_shelly_3em_hlavni_meter_total_0')|float + states('sensor.shelly_3em_shelly_3em_hlavni_meter_total_1')|float + states('sensor.shelly_3em_shelly_3em_hlavni_meter_total_2')|float)|round(3) }}"
        availability_template: >
          {% if is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_0", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_1", "unknown") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_1", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_1", "unknown") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_2", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_3em_shelly_3em_hlavni_meter_total_2", "unknown") %}
            false
          {% else %}
            true
          {%- endif %}

The availability_template is not very clever, hopefully I could merge the unvailable and unknown for each sensor into one line, but it works for now. It prevents getting the state of 0 after converting those states after reset.

2 Likes

I had similar problems with restarting HA and found better, dynamic templates

https://community.home-assistant.io/t/daily-energy-monitoring/143436/127?u=systemz