arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
465 stars 104 forks source link

MQTT Autodiscovery #258

Open mkormendy opened 4 years ago

mkormendy commented 4 years ago

One of the most loved features for Home Assistant is its MQTT Autodiscovery.

https://www.home-assistant.io/docs/mqtt/discovery/

Since this plugin for homebridge attempts to be a catch-all for MQTT device communication/operation. I'd be interested in seeing discussion around a larger project to port over the MQTT Autodiscovery implementation from Home Assistant to this plugin.

Thoughts?

arachnetech commented 4 years ago

That looks like a great feature. It’s a long time since I’ve looked at Home Assistant and I wasn’t aware of it.

I agree, it would be great to support this for Homebridge.

dhutchison commented 3 years ago

Did anyone ever make a start looking at this? I think this would greatly improve the usability of the plugin.

I think I might start taking a look at this later in the week (once I've finished tinkering with bridging BTLE blinds to MQTT).

To start a discussion, the basic steps I think are needed are:

  1. add to the plugin an export for (and create) a platform plugin
  2. query for messages in /homeassistant/* to look for device configs
  3. do something to map this into an accessoryConfig
  4. pass to the existing makeThing to create the accessory (hopefully, not completely sure how interchangeable platform vs independent accessories are)

What big gaping holes in this plan do others see?

NorthernMan54 commented 3 years ago

@dhutchison Already completed, take a look at homebridge-tasmota it automatically handles most common device types. I created it in the summer, after these issues were raised.

mkormendy commented 3 years ago

I was just going to say that @NorthernMan54 has an auto discovery implementation in the wild!!

dhutchison commented 3 years ago

@NorthernMan54 is that specific to devices that came from tasmota or is it much more generic than the name suggests?

NorthernMan54 commented 3 years ago

It is more generic that the name suggests, as the code is using the home assistant mqtt discovery messages. Technically any device that generates home assistant discovery mqtt messages is supported.

The currently supported devices match what I have in my home, but pull requests for more devices are gladly accepted.

dhutchison commented 3 years ago

Ta, I shall take a proper look through it later in the week.

From a skim it looks like a few of the device types I have are not supported in your plugin, I'll take a look through how you have done the discovery config parsing though. Personally I'd rather try to add discovery to Mqttthing, with it's wider service type support, than try to add service types to another plugin, but we'll see how I get on with that :)

arachnetech commented 3 years ago

A complication in doing this in mqttthing is that it's not a platform plugin, and I believe changing it to be (which I have considered) would break compatibility with existing configurations.

Automatic configuration would be great if it can be done though. I have considered writing a new 'version 2' if I can ever find the time.

dhutchison commented 3 years ago

That is a worry that I need to confirm.

I just don't know with the homebridge API if one module can expose two types of plugins, or if the solution is to make a second "auto-discovery" plugin that uses the existing one as a dependency for all the single accessory logic.

I'll start taking a look in a few days and report back initial findings.