I have added a device tracker in MQTT to track the state of my kiddo. I update this state in MQTT based on various events/automations that occur. (we arrive/leave from daycare, his door opens/closes etc.) This all works great. Below is the code for the configured device tracker including an example script:
mqtt:
device_tracker:
- name: "kiddo"
source_type: "router" # This makes it a stationary tracker
state_topic: "homeassistant/device_tracker/kiddo/state"
script:
kiddo_is_home:
alias: "Kiddo is home"
sequence:
- service: mqtt.publish
data:
topic: homeassistant/device_tracker/kiddo/state
payload: home
retain: true
mode: single
icon: mdi:teddy-bear
The problem I’m having is that the state of the device tracker does not seem to survive a restart of Home Assistant. The retain option works perfectly, if I check MQTT Explorer AFTER firing the script the state clearly shows the latest value, so that works. The device tracker also updates, but unfortunaly when restarting it does not retrieve the value from MQTT again, resulting in an “unknown”.
I figured I could just add an automation that updates the value on restart, but it seems you can only publish to MQTT and there is no read service.
In the end, I think the device tracker should just update correctly. Is this a bug or am I missing something? The documentation for MQTT device tracker doesn’t really give more insights: MQTT Device Tracker - Home Assistant