Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group sensor loses its state_class, device_class, and unit_of_measurement for no apparent reason. #120018

Open
jlpouffier opened this issue Jun 20, 2024 · 1 comment

Comments

@jlpouffier
Copy link

The problem

Context

I have a sensor group that sums up all my tracked power sensors at home.
Every child of this group is a numerical sensor with a device_class set to power and a unit set to W.

Here is a small analysis of this group:

CleanShot 2024-06-20 at 12 09 38

Here is the sensor. You can see its state_class: measurement, device_class: power and unit_of_measurement: W

Here are the details of its child, I used a small template to extract everything if it is needed:

{% set childs = ['sensor.prise_frigo_power','sensor.prise_media_center_power','sensor.prise_lave_vaisselle_power','sensor.doorbell_power','sensor.alexa_power','sensor.prise_server_power','sensor.prise_bureau_power','sensor.machine_a_laver_power','sensor.plaques_a_induction_power','sensor.chargeur_tesla_power','sensor.four_power','sensor.puissance_simulee_lumiere','sensor.sonos_chambre_power','sensor.sonos_chambre_marilou_power','sensor.sonos_salle_de_douche_power'] %}
{% for state in states -%}
  {%- if state.entity_id in childs -%}
    {{ state.entity_id }}:
    {{state.attributes}}
  {% endif -%}
{%- endfor %}
sensor.puissance_simulee_lumiere:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'entity_id': ['sensor.suspension_bureau_power', 'sensor.sphere_exterieur_power', 'sensor.plafonnier_table_salon_power', 'sensor.miffy_chambre_marilou_power', 'sensor.lit_chambre_marilou_power', 'sensor.etoile_chambre_marilou_power', 'sensor.comptoir_cuisine_power', 'sensor.chevet_gauche_chambre_power', 'sensor.chevet_droit_chambre_power', 'sensor.buffet_gauche_salon_power', 'sensor.buffet_droit_salon_power', 'sensor.bloom_chambre_power', 'sensor.applique_escalier_couloir_power'], 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:lightbulb-alert', 'friendly_name': 'Puissance Simulée Lumières'}


sensor.chargeur_tesla_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:ev-plug-tesla', 'friendly_name': 'Chargeur Tesla Puissance'}

sensor.plaques_a_induction_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:gas-burner', 'friendly_name': 'Plaques à induction Puissance'}

sensor.four_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:stove', 'friendly_name': 'Four Puissance'}

sensor.sonos_chambre_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'calculation_mode': <CalculationStrategy.LINEAR: 'linear'>, 'integration': 'powercalc', 'source_entity': 'media_player.sonos_chambre', 'source_domain': 'media_player', 'energy_sensor_entity_id': 'sensor.sonos_chambre_energy', 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:speaker', 'friendly_name': 'Sonos Chambre power'}

sensor.sonos_chambre_marilou_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'calculation_mode': <CalculationStrategy.LINEAR: 'linear'>, 'integration': 'powercalc', 'source_entity': 'media_player.sonos_chambre_marilou', 'source_domain': 'media_player', 'energy_sensor_entity_id': 'sensor.sonos_chambre_marilou_energy', 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:speaker', 'friendly_name': 'Sonos Chambre Marilou power'}

sensor.sonos_salle_de_douche_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'calculation_mode': <CalculationStrategy.LINEAR: 'linear'>, 'integration': 'powercalc', 'source_entity': 'media_player.sonos_salle_de_douche_2', 'source_domain': 'media_player', 'energy_sensor_entity_id': 'sensor.sonos_salle_de_douche_energy', 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:speaker', 'friendly_name': 'Sonos Salle de Douche power'}

sensor.prise_bureau_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:desk', 'friendly_name': 'Prise Bureau Puissance'}

sensor.machine_a_laver_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:washing-machine', 'friendly_name': 'Prise Machine à Laver Puissance'}

sensor.prise_frigo_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:fridge', 'friendly_name': 'Prise Frigo Puissance'}

sensor.prise_lave_vaisselle_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:dishwasher', 'friendly_name': 'Prise Lave Vaisselle Puissance'}

sensor.prise_media_center_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:television', 'friendly_name': 'Prise Media Center Puissance'}

sensor.doorbell_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:doorbell', 'friendly_name': 'Prise Sonnette Puissance'}

sensor.prise_server_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'icon': 'mdi:server', 'friendly_name': 'Prise Server Puissance'}

sensor.alexa_power:
{'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'unit_of_measurement': <UnitOfPower.WATT: 'W'>, 'device_class': 'power', 'friendly_name': 'Prise Alexa Puissance'}

TL;DR: Every child also have a state_class: measurement, device_class: power and unit_of_measurement: W

The problem

Two times I noticed that the group sensor lost its state_class, device_class, and unit_of_measurement.

It becomes an "untyped" sensor:
CleanShot 2024-06-20 at 11 59 11

I lose the history graph:
CleanShot 2024-06-20 at 11 58 50

Root cause.

I tried many things to understand where it was coming from. but I did not manage to find out for now.

Here is what I tried:

Is it because a child becomes unavailable temporarily? ... NO:
https://github.com/home-assistant/core/assets/5878296/34e70f80-a051-4907-a9f0-48e7c13de923

Is it because a child becomes unavailable temporarily, and loses its state_class, device_class, and unit_of_measurement? ... NO:
https://github.com/home-assistant/core/assets/5878296/6425f85d-a802-485e-aca4-9de3d9abff3e

What version of Home Assistant Core has the issue?

core-2024.6.3

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

group

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

NOthing particular 😞

Additional information

No response

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (group) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of group 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 group 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)


group documentation
group source
(message by IssueLinks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant