How to turn mqtt entity into a device?

Hi,

I’m new to HA, so I’m sorry if my questions is dumb, but I still need some help to understand HA philosophy.

I’ve built some custom mqtt controlled lights and switches using 1-wire and now I’d like to expose them into HA. I’ve added this to configuration.yaml:

light:
  - platform: mqtt
    name: "test_lamp"
    unique_id: "a1c386fc-7777-11ea-bc55-0242ac130003"
    state_topic: "test_lamp/light/status"
    command_topic: "test_lamp/light/switch"

Ok, now I have test_lamp entity on the home screen. But as long as it’s just an entity, I can’t add it to any area, since I has to be a device then. So I wonder how to turn an entity into a device, but I feel like my question doesn’t make sense and I’m missing something.

Please suggest! Thanks.

There is an explanation about how devices are build over here: https://developers.home-assistant.io/docs/device_registry_index/

Mqtt.light also has a 'device" parameter you can set.

Although I don’t know how to set it up, those are the places I would start looking.

This is an example of an autodiscovery mqtt message including a device:

topic: homeassistant/binary_sensor/garagedoor/config
message :
‘{“name”: “garagedoor”, “device_class”: “garage_door”, “state_topic”: “sensor/garagedoor”, “unique_id”: “garagedoor”, “off_delay”: 30, “device”: {“identifiers”: [“rfbridge_564886”],“name”: “garagedoor”, “model”: “Digoo door sensor”, “manufacturer”: “Digoo”}}’

2 Likes

Thanks @123, @francisp, this is what I was looking for.

I’d love to find such example on the MQTT discovery specs page.

1 Like

I’m using Mosquitto with a SmartThings MQTT Bridge server, so there is no auto-discovery. I have a ton of MQTT entities that I can use to control and see the state of my ST gadgets, but I can’t get the entities built into devices.

Here’s the entity definition for a motion sensor I have configured in configuration.yaml, for example:

- platform: mqtt
  name: "Entryway Motion"
  unique_id: "smartthings/Dome Motion/Light Sensor"
  state_topic: "smartthings/Dome Motion/Light Sensor/motion"

The unique ID was manually created, obviously, because it’s not passed through and adopting the topic name would keep it unique.

Here is the topic I’m publishing to in an attempt to configure a device from that entity:

homeassistant/binary_sensor/Entryway_Motion/config

The payload is:

{"name": "Entryway_Motion", "device_class": "motion", "state_topic": "smartthings/Dome Motion/Light Sensor/motion"}

The docs are far from clear as to what is going on, but this is my best guess. But with that, I never see a new device created. I can see that the topic is going out correctly, though, if I subscribe to #.

Message 165 received on homeassistant/binary_sensor/Entryway_Motion/config at 1:06 PM:
{
    "name": "Entryway_Motion",
    "device_class": "motion",
    "state_topic": "smartthings/Dome Motion/Light Sensor/motion"
}

Any help? I know this is an old topic, but I figured this was still on top and at least you guys have specific experience. Thanks.

Actually I figured out that I need to pass in a device definition as well. I’ve gotten that working, though I don’t know whether the created device works. I think the fact that the MQTT message for the sensor comes across as active/inactive instead of on/off is the issue, but that’s a separate topic for a separate thread.

Here’s the payload that worked for me:

{
  "name": "Entryway_Motion",
  "device_class": "motion",
  "state_topic": "smartthings/Dome Motion/Light Sensor/motion",
  "device":{"identifiers":"smartthings/Dome Motion/Light Sensor",
    "manufacturer":"Dome",
    "model":"Motion Sensor",
    "name":"Dome Motion/Light Sensor"
  }
}
1 Like