core icon indicating copy to clipboard operation
core copied to clipboard

utility_meter integration warns for invalid state change `unavailable`

Open drthanwho opened this issue 1 year ago • 11 comments

The problem

I have utility meter sensors that as their source use template sensors. Said template sensors have availability templates to guard if their corresponding source sensors in their templates go unavailable (esphome device going offline).

On start up esphome devices are unvailable briefly which triggers the availability template and therefore triggers the warning on the utility meter integration. The behaviour of the template sensor is correct though (also doesn't give any warning there anyway) but the utility meter doesn't ike that.

What version of Home Assistant Core has the issue?

core-2023.5.0b2

What was the last working version of Home Assistant Core?

core-2023.4.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

utility_metwe

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-04-29 16:24:48.346 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Φάση 1 Κατανάλωση nixterino received an invalid state change coming from sensor.pzem_l1_energy (unavailable > 1167087)
2023-04-29 16:24:48.411 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Φάση 2 Κατανάλωση nixterino received an invalid state change coming from sensor.pzem_l2_energy (unavailable > 4531248)
2023-04-29 16:24:48.500 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] utility_test peak received an invalid state change coming from sensor.pzem_l3_power (unavailable > 233.40)
2023-04-29 16:24:48.503 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Total House Power Meter kanoniko received an invalid state change coming from sensor.total_power_consumption (unavailable > 374.5)
2023-04-29 16:24:48.506 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Total House Power Meter kanoniko received an invalid state change coming from sensor.total_power_consumption (unavailable > 374.5)
2023-04-29 16:24:48.521 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Φάση 3 Κατανάλωση nixterino received an invalid state change coming from sensor.pzem_l3_energy (unavailable > 5480295)
2023-04-29 16:24:48.528 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Συνολογική Κατανάλωση nixterino received an invalid state change coming from sensor.total_energy_consumption (unavailable > 11178.63)

Additional information

No response

drthanwho avatar Apr 29 '23 14:04 drthanwho

Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration (utility_meter) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of utility_meter can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign utility_meter Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


utility_meter documentation utility_meter source (message by IssueLinks)

home-assistant[bot] avatar Apr 29 '23 15:04 home-assistant[bot]

It's a warning so that users know that the utility_meter will miss a value (will be less accurate) it does not imply a malfunction.

When the utility_meter receives a state change from "unavailable" to any valid state it does not know what happened during the unavailability period, and therefore a warning is raised to avoid recurrent issues with users complaining that utility_meter does not match the sum of the source sensor (which is usually able to track values while unavailable/offline).

dgomes avatar Apr 29 '23 15:04 dgomes

We should not raise warnings that can't be fixed by an user.

frenck avatar Apr 29 '23 15:04 frenck

The user will become aware that the source sensor is not reliable and will be able to address the root cause of the utility_meter not keeping accurate values.

dgomes avatar Apr 29 '23 15:04 dgomes

And https://github.com/home-assistant/core/pull/91035 actually addressed the issue of start-up

dgomes avatar Apr 29 '23 15:04 dgomes

Hi, don't know when this started but since ... I get these errors in my logs. Is that something I need to address in my utility meter config?

Logger: homeassistant.components.utility_meter.sensor
Source: components/utility_meter/sensor.py:456
Integration: Utility Meter (documentation, issues)
First occurred: 08:13:28 (6 occurrences)
Last logged: 08:13:28

Daily Growatt Solar received an invalid state change coming from sensor.growattmodbus_total_gen (unavailable > 14554.7)
Weekly Growatt Solar received an invalid state change coming from sensor.growattmodbus_total_gen (unavailable > 14554.7)
Monthly Growatt Solar received an invalid state change coming from sensor.growattmodbus_total_gen (unavailable > 14554.7)
Quarterly Growatt Solar received an invalid state change coming from sensor.growattmodbus_total_gen (unavailable > 14554.7)
Yearly Growatt Solar received an invalid state change coming from sensor.growattmodbus_total_gen (unavailable > 14554.7)

My config:

#### Solar Power Counters ####
hourly_growatt_modbus:
  name: Hourly Growatt Solar
  source: sensor.growattmodbus_total_gen
  #source: sensor.growattmodbus_output_power
  cycle: hourly
  net_consumption: true
daily_growatt_modbus:
  name: Daily Growatt Solar
  source: sensor.growattmodbus_total_gen
  #source: sensor.growattmodbus_output_power
  cycle: daily
  net_consumption: true
weekly_growatt_modbus:
  name: Weekly Growatt Solar
  source: sensor.growattmodbus_total_gen
  #source: sensor.growattmodbus_output_power
  cycle: weekly
  net_consumption: true
monthly_growatt_modbus:
  name: Monthly Growatt Solar
  source: sensor.growattmodbus_total_gen
  #source: sensor.growattmodbus_output_power
  cycle: monthly
  net_consumption: true
quarterly_growatt_modbus:
  name: Quarterly Growatt Solar
  source: sensor.growattmodbus_total_gen
  #source: sensor.growattmodbus_output_power
  cycle: quarterly
  net_consumption: true
yearly_growatt_modbus:
  name: Yearly Growatt Solar
  source: sensor.growattmodbus_total_gen
  #source: sensor.growattmodbus_output_power
  cycle: yearly
  net_consumption: true
#### Solar Power Counters ####

sanderlv avatar Apr 30 '23 06:04 sanderlv

@drthanwho have you considered setting "periodically-resetting" option: https://www.home-assistant.io/integrations/utility_meter/#periodically-resetting ?

dgomes avatar Apr 30 '23 10:04 dgomes

@drthanwho have you considered setting "periodically-resetting" option: https://www.home-assistant.io/integrations/utility_meter/#periodically-resetting ?

I don't see how that would help. The template goes unavailable only on start up because the esphome entity is unavailable on start up. How would that be fixable by the end user?

I never saw any difference after that PR was merged by the way

drthanwho avatar May 01 '23 08:05 drthanwho

It made no difference because we didn't want to change the existing behaviour

try to set: periodically-resetting: false if esphome doesn't reset periodically it will probably fix your case

dgomes avatar May 01 '23 19:05 dgomes

wasnt this supposed to already be fixed upon reloading templates? Still seeing these warnings at those moments.

system should really 'know' that, and that is has nothing to do with source sensors being unreliable, or the utility_meter entity beng less accurate for that matter?

Mariusthvdb avatar May 01 '23 20:05 Mariusthvdb

@Mariusthvdb if you reload a template, during the time it takes for it to reload, it might loose readings.

We can make the warning go away, by simply removing the warning from the code, but the utility_meter simply can't know what has happened while a source sensor has been unavailable.

What we can do is optimistic guesses, that is why periodically-resetting: false was introduced. If you add this option to your utility_meter and consider that your template never resets then you not only get ride of the warning, you will also get more accuracy in the utility_meter readings.

dgomes avatar May 01 '23 22:05 dgomes

Shouldnt it be : periodically_resetting and not periodically-resetting ?

Helllie avatar May 05 '23 08:05 Helllie

I was having the same issue and fixed the problem by adding the following if statements to my grid sensors.

No more log warnings or sensors sitting on "unavailable" state if my meter disconnects temporarily.

#Configure grid export power sensor
- sensor:
  - name: Grid Import Power
    state_class: measurement
    icon: mdi:transmission-tower
    unit_of_measurement: W
    device_class: power
    state: >
      {% if is_number(states('sensor.envoy_XXXXXXXXXXXX_current_power_consumption')) and is_number(states('sensor.envoy_XXXXXXXXXXXX_current_power_production')) %}
        {{ [0, states('sensor.envoy_XXXXXXXXXXXX_current_power_consumption') | int - states('sensor.envoy_XXXXXXXXXXXX_current_power_production') | int ] | max }}
      {% else %}
        None
      {% endif %}

#Configure grid export power sensor
- sensor:
  - name: Grid Export Power
    state_class: measurement
    icon: mdi:transmission-tower
    unit_of_measurement: W
    device_class: power
    state: >
      {% if is_number(states('sensor.envoy_XXXXXXXXXXXX_current_power_production')) and is_number(states('sensor.envoy_XXXXXXXXXXXX_current_power_consumption')) %}
        {{ [0, states('sensor.envoy_XXXXXXXXXXXX_current_power_production') | int - states('sensor.envoy_XXXXXXXXXXXX_current_power_consumption') | int ] | max }}
      {% else %}
        None
      {% endif %}

andre-sam avatar Jun 12 '23 12:06 andre-sam

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.