Need a way to publish a message to mqtt broker that hass have been stopped

Hi,

Is there any way to publish a message to mqtt broker that hass have been stopped?

Tried so far:

mqtt:
  broker: 127.0.0.1
  birth_message:
    topic: 'homeassistant/state'
    payload: 'online'
  will_message:
    topic: 'homeassistant/state'
    payload: 'offline'  
  • this works only if I kill -SIGKILL hass.

automations.yaml:

- alias: mqtt_ha_shutdown
  trigger:
    platform: homeassistant
    event: shutdown
  action:
    - service: mqtt.publish
      data:
        topic: homeassistant/state
        retain: true
        payload: "offline"
  • this does not work - I think mqtt platform is already shutdown when automation is triggered by this event.

(First example).

EDIT: oh, you tried that and it did not work. Sorry.