Fix MQTT last will on graceful disconnect#12133
Fix MQTT last will on graceful disconnect#12133OttoWinter wants to merge 1 commit intohome-assistant:devfrom
Conversation
You made the right observation. https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament states:
So last will is only for ungracefully disconnections. I think an update to the docs is appropriate. I think that alway sending a message can already be done today by having an automation listen for Home Assistant shutting down? |
balloob
left a comment
There was a problem hiding this comment.
Since Home Assistant is the foundation for others to build upon, we need to follow the spec to the letter. Anytime we diverge, we are causing confusion and problems down the line.
|
Sorry for the late reply, just lots of stuff going on right now. Anyway... I agree Home Assistant should remain free of unexpected behavior and I'm happy this project choses this path since many other projects have failed because their custom unexpected behavior accumulated over time. So, to still address the underlying problem, as you hinted at, it would be best to update the docs instead. But while doing so, I noticed that manually publishing a MQTT message on - alias: MQTT last will
id: [...]
trigger:
- event: shutdown
platform: homeassistant
action:
- service: mqtt.publish
data:
topic: hass/status
payload: offline(Unrelated, but is there any update on #12004? I would like to have that issue fixed 😀) |
Description:
See linked issues. In a nutshell, the MQTT client only sends the last will message if the connection is dropped, but not on a graceful disconnect.
Note: There's a point to be made in favor of the current behavior. Sometimes we want to know when a disconnect was "ungraceful". I would say though that in most cases, the last will message is used to determine whether Home Assistant is
onlineoroffline(even the docs are using it this way)Related issue (if applicable): fixes #6240, fixes #9017
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4566
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass