Need to reset mqtt broker after each ha restart

Hi,
Im new to Home assistant, hope that this is the right place to ask this question.
im having a setup of rp that run ha supervised using docker.
i installed mosquitto directly on the rp.
i have 6 ACs that connected to the mqtt using broadlink_ac_mqtt.
i connected the mqtt to the ha using the flowing config:

discovery: true
  discovery_prefix: homeassistant
  broker: 192.168.31.253
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  username: *****
  password: ******
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

after adding it everything works perfect including the auto-discover and im able to control my ac using HA.

my issue is that after every ha restart (can be complete restart of the rb or also after restarting only the ha docker) i lost all my devices and they all moved to unavailable.
the only option to make them available again is by restarting the mosquitto service.
Any idea how can I solve this issue?

Thanks in advance and hope that this is the right place for those topics.
Best,
Yoed

2 Likes

Hey
Did you get anywhere with that?
I have a similar problem…

Thanks,
Uri.

1 Like

Good day.
Anyone found a fix for the above.
I installed MQTT Broken in addons and all works fine until i restart HA.
I then have to manually stop and start the ad one before anything works again

It’s because the availability topic has to receive it’s online state for each entity. The device sends an online state when it connects to the mqtt broker. When you restart the homeassistant without restarting the broker it won’t receive the online message because the device doesn’t know it has to update the availability topic, so the HA assumes the entity is unavailable. I have just experienced that. If anyone know how this should work let me know. I use my own device that I programmed myself. Additional questions: is the availability topic supposed to be “retained” type? Or should it be updated frequently between connect/disconnect?

1 Like

Thanks a lot to point to that. So I struggle restarting HA and EMQX while the workaround is to restart z2m.
Thanks.

The whole day trying different solutions, finally and simply i just need to maintain retain true.

mqtt:
  switch:
    - unique_id: dingtian-relay8982752-r1
      name: "1"
      icon: "mdi:lightbulb"
      state_topic: "dingtian/relay8982752/out/r1"
      command_topic: "dingtian/relay8982752/in/r1"
      availability:
        - topic: "dingtian/relay8982752/out/lwt_availability"
          payload_available: "online"
          payload_not_available: "offline"
      payload_on: "ON"
      payload_off: "OFF"
      optimistic: false
      qos: 0
    //retain: false
      retain: true

so that, you won’t be obligated to restart the broker or even the MQTT equipment, the connection and availability will be maintained even after HA reboot.
NB: If you are working on equipment with interface try to activate the “retain” option.

Hi, sorry I know this is an old topic but where did you find this mqtt code? I’ve been looking in file editor but can’t find a similar mqtt object like yours. The only mqtt I’ve found is in my Zigbee2MQTT config file but I don’t know if that needs retain added to it or where to add it if so.