Mosquitto running on pi as default broker

I have Home assistant auto starting on boot. I have mosquito as the default broker on localhost.
Having difficult trying to auto start mosquitto before auto starting home assistant. Is the sequence order of the autostart important. Its logical that the broker must auto start before ha.

What operating system are you using? What version? What have you tried? What isn’t working? What does the HASS log say about MQTT when it starts?

I believe HASS will just try until it can connect. I know it reconnects when it loses connection.

If you’re using a unit file for systemd, I think you can add a key After or Requires, that maps to the broker unit service.

Excerpts from https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files:

After=: The units listed in this directive will be started before starting the current unit. This does not imply a dependency relationship and one must be established through the above directives if this is required.

Requires=: This directive lists any units upon which this unit essentially depends. If the current unit is activated, the units listed here must successfully activate as well, else this unit will fail. These units are started in parallel with the current unit by default.

2 Likes

Platform is raspberry. Installed with all in one script.
I get mqtt to work if I ssh to the pi and execute mosquitto. Then if I restart Ha it works. My problem is getting to auto start mosquitto.
I have the pi to auto restart ha with systemd

Look at how to make a systemd unit file and enable the service here:
https://alexander-rudde.com/2014/02/install-mosquitto-mqtt-broker-on-raspberry-pi-running-arch-linux/

Then add:

After=mosquitto.service

to the unit file for home assistant under [Unit]. If you already have the After key, add the mosquitto service to that key with a space after the current last value, eg:

After=network.target mosquitto.service

Then reload systemd

systemctl daemon-reload

More info here:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html

1 Like