esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
417 stars 26 forks source link

Generate custom object_id for MQTT auto discovery #1569

Closed misery closed 2 years ago

misery commented 2 years ago

Describe the problem you have/What new integration you would like I have several ESP32 here with a similar configuration and sensors. This works good and Home-Assistant can find anything with MQTT Auto-Discovery. Also I'm using the WebUI of esphome.

Since I have similar sensors the name must be changed to avoid something like "sensors.temperature_22" in home-assistant. I think we all know this hack:

esphome
  name: myhome

substitutions:
  roomname: wohnzimmer

sensor:
  - platform: dht
    model: am2302
    pin: GPIO01
    temperature:
      name: "Temperature ${roomname}"
    humidity:
      name: "Humidity ${roomname}"
    update_interval: 60s

This looks ugly for me in WebUI and Device-UI of HA. Also it is a pain to write it. ;-)

I like to request that esphome can use new object_id to automatically generate a better name by default. Something like object_id: ${esphome_name}_${name_of_sensor}" -> object_id: myhome_temperature". So we don't need to care about "unique names" of that device.

As this is not backward compatible it should be an option like this: https://github.com/esphome/esphome-docs/pull/1610 discovery_object_id_generator with no or auto. Maybe it would be useful to provide allow manually adding object_id to a component.

Please describe your use case for this integration and alternatives you've tried: Current alternative

      name: "Custom Name with suffix ${name}"

Additional context

Newest HA allows object_id in auto discovery. https://www.home-assistant.io/docs/mqtt/discovery/

{
  "name":"My Super Device",
  "object_id":"device1",
  "state_topic": "homeassistant/sensor/device1/state",
 }

In the example above, the the entity_id will be sensor.device1 instead of sensor.my_super_device.

misery commented 2 years ago

@akomelj Thank you very much!