HA not sending MQTT 'will message' (offline)

As per the instructions, I have the following code in HA configuration.yaml:

mqtt:
  broker: localhost
  username: mqttuser
  password: !secret mqtt_password
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

However, I am only receiving messages with payload ‘online’ when restarting/stopping HA (either from frontend or via a systemctl/service command). Receiving the ‘offline’ message has worked before though.

Could this be a bug in HA?

Read the big blue box at the top of the page.

Thanks fixed. I tried that button already, don’t know why it didn’t work the first time.

No sure… can be completely wrong about this… but it seems you are using the embedded broker, itsn’t that one stopped as well if you stop or restart HA?

This is not the embedded broker. Please read the MQTT page.

Seriously? Like I mentioned just trying to help…

I am sure you were trying to help, but making statements that are obviously incorrect if you had a basic understanding of the MQTT configuration only serves to confuse people.

Especially, as in this case, where there appears to be a bug in HA, and it is not doing what the documentation says it is supposed to do.

I was expecting some delay because of TCP timeouts before the will message was sent, but I have currently disconnected a test HA instance from the broker for a few minutes, but nothing so far…

It seem you have a bit trouble reading. But no worries, next time I will first consult you if my “statement” is not going to confuse people. Hope it makes you feel better.

I’m using the Mosquitto broker, which is working perfectly and stays ‘up’ while HA is rebooting.

This is by design and mentioned on the instruction page you’ve linked:

MQTT supports so-called Birth and Last Will and Testament (LWT) messages. The former is used to send a message after the service has started, and the latter is used to notify other clients about an ungracefully disconnected client.

Shutting down or rebooting Home Assistant is not ungracefully, but something like removing power is.

See Paulus’ comment on github in an corresponding issue. The issue also mentions that sending the will message by an automation does not seem to work so you might be out of luck here.

1 Like

Ok clear, thanks. And in case of HA crashing, would that also qualify as ‘ungracefully’ (I assume yes)?

I just want to monitor if HA is still up and running. Mosquitto is on the same machine, so I can’t test removing the power :slight_smile:

I just tested it by killing HA’s container and got the will message. I would assume an internal crash of HA would produce the same result.