Why is "device" variable only available through discovery for MQTT sensors?

Both “MQTT Binary Sensor” and “MQTT Sensor” platform admit a “device” variable, but only when created through MQTT discovery, not when defined directly on YAML. So, if I want to define a device with several sensors, I have to create a script that sends the discovery info through MQTT…

Is there any reason for this behavior? Perhaps I am missing something here? Thanks!

Did you try to configure one in YAML?
I don’t understand that note, tbh, because if you use discovery, you don’t use YAML :thinking:

Because only ‘devices’ configured through the GUI or auto-discovered can create devices. None of the .YAML configured integrations can create devices. Devices are relatively new to HA, they only exist a year or 2 or so. Before we only had entities.

1 Like

I have several devices that send their status via MQTT, but do not follow HA’s discovery protocol. So, as far as I know, I have two options here:

  • Configure them through YAML, using the MQTT Sensor platform; however, as stated in that page, the “device” configuration variable “Only works through MQTT discovery and when unique_id is set”.
  • Create a script, that uses the “mqtt.publish” service to send discovery messages to HA; this allows to use the “device” configuration variable, but is not a clean solution.