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
72.79k stars 30.49k forks source link

Sensor with device_class enum has always state 'unknown' in trigger-based mode #129123

Open rvalitov opened 1 day ago

rvalitov commented 1 day ago

The problem

If I create a sensor with device_class: enum it does not work in trigger-based mode. In this case the options attributes of the sensor are ignored and are not visible in the UI.

Standard sensor (correctly handles the options): image

YAML code:

- template:
    - sensor:
        - name: "Garage door status"
          unique_id: garage_door_status
          device_class: enum
          attributes:
            options: "{{ ['This', 'That'] }}"
          state: "This"

Trigger-based sensor seems to ignore the options as a result the state is always 'unknown': image

YAML code:

- template:
    - trigger:
        - platform: state
          entity_id: binary_sensor.garage_door_sensor_contact

        - platform: event
          event_type:
            - template_reloaded
            - homeassistant_started

      sensor:
        name: "Garage door status"
        unique_id: garage_door_status
        device_class: enum
        attributes:
          options: "{{ ['This', 'That'] }}"
        state: "This"

What version of Home Assistant Core has the issue?

2024.10.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

No response

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?

No response

Additional information

No response

home-assistant[bot] commented 1 day ago

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

Code owner commands Code owners of `template` 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 template` 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)


template documentation template source (message by IssueLinks)