Trouble Working With Auto-Discovered MQTT Devices

I’m not having much success finding information on this, so hopefully someone can help me out.

I am creating my own simple smart home devices and connecting them through Mosquitto to Home Assistant. So far in my tests my devices are showing up as “entities” (but not as “devices”) in the Home Assistant configuration.

What I am hoping to do is to use the MQTT auto-discovery to have the devices appear in the Home Assistant UI and then be assignable to a room. I’m starting to suspect that it isn’t possible to do that assignment through the HA UI and, instead, the device itself my specify the room it is in through its MQTT config.

I’m rather hoping it’s the former as, to me, it makes sense to be able to simply plug in a device in a room and not have to configure it through its own UI. Being able to see that device auto-discovered in the HA UI and then assigning the room it is in would work well.

Is it possible to do what I’m looking for here? Thanks!

You can’t use MQTT Discovery to assign an area to a device or entity. However, you can use the UI to do it.

You can’t auto-add an area via discovery but you should be able to create devices, not just ungrouped entities. I don’t have much experience doing this manually myself but here’s an example of a discovery payload Zigbee2MQTT sent for one of my lights which created a device:

Topic: homeassistant/light/0x0017880102bd4d3c/light/config
Payload:

availability:
  - topic: zigbee2mqtt/bridge/state
brightness: true
brightness_scale: 254
color_temp: false
command_topic: zigbee2mqtt/Bedroom Bed back light/set
device:
  identifiers:
    - zigbee2mqtt_0x0017880102bd4d3c
  manufacturer: Philips
  model: Hue white A60 bulb E27 (9290011370)
  name: Bedroom Bed back light
  sw_version: Zigbee2MQTT 1.17.0
effect: true
effect_list:
  - blink
  - breathe
  - okay
  - channel_change
  - finish_effect
  - stop_effect
hs: false
json_attributes_topic: zigbee2mqtt/Bedroom Bed back light
name: Bedroom Bed back light
schema: json
state_topic: zigbee2mqtt/Bedroom Bed back light
unique_id: 0x0017880102bd4d3c_light_zigbee2mqtt
xy: false
platform: mqtt

What are you sending for the discovery payload? Are you including device info like in the payload above or just describing the entity?

I provided someone else with an example of how to use a script to create an entity via MQTT Discovery. It also includes an example of defining a device (i.e. the entity becomes part of the device). The script itself is simple, it publishes a retained payload to a topic. The real work is in defining the payload.

Please note that in previous versions, only a device could be assigned to an area but now it can also be done for entities (so it may obviate your need to define devices).

Thanks for the replies @123 and @CentralCommand.

The method you linked to, @123, has solved my problems and answered my questions! I now have a standard firmware I can flash to these devices and have them announce themselves by MAC address for differentiation.

Cheers!