Create device manually via YAML

Hey there,

I’ve developed my own PCB that serves as a LoRa-To-MQTT gateway, which also provides some metrics and control options via MQTT and I wanted to simply add it to HA to control it. Of course, I have all the entities (switches, numeric states, etc.) in HA and can use them, put them on a dashboard etc etc. But I wanted to “group” them together under a device, but that doesn’t seem to be possible in HA, neither via the UI, nor via YAML. Or I’m just blind :slight_smile: It really seems only integrations can add devices, or put differently: A device ALWAYS has an integration.

Is there really no way to type a device in YAML and tell which entities belong to it? Like this (totally making this up):

device:
  name: "LoRa Gateway"
  entities:
  - number.lora_gateway_uptime
  - number.lora_gateway_packages
  - switch.lora_gateway_toggle_eth

Thanks and greetings,

Andy!

1 Like

It’s not possible. The only way you can do this with yaml is by setting up everything in MQTT, but the entities need to be in MQTT as well. You can’t add entities from other integrations.

I’m assuming you’re feeling stuck when automating? If that’s the case, keep in mind that everything can be done without a device. You just need to use the other trigger, condition, and action options.

1 Like

You can do it with mqtt discovery, which is basically UI… Via mqtt config messages.

Should be some examples on the forums to follow for making the config messages.

here’s one

probably easier to read one

1 Like

Hrrrmmmm, these are all MQTT entities. That’s a good lead actually! I can add them via the MQTT integration. I was used to type my entities by hand into the YAML and add them that way. But I can certainly use the MQTT integration and get them as a device that way! I may even do a proper MQTT discovery support; the software on that ESP is my own anyways, so I add that! Thanks for the lead!

Nah it was not related to automations. Just not having one place in HA that has all the entities for that one device! They are just entities right now and I need to search for them to see them all. Instead of going to devices, click the device, get the nice device view with the related entities, etc.

Thanks!

STILL: I think this could be a nice and easy addition to HA to configure devices manually via YAML and simply list the entities that belong to it. Maybe somebody finds that useful and has time to build it :wink:

2 Likes

Nice, then it seems easy for you. Just take a look at the examples hasqt posted for MQTT discovery. It’s essentially the same as a configuration, except it’s an automation that runs at startup.

I like the idea to be able to define a device and configure entities belonging to that device.

Actually I have entities defined for a modbus integration and would like to define a Device they are belonging to. Any idea how to accomplish that with the current HA implementation are highly appreciated.

MQTT discovery and MQTT yaml are the only yaml integrations that can create devices. There is no way to extend this functionality to modbus

has anything changed here? Got a wifi device that provides functions and sensors via a rest api and I would look to bundle them in HA together to a device …

1 Like

I did see a reference to a HACS integration allowing that and even more. It is in early development stage. However so far, I was not able to set it up via HCAS (not found when exploring HACS integrations).
Device tools for Home Assistant

1 Like