home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.14k stars 29.82k forks source link

Utility meter warns 'received an invalid new state' upon reload MQTT #113392

Closed Mariusthvdb closed 2 months ago

Mariusthvdb commented 6 months ago

The problem

Source sensors are direct Mqtt topic sensors, example below.

since the user can not guard this with some availability template in Utility meter (or the source for that matter as it is a direct Mqtt topic, and has no availability topic), the warning is not very helpful, off setting even as it makes the user want to fix this.

(maybe move to debug?)

What version of Home Assistant Core has the issue?

2024.4.0.dev20240314

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Utility meter

Link to integration documentation on our website

https://www.home-assistant.io/integrations/utility_meter

Diagnostics information

No response

Example YAML snippet

- unique_id: watermeter_smart_gateways_current_value
      state_topic: watermeter/reading/current_value
      name: Watermeter stand
      unit_of_measurement: L
      state_class: total_increasing
      device_class: water

Anything in the logs that might be useful for us?

2024-03-14 09:11:58.492 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Gas per uur received an invalid new state from sensor.gas_totaal : unknown
2024-03-14 09:11:58.493 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Gas per dag received an invalid new state from sensor.gas_totaal : unknown
2024-03-14 09:11:58.493 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Gas per maand received an invalid new state from sensor.gas_totaal : unknown
2024-03-14 09:11:58.493 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Gas per jaar received an invalid new state from sensor.gas_totaal : unknown
2024-03-14 09:11:58.493 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Gas per kwartaal received an invalid new state from sensor.gas_totaal : unknown
2024-03-14 09:11:58.493 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Gas per week received an invalid new state from sensor.gas_totaal : unknown
2024-03-14 09:11:58.494 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Inductieplaat totaal daily received an invalid new state from sensor.inductieplaat_totaal : unknown
2024-03-14 09:11:58.494 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Inductieplaat totaal yearly received an invalid new state from sensor.inductieplaat_totaal : unknown
2024-03-14 09:11:58.495 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Patchboard Zolder totaal daily received an invalid new state from sensor.patchboard_zolder_totaal : unknown
2024-03-14 09:11:58.495 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Patchboard Zolder totaal yearly received an invalid new state from sensor.patchboard_zolder_totaal : unknown
2024-03-14 09:11:58.496 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Water per dag received an invalid new state from sensor.watermeter_stand : unknown
2024-03-14 09:11:58.496 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Water per jaar received an invalid new state from sensor.watermeter_stand : unknown
2024-03-14 09:11:58.496 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Water per kwartaal received an invalid new state from sensor.watermeter_stand : unknown
2024-03-14 09:11:58.496 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Water per kwartier received an invalid new state from sensor.watermeter_stand : unknown
2024-03-14 09:11:58.496 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Water per maand received an invalid new state from sensor.watermeter_stand : unknown
2024-03-14 09:11:58.496 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Water per uur received an invalid new state from sensor.watermeter_stand : unknown
2024-03-14 09:11:58.497 WARNING (MainThread) [homeassistant.components.utility_meter.sensor] Water per week received an invalid new state from sensor.watermeter_stand : unknown

Additional information

Scherm­afbeelding 2024-03-14 om 09 17 09

fwiw, all of these have the always available on the configuration :

Scherm­afbeelding 2024-03-14 om 10 41 41
home-assistant[bot] commented 6 months ago

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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


utility_meter documentation utility_meter source (message by IssueLinks)

nagtegaal commented 3 months ago

I have the feeling that these errors are generated because the template sensor is receiving state "unknown" while it is expecting is_number(). Is this where the template_available option is designed for and should be used inside our custom template sensors?

tomlut commented 2 months ago

This has nothing to do with template sensors. This is being reported by the Utility Meter integration. Template sensors would cause the Utility Meter to report this if you use the availability: template option but that is beside the point.

e.g. I have a bunch of zigbee smart plugs (no templates) that report the same thing after I restart the mqtt addon or host machine (e.g. for an OS update):

Logger: homeassistant.components.utility_meter.sensor Source: components/utility_meter/sensor.py:502 integration: Utility Meter (documentation, issues) First occurred: 07:48:22 (12 occurrences) Last logged: 07:48:22

Electronics Bench Energy Daily received an invalid new state from sensor.electronics_bench_energy : unknown Cinema Subwoofer Energy Daily received an invalid new state from sensor.cinema_subwoofer_energy : unknown Workshop Fridge Energy Daily received an invalid new state from sensor.workshop_fridge_energy : unknown Electric Blanket Energy Daily received an invalid new state from sensor.electric_blanket_energy : unknown Washing Machine Energy Daily received an invalid new state from sensor.washing_machine_energy : unknown

The main gripe I have is that unknown is not "an invalid new state" It is a required state to to prevent the utility meter doing incorrect things.

If the utility meter sees some_value0some_value it will add the 0some_value step. This will not occur if the device reports some_valueunknownsome_value.

In short unknown should not be reported as an "an invalid new state".

dgomes commented 2 months ago

it is invalid...

what should happen is for the source sensor to go unavailable and back to available.

tomlut commented 2 months ago

So is the buck being passed to home assistant core or Zigbee2mqtt for setting the states to unknown instead of unavailable when the the host machine is shut down for an OS upgrade?

dgomes commented 2 months ago

when zigbee2mqtt disconnects, all its entities should change state to unavailable - which is literally what's going on

Mariusthvdb commented 2 months ago

in my case, I dont use zigbee2mqtt, my issue is about core Mosquito Mqtt entities.

however, I just reloaded Mqtt and checked, and the reported logging is no longer there using default: logger set to warning or error.

was this fixed after all? (currently HA 2024.6.3)

dgomes commented 2 months ago

The warning is still there in the code... so you fixed things in another way...

Mariusthvdb commented 2 months ago

The warning is still there in the code... so you fixed things in another way...

haha, I did no such thing. both my mqtt and utility_meter configs are untouched. there was nothing I could do. not complaining though cheers

tomlut commented 2 months ago

Yeah it's not fixed and should not have been closed.