arachnetech / homebridge-mqttthing

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

Global configuration for MQTT server/username/password? (ie. MQTT server specified for every accessory?) #493

Open sofakng opened 2 years ago

sofakng commented 2 years ago

Is it possible to only specify the MQTT server/username/password once?

For example, I have many accessories (zwavejs2mqtt) that I'd like to use with mqttthing but it seems redundant to specify the server/username/password repeatedly. I'm also worried that each accessory makes a separate connection to the MQTT server?

arachnetech commented 2 years ago

Not currently, unfortunately. I agree: it's a pain particularly when using the configuration GUI.

Unfortunately, Homebridge accessories must either be of the 'platform' type where one configuration is used for all accessories, or as individually-configured accessories (as mqttthing is). I had hoped that it might be possible to use a 'platform' Config block for shared/default settings and then individually-configured accessories for the accessory-specific settings, but my understanding is that this isn't allowed.

Given time I'd like to move mqttthing to the former (and probably rewrite it in TypeScript), probably as an incompatible 'version 2'. Hopefully one day...

redging-very-well commented 2 years ago

What about using environment variables to allow these to be set? For example, this plugin: https://github.com/joe-ng/homebridge-dyson-link/blob/b7deeb46a6d00e60590e3e830dcd5716f206d6bd/index.js#L47-L48

Alternatively, I believe you can share configuration at the platform level — at least this CBUS plugin does this:

https://github.com/anthonywebb/homebridge-cbus

arachnetech commented 2 years ago

Yes, cbus does it how I'd do it now (!) - it uses a platform-level config with an array of accessories. If I ever get time to do an MQTT-Thing 2.0 I'll go with that design, but it would be incompatible with existing configurations.

Good idea re. environment variables as an alternative. I'll have a look at that.

redging-very-well commented 2 years ago

I could raise PR for the env-var thing if you'd like?

arachnetech commented 2 years ago

Thanks, go for it!

redging-very-well commented 2 years ago

https://github.com/arachnetech/homebridge-mqttthing/pull/505 Let me know if there's anything else you'd like me to do on that PR.