Utility_meter wrong value, but Energy cart is OK?

Hi

I have power meter with configuration:

mqtt:
  sensor:
    - name: "Watomierz 1.8.0 kWh"
      unique_id: watomierz_180_kwh
      object_id: watomierz_180_kwh
      state_topic: "tele/energia/watomierz"
      value_template: "{{ value_json['1.8.0_kWh']|default(0.000) }}"
      unit_of_measurement: kWh
      device_class: energy
      state_class: total_increasing
      icon: mdi:meter-electric

And also utility meters:

utility_meter:
  watomierz_180_kwh_dziennie:
    name: Watomierz 1.8.0 - dziennie
    unique_id: watomierz_180_kwh_dziennie
    source: sensor.watomierz_180_kwh
    cycle: daily
  watomierz_180_kwh_godzinnie:
    name: Watomierz 1.8.0 - godzinnie
    unique_id: watomierz_180_kwh_godzinnie
    source: sensor.watomierz_180_kwh
    cycle: hourly

Yesterday I noticed strange behavior. For some time my sensor was offline (12:30 - 18:30):

And daily calculation for that sensor “stopped” - so it was calculated wrong:

All on one chart:

Total usage at 12:31:34 is 1530.87 kWh and at 18:28:26 is 1538.49. So delta is 7.62 kWh.
And for daily usage at 12:31:34 is 8.46 and at 18:28:26 is 9.52. So delta is 1.06.

But, hourly (and also daily) usage from Energy dashboard is OK. As you can see below at 18 o’clock “missing” usage is present:

Why my manually defined utility_meter is not calculated correctly?

You are lucky that this:

value_template: "{{ value_json['1.8.0_kWh']|default(0.000) }}"

Did not cause you more issues. Defaulting to zero like that can cause a massive jump to the full sensor total when the sensor returns. You should default to unavailable as the change unavailable → total adds nothing.

value_template: "{{ value_json['1.8.0_kWh']|default('none') }}"

I can’t explain your energy dashboard. Which one of the sensors are you using in the energy dashboard?

watomierz_180_kwh

From charts I have values:

  • total usage at 12:31:34 is 1530.87 kWh and at 18:28:26 is 1538.49. So delta is 7.62 kWh.
  • daily usage at 12:31:34 is 8.46 and at 18:28:26 is 9.52. So delta is 1.06.

As You can see 6.56 is missing in daily utility_meter, but energy dashboard is OK.

Second attempt, with new config:

- name: "Watomierz 1.8.0 kWh"
  unique_id: watomierz_180_kwh
  object_id: watomierz_180_kwh
  expire_after: 50
  availability:
    - topic: "tele/energia/watomierz/availability"
  payload_available: "online"
  payload_not_available: "offline"
  state_topic: "tele/energia/watomierz"
  value_template: "{{ value_json['1.8.0_kwh']|default('none') }}"
  unit_of_measurement: kWh
  device_class: energy
  state_class: total_increasing
  icon: mdi:meter-electric

and utility meters:

watomierz_180_kwh_pietnastominutowo:
  name: Watomierz 1.8.0 - pietnastominutowo
  unique_id: watomierz_180_kwh_pietnastominutowo
  source: sensor.watomierz_180_kwh
  cycle: quarter-hourly

watomierz_180_kwh_godzinnie:
  name: Watomierz 1.8.0 - godzinnie
  unique_id: watomierz_180_kwh_godzinnie
  source: sensor.watomierz_180_kwh
  cycle: hourly

watomierz_180_kwh_dziennie:
  name: Watomierz 1.8.0 - dziennie
  unique_id: watomierz_180_kwh_dziennie
  source: sensor.watomierz_180_kwh
  cycle: daily

Again I have mismatch between daily usage and real usage:


In red and green circles you can see those mismatch.
In red there is daily usage, in green is 15mins/hourly usage.

Third example:

    - name: "Watomierz 1.8.0 kWh"
      unique_id: watomierz_180_kwh
      object_id: watomierz_180_kwh
      state_topic: "tele/energia/watomierz"
      value_template: "{{ value_json['1.8.0_kwh']|default('none') }}"
      unit_of_measurement: kWh
      device_class: energy
      state_class: total_increasing
    - name: "Watomierz 1.8.0 kWh avail"
      unique_id: watomierz_180_kwh_avail
      object_id: watomierz_180_kwh_avail
      expire_after: 50
      availability:
        - topic: "tauron/testy/watomierz_avail/availability"
      payload_available: "online"
      payload_not_available: "offline"
      state_topic: "tele/energia/watomierz"
      value_template: "{{ value_json['1.8.0_kwh']|default('none') }}"
      unit_of_measurement: kWh
      device_class: energy
      state_class: total_increasing
    - name: "Watomierz 1.8.0 kWh sometimes off"
      unique_id: watomierz_180_kwh_sometimes_off
      object_id: watomierz_180_kwh_sometimes_off
      state_topic: "tauron/testy/watomierz_sometimes_off"
      value_template: "{{ value_json['1.8.0_kwh']|default('none') }}"
      unit_of_measurement: kWh
      device_class: energy
      state_class: total_increasing

and utility_meters similar to second example.

Grey line is from reference sensor – always sending data and always available.
Blue line is from sensor always available, but sometimes NOT sending data.
Pink is from sensor sometimes NOT available.


Top lines are from total, bottom from hourly. As you can see transition from available->unavailable->available caused that calculation is incorrect.