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.
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?
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.
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.