TL;DR: After I enabled a few additional PiFire entities, Home Assistant reloaded its MQTT integration. Every PiFire entity then became unavailable even though the smoker was still running normally.
Restarting PiFire would have published its online status again, but I did not want to restart the control process in the middle of a cook. I manually republished the status instead. Some values, including the setpoint, were still missing because PiFire only republishes them when they change.
The problem is that PiFire only tells the MQTT broker to save the autodiscovery messages that describe which Home Assistant entities should exist. It does not tell the broker to save whether PiFire is online or the current values for those entities. Home Assistant can therefore recreate everything when it reconnects, but it has no way to know whether PiFire is available or what values it should display.
I’ve started working on this, and I’m planning to split the fix into two PRs.
The first PR should fix availability and MQTT connection cleanup:
- After PiFire connects, it should publish
online as a retained message. This lets the broker remember that PiFire is available and provide that status when Home Assistant reconnects.
- Before connecting, PiFire should configure an MQTT last will. This tells the broker to publish
offline if PiFire unexpectedly disappears because of a power loss, crash, Wi-Fi failure, or broken connection.
- PiFire also needs to publish
offline before an intentional disconnect. The broker only uses the last will when the connection disappears unexpectedly.
- Finally, PiFire should close the MQTT connection when MQTT is disabled or the control process exits.
The second PR should change the MQTT handler to use MQTT’s retain property to persist sensor state in the broker, just as it already does for the autodiscovery data:
- This should allow Home Assistant to recover the latest temperatures, setpoint, relay states, PID data, and other current values as soon as it reconnects.
- Event notifications should not be retained. They describe something that happened at a particular time, so replaying an old notification after Home Assistant restarts would be misleading.
- PID data needs some additional handling because PiFire sometimes publishes only part of it, such as the current cycle ratio. Since MQTT replaces the entire retained message, PiFire needs to combine partial updates with the previous PID values before publishing them.
- PiFire also currently records values as published before the MQTT client has accepted them. If a publication fails while the connection is starting, PiFire can think the value was already sent and never try again. The handler should only update that bookkeeping after the publication succeeds.
I have a fix for the first issue mostly done and hope to have a PR for that up soon. The second issue is a bit more complex, and I am working on it now. It will likely take me a bit longer because I expect to do some refactoring to avoid making the existing code messy.
TL;DR: After I enabled a few additional PiFire entities, Home Assistant reloaded its MQTT integration. Every PiFire entity then became unavailable even though the smoker was still running normally.
Restarting PiFire would have published its
onlinestatus again, but I did not want to restart the control process in the middle of a cook. I manually republished the status instead. Some values, including the setpoint, were still missing because PiFire only republishes them when they change.The problem is that PiFire only tells the MQTT broker to save the autodiscovery messages that describe which Home Assistant entities should exist. It does not tell the broker to save whether PiFire is online or the current values for those entities. Home Assistant can therefore recreate everything when it reconnects, but it has no way to know whether PiFire is available or what values it should display.
I’ve started working on this, and I’m planning to split the fix into two PRs.
The first PR should fix availability and MQTT connection cleanup:
onlineas a retained message. This lets the broker remember that PiFire is available and provide that status when Home Assistant reconnects.offlineif PiFire unexpectedly disappears because of a power loss, crash, Wi-Fi failure, or broken connection.offlinebefore an intentional disconnect. The broker only uses the last will when the connection disappears unexpectedly.The second PR should change the MQTT handler to use MQTT’s
retainproperty to persist sensor state in the broker, just as it already does for the autodiscovery data:I have a fix for the first issue mostly done and hope to have a PR for that up soon. The second issue is a bit more complex, and I am working on it now. It will likely take me a bit longer because I expect to do some refactoring to avoid making the existing code messy.