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.97k stars 30.17k forks source link

MQTT sensor with device_class enum does not support options #123224

Closed nuessgens closed 1 month ago

nuessgens commented 1 month ago

The problem

I tried building sensors which are automatically discovered via the MQTT discovery. I have the usecase for enum / limited set of (non-numeric) states (e.g. presence in 'free', 'in-call', 'off' or wind-direction in 'N', 'NW' etc.)

It seems that this is not supported (at least for MQTT sensors; because e.g. the charger_type of the companion app exactly this is done). Unfortunately therefore all the visual editors provide no drop-down with possible values of such entities.

I was assuming that with #89391 device_class enum was introduced for MQTT sensors

What version of Home Assistant Core has the issue?

core-2024.7.4

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

MQTT sensor (autodiscovery)

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sensor.mqtt/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Here is a config-example for my "presence" / busylight use-case

MQTT discovery msg: Topic: homeassistant/sensor/host1/msteams/config Payload:

{
  "unique_id": "host1-busylight-msteams-state",
  "state_topic": "busylight_msteams/host1/state",
  "name": "Microsoft Teams Präsenz",
  "icon": "mdi:microsoft-teams",
  "value_template": "{{ value_json.state }}",
  "device_class": "enum",
  "options": [
    "off",
    "free",
    "in-call",
    "in-call-muted"
  ],
  "availability": [
    {
      "topic": "busylight_msteams/host1/state",
      "value_template": "{{ value_json.status }}"
    }
  ],
  "object_id": "host1-busylight-msteams-state",
  "device": {
    "identifiers": "host1-busylight-msteams",
    "name": "Microsoft Teams Präsenz (host1)",
    "manufacturer": "nuessgens",
    "sw_version": "1.6"
  }
}

MQTT state msg: Topic: busylight_msteams/host1/state Payload:

{
  "state": "free",
  "status": "online"
}

But in the Developer Tools > States Entity it just shows Entity: sensor.host1_busylight_msteams_state State: free State attributes:

device_class: enum
icon: mdi:microsoft-teams
friendly_name: Microsoft Teams Präsenz (host1) Microsoft Teams Präsenz
home-assistant[bot] commented 1 month ago

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

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


mqtt documentation mqtt source (message by IssueLinks)

jbouwh commented 1 month ago

https://github.com/home-assistant/core/pull/123248 will add support for this. That it is not supported yet is not an issue though, it is a feature request. So I am going to close this as it is not an issue.

nuessgens commented 1 month ago

Tanks for the quick reply.

You are totally right: this was rather a feature request.

Regarding the pull-request: amazing! that was lightning fast 😎 Looking forward to the next release ;-)