Skip to content

Commit 7069c87

Browse files
BrentIOclaude
andcommitted
fix: clear OTA update availability on initial MQTT connect after reboot
On first MQTT connect (auto-discovery not yet sent), publish retained "offline" to the update availability topic so HA shows "Unavailable" instead of the stale "Update available" from the previous session's retained state. The OTA check will publish "online" once it confirms the current firmware state. Also adds "online" to the onAvailable callback, which previously never set the availability topic, leaving the entity stuck "Unavailable" after the initial connect fix when an update is found. Closes #685 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 43b27c6 commit 7069c87

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Controller/Controller.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,6 +3661,10 @@ void setup_OtaFirmware(){
36613661
if(!mqttClient.connected()){ return; }
36623662
eventLog.createEvent("OTA update available");
36633663

3664+
char availability_topic[MQTT_TOPIC_UPDATE_AVAILABILITY_LENGTH+1];
3665+
snprintf(availability_topic, sizeof(availability_topic), MQTT_TOPIC_UPDATE_AVAILABILITY_PATTERN, deviceIdentity.data.uuid);
3666+
mqttClient.publish(availability_topic, "online", true);
3667+
36643668
JsonDocument mqttDoc;
36653669
mqttDoc["installed_version"] = VERSION;
36663670
mqttDoc["latest_version"] = version;
@@ -4161,6 +4165,11 @@ void mqtt_reconnect(){
41614165
mqtt_autoDiscovery_heapFree();
41624166
mqtt_autoDiscovery_heapLargestFreeBlock();
41634167
mqttClient.autoDiscovery.sent = true;
4168+
if(deviceIdentity.enabled && !_otaManifestUrl.isEmpty()){
4169+
char update_avail_topic[MQTT_TOPIC_UPDATE_AVAILABILITY_LENGTH+1];
4170+
snprintf(update_avail_topic, sizeof(update_avail_topic), MQTT_TOPIC_UPDATE_AVAILABILITY_PATTERN, deviceIdentity.data.uuid);
4171+
mqttClient.publish(update_avail_topic, "offline", true);
4172+
}
41644173
}
41654174
mqtt_publishAllAvailability();
41664175
mqtt_publishTemperatures();

0 commit comments

Comments
 (0)