How to modify mosquitto.conf?

The Mosquitto Add-on adds a timestamp to each log entry:

1588009094: mosquitto version 1.6.3 starting
1588009094: Config loaded from /etc/mosquitto.conf.
1588009094: Loading plugin: /usr/share/mosquitto/auth-plug.so
1588009094: |-- *** auth-plug: startup
1588009094:  ├── Username/password checking enabled.
1588009094:  ├── TLS-PSK checking enabled.
1588009094:  └── Extended authentication not enabled.
1588009094: Opening ipv4 listen socket on port 1883.
1588009094: Opening ipv6 listen socket on port 1883.
1588009094: Opening websockets listen socket on port 1884.

I want to change that timestamp into a date and time.

According to the mosquitto’s documentation, all that’s needed is to add this line to the mosquitto.conf file:

log_timestamp_format %Y-%m-%dT%H:%M:%S

However, I’ve had no success implementing it with the Mosquitto Addon.

I found an instance of mosquitto.conf here:

/usr/share/hassio/addons/core/mosquitto/data

but any changes made to that instance are not read by mosquitto on restart (or at least not for me).

I proceeded to follow the instructions provided by the Mosquitto addon. I changed active: from false to true:

customize:
  active: true
  folder: mosquitto

then created the following directory:

/usr/share/hassio/share/mosquitto

and added mosquitto.conf to it, containing just that one line shown above. My thinking was that its contents would be appended to the base mosquitto.conf file.

After restarting the mosquitto addon, there was no change to the log’s timestamp. In fact, the log contained no reference to using my “appended” copy of the config file. It didn’t use it as a substitute for the base config file either.

How does one go about adding options to the base mosquitto.conf file?


NOTE

According to the log, it reads the mosquitto.conf file from /etc

1588009094: Config loaded from /etc/mosquitto.conf.

but Portainer shows that there’s no mapping for /etc so it implies it is reading /etc/mosquitto.conf from within the container itself (meaning any changes to it will not survive a restart). If that’s true then it doesn’t bode well for my desire to modify it.

Screenshot from 2020-04-27 14-52-48

It appears I was on the right track but, for reasons unclear to me, it simply didn’t work on the first shot but did when I tried again. :thinking: :man_shrugging:

I toggled the active option back to false (saved; restarted) then changed it to true again (saved;restarted). Refreshed the log view and confirmed that this time it worked.

On startup, the Mosquitto addon loaded the file I added containing the additional option:

/usr/share/hassio/share/mosquitto/mosquitto.conf

and then loaded its base config file:

/etc/mosquitto.conf

Here’s a screenshot with the relevant portions highlighted. The desired “date and time” format is now enabled.
Screenshot from 2020-04-27 17-14-56

I hope this helps others who may wish to do the same thing or append some other option.

3 Likes

Hi Taras,

thanks for your posting. I have the same problem.

I’m using this home assistant operating system:

ha > info
arch: amd64
channel: stable
docker: 19.03.11
hassos: "4.12"
homeassistant: 0.114.3
hostname: homeassistant

But there is no path /usr/share/hassio
I found /usr/share/supervisor/addons/core/mosquitto/data
But if I change the mosquitto.conf inside this folder it has no effect.

Could you please be so kind to tell me, how I can change the mosquitto.conf which is used for the running docker container addon_core_mosquitto

If I change the config in the container itself and restart mosquitto within the container all works fine but on every restart of the VM all is lost again.

Thanks a lot in advance.

Unfortunately, I can’t provide you with assistance because I don’t have mosquitto running on Home Assistant OS.

The example I provided was for mosquitto running on Home Assistant Supervised. The directory structure is different between OS and Supervised. Whatever instructions I might give you would just be a guess on my part. It’s best if someone else, who is using mosquitto with Home Assistant OS, replies to your question.

You need to create the folder mosquitto within the /share folder and then add a file with extension “.conf” (i.e.: /share/mosquitto/mosquitto.conf). Then add these lines to the file

log_timestamp true
log_timestamp_format %Y-%m-%dT%H:%M:%S

and restart Mosquitto. You should see these lines in the log

1617478797: Loading config file /share/mosquitto/mosquitto.conf
2021-04-03T20:39:57: mosquitto version 1.6.3 starting

and from that point the timestamp will be in the correct format

4 Likes

I’ve run into a similar issue… I’m running Home Assistant OS and need to modify the config for the Mosquitto Broker Addon. I created /share/mosquitto/mosquitto.conf file and restarted the broker service, but once it loaded there was no reference to "loading config file /share/mosquitto/mosquitto.conf. Have things changed since this was originally posted?

I should also note that it seems to take like 40 minutes before the service fully loads - at least before I see the log entries about it listening. Based on behavior it seems to be up a lot quicker (I can use the Ring to MQTT service after a few min), but I can sit and refresh the log for 30-45 min before it shows the block about loading the config and listening on 1883.

From the docs

Option: customize.active

If set to true additional configuration files will be read, see the next option.

Default value: false

Option: customize.folder

The folder to read the additional configuration files (*.conf) from.

I’ve just updated my conf file. I created a moquitto folder manually here:
share/
image
(screenshot from the file editor addon)

The file is loaded without any issue:
1701764584: Loading config file /share/mosquitto/mqtt_bridges.conf