From 305a58cb8435d90254181e1fe18ad3ddc8b44f50 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 16 Dec 2025 00:07:28 +0000 Subject: [PATCH] Use config_hash in MQTT and version sensor Change MQTT sw_version and version text sensor to display config_hash instead of build_time_str. Format: "(config hash 0xXXXXXXXX)" Version sensor with hide_timestamp=false also includes build time: "(config hash 0xXXXXXXXX, built: YYYY-MM-DD HH:MM:SS +ZZZZ)" --- esphome/components/mqtt/mqtt_component.cpp | 8 ++++---- esphome/components/version/version_text_sensor.cpp | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/esphome/components/mqtt/mqtt_component.cpp b/esphome/components/mqtt/mqtt_component.cpp index 6f5cf5edad..44fa570850 100644 --- a/esphome/components/mqtt/mqtt_component.cpp +++ b/esphome/components/mqtt/mqtt_component.cpp @@ -68,7 +68,8 @@ bool MQTTComponent::send_discovery_() { return global_mqtt_client->publish(this->get_discovery_topic_(discovery_info), "", 0, this->qos_, true); } - ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name_().c_str()); + ESP_LOGI(TAG, "'%s': Sending discovery to %s", this->friendly_name_().c_str(), + this->get_discovery_topic_(discovery_info)); // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson return global_mqtt_client->publish_json( @@ -154,9 +155,8 @@ bool MQTTComponent::send_discovery_() { device_info[MQTT_DEVICE_MANUFACTURER] = model == nullptr ? ESPHOME_PROJECT_NAME : std::string(ESPHOME_PROJECT_NAME, model - ESPHOME_PROJECT_NAME); #else - char build_time_str[App.BUILD_TIME_STR_SIZE]; - App.get_build_time_string(build_time_str); - device_info[MQTT_DEVICE_SW_VERSION] = str_sprintf(ESPHOME_VERSION " (%s)", build_time_str); + device_info[MQTT_DEVICE_SW_VERSION] = + str_sprintf(ESPHOME_VERSION " (config hash 0x%08" PRIx32 ")", App.get_config_hash()); device_info[MQTT_DEVICE_MODEL] = ESPHOME_BOARD; #if defined(USE_ESP8266) || defined(USE_ESP32) device_info[MQTT_DEVICE_MANUFACTURER] = "Espressif"; diff --git a/esphome/components/version/version_text_sensor.cpp b/esphome/components/version/version_text_sensor.cpp index 88774b4b3a..f03c91e5f5 100644 --- a/esphome/components/version/version_text_sensor.cpp +++ b/esphome/components/version/version_text_sensor.cpp @@ -11,11 +11,12 @@ static const char *const TAG = "version.text_sensor"; void VersionTextSensor::setup() { if (this->hide_timestamp_) { - this->publish_state(ESPHOME_VERSION); + this->publish_state(str_sprintf(ESPHOME_VERSION " (config hash 0x%08" PRIx32 ")", App.get_config_hash())); } else { char build_time_str[esphome::Application::BUILD_TIME_STR_SIZE]; App.get_build_time_string(build_time_str); - this->publish_state(str_sprintf(ESPHOME_VERSION " %s", build_time_str)); + this->publish_state(str_sprintf(ESPHOME_VERSION " (config hash 0x%08" PRIx32 ", built: %s)", App.get_config_hash(), + build_time_str)); } } float VersionTextSensor::get_setup_priority() const { return setup_priority::DATA; }