karloygard / hassio-addons

My Hass.io addons
6 stars 2 forks source link

Plugin does not work with ACL setup of Mosquitto #21

Open geurtsd opened 2 years ago

geurtsd commented 2 years ago

Hi,

After setting up the mosquitto Hassio integration and plugin (as per documentation) to work with ACL and dedicated user (mqttuser), the hassio xcomfortd-go plugin no longer works.

this config is needed to have an intergation of my SMA solar panel working (see https://community.home-assistant.io/t/integration-with-sma-solar-stp-10000tl-20-via-sbfspot/204278) which sends MQTT messages from SBFSpot message send as: (mosquitto_pub -h {host} -t {topic} -m "{{message}}" -u username -P password)

I see that the xcomfortd-go connects with the user "addons" and client "xcomfort" (see screenshot form logfile mosquitto)... screenshot

so I have allready tried following:

  1. set the client ID and prefix BOTH to "xcomfort".. in order to hope ACL via pattern ID to work ("pattern readwrite %c")... --> does not work
  2. set the ACL to allow the user "addons" to be able to readwrite all topics : ("user addons -- topic readwrite #") --> does not work

however the only thing that works is to disable the mosquitto option "customize: active:" by setting it to false, but then it breaks the external integration of sending (and updating) MQTT messages as it no longer reads in the (required) ACL file!!!!

I'm assuming that by enabling the ACL, the user addon does not get authenticated, as it is not defined (nor is the password known, besides by the system!!!) Could the config be extended to override the default pull via Bashio of the username and password to use a defined Username and password to connect and send MQTT publish messages!!!

PS: (willing to test any setup or alternative --> I have a fairly "clean" setup and would only want to extend onze this works... ;-) - ps: have some dev reading skills as well - am an IT guy... ;-))

cheers

Davy

geurtsd commented 2 years ago

UPDATE!!!

I have it working Now.... however seems to be requiring some special / dual config in ACL files.... will be testing some more HOW I managed to get it working because it was trial and error (and then luck.... ;-))

I think its in the direction of having at least 2 entries in the ACL in combination with the client ID and the prefix set to a certain value in the config!!!!! Once I know more I'll post here and maybe its not a bug anymore, but just a documentation update for future reference...

geurtsd commented 2 years ago

UPDATE 2!!!!

Have uncovered one "symptom"... The config stopped working after a reboot of the server (and without any config changes)... After some testing uncovered that a restart of the XcomfortD plugin restored the function again.....

Have restarted the server now several times, and every time need to restart the plugin once to retore function....

seems like a "out of sequence" loading between Mosquitto and Xcomfort plugins..... Maybe related with the ACL config loading of Mosquitto?

karloygard commented 2 years ago

Have uncovered one "symptom"... The config stopped working after a reboot of the server (and without any config changes)... After some testing uncovered that a restart of the XcomfortD plugin restored the function again.....

Have restarted the server now several times, and every time need to restart the plugin once to retore function....

This is a flaw in the regular configuration as well. HA should should send birth and last will MQTT messages, but this appears to only work sporadically. The add-on does listen for these messages and resends the MQTT discovery messages when HA starts up, but most of the time the messages are not sent. I have not had time to investigate why the messages don't appear.

karloygard commented 2 years ago

I have it working Now.... however seems to be requiring some special / dual config in ACL files.... will be testing some more HOW I managed to get it working because it was trial and error (and then luck.... ;-))

I haven't played with ACL, but please post the configuration that you're using, and I can at least let you know if your approach will cause any issues.

geurtsd commented 2 years ago

I have it working Now.... however seems to be requiring some special / dual config in ACL files.... will be testing some more HOW I managed to get it working because it was trial and error (and then luck.... ;-))

I haven't played with ACL, but please post the configuration that you're using, and I can at least let you know if your approach will cause any issues.

Will do some more testing and will post my findings... let me first find some time to take a methodical approach Once I have done this, I will update the topic here for reference (if I have "stumbled" on the solution) or for further (joint) investigation.. ;-)

geurtsd commented 2 years ago

Have uncovered one "symptom"... The config stopped working after a reboot of the server (and without any config changes)... After some testing uncovered that a restart of the XcomfortD plugin restored the function again..... Have restarted the server now several times, and every time need to restart the plugin once to retore function....

This is a flaw in the regular configuration as well. HA should should send birth and last will MQTT messages, but this appears to only work sporadically. The add-on does listen for these messages and resends the MQTT discovery messages when HA starts up, but most of the time the messages are not sent. I have not had time to investigate why the messages don't appear.

OK, I have no idea about the birth and last will messages.... do you have some general info on this I can read up upon (links or so?)... I'm new to MQTT as far as API and application communications, so still have a steep learning curve to overcome.... (but keen on understanding...)

karloygard commented 2 years ago

OK, I have no idea about the birth and last will messages.... do you have some general info on this I can read up upon (links or so?)... I'm new to MQTT as far as API and application communications, so still have a steep learning curve to overcome.... (but keen on understanding...)

There is some info here: https://www.home-assistant.io/docs/mqtt/birth_will/