Build Info and compilation_time API Changes
The App.get_compilation_time() method is deprecated in favor of new constexpr methods. The compilation_time field in the native API now updates on every compile.
This is a breaking change for external components in ESPHome 2026.1.0 and later.
Background
Section titled “Background”PR #12425: Add build info to image
This PR modernizes the build info API with compile-time evaluated methods and fixes the inconsistent compilation_time behavior.
What’s Changing
Section titled “What’s Changing”Deprecated Methods
Section titled “Deprecated Methods”// Deprecated - removal in 2026.7.0std::string App.get_compilation_time();
// Removed immediatelyconst StringRef &App.get_compilation_time_ref();New Methods
Section titled “New Methods”// New - compile-time evaluatedconstexpr time_t App.get_build_time(); // Unix timestampconstexpr uint32_t App.get_config_hash(); // FNV-1a config hashconstexpr uint32_t App.get_config_version_hash(); // Config + version hash
// New - formatted string outputvoid App.get_build_time_string(std::span<char, BUILD_TIME_STR_SIZE> buffer); // "2026-01-12 14:30:45 +0000"API compilation_time Behavior
Section titled “API compilation_time Behavior”The compilation_time field in the native API DeviceInfoResponse now updates on every compile, not just when main.cpp changes.
Who This Affects
Section titled “Who This Affects”External components that:
- Call
App.get_compilation_time()orApp.get_compilation_time_ref() - Use compilation time for preference hashing
- Depend on
compilation_timestaying constant across builds
Standard YAML configurations are not affected.
Migration Guide
Section titled “Migration Guide”1. Getting build time for display
Section titled “1. Getting build time for display”// BeforeESP_LOGI(TAG, "Built: %s", App.get_compilation_time());
// After - use bufferchar build_time[Application::BUILD_TIME_STR_SIZE];App.get_build_time_string(build_time);ESP_LOGI(TAG, "Built: %s", build_time);2. Getting build time as timestamp
Section titled “2. Getting build time as timestamp”// Before - parsed the stringconst char *time_str = App.get_compilation_time();// ... parse string to get time
// After - direct timestamp (constexpr)time_t build_time = App.get_build_time();3. Hashing for preferences
Section titled “3. Hashing for preferences”// Before - runtime hash of stringuint32_t hash = fnv1_hash(App.get_compilation_time_ref());
// After - compile-time evaluated hashuint32_t hash = App.get_config_version_hash(); // Includes ESPHome version// oruint32_t hash = App.get_config_hash(); // Config only4. Checking if config changed
Section titled “4. Checking if config changed”// The new hashes are constexpr - no runtime costconstexpr uint32_t CONFIG_HASH = App.get_config_hash();
// Use for preference invalidationif (stored_hash != CONFIG_HASH) { // Config changed, reset preferences}New API Details
Section titled “New API Details”get_build_time()
Section titled “get_build_time()”Returns the build time as a Unix timestamp (time_t). This is constexpr, meaning it’s evaluated at compile time with zero runtime cost.
time_t build = App.get_build_time();// Example: 1736694645 (Unix timestamp)get_config_hash()
Section titled “get_config_hash()”Returns a 32-bit FNV-1a hash of the configuration. Changes when the YAML config changes. Also constexpr.
uint32_t hash = App.get_config_hash();// Example: 0xABCD1234get_config_version_hash()
Section titled “get_config_version_hash()”Combines the config hash with the ESPHome version. Changes when either config or ESPHome version changes. Useful for preference invalidation.
uint32_t hash = App.get_config_version_hash();get_build_time_string()
Section titled “get_build_time_string()”Writes a formatted build time string to a buffer. Format: "YYYY-MM-DD HH:MM:SS +ZZZZ" (ISO 8601 style).
char buffer[Application::BUILD_TIME_STR_SIZE]; // 26 bytesApp.get_build_time_string(buffer);// buffer now contains "2026-01-12 14:30:45 +0000"Supporting Multiple ESPHome Versions
Section titled “Supporting Multiple ESPHome Versions”#if ESPHOME_VERSION_CODE >= VERSION_CODE(2026, 1, 0) // New API char build_time[Application::BUILD_TIME_STR_SIZE]; App.get_build_time_string(build_time); ESP_LOGI(TAG, "Built: %s", build_time);#else // Old API ESP_LOGI(TAG, "Built: %s", App.get_compilation_time());#endifTimeline
Section titled “Timeline”- ESPHome 2026.1.0 (January 2026): New methods available;
get_compilation_time()deprecated - ESPHome 2026.7.0 (July 2026):
get_compilation_time()removed
Finding Code That Needs Updates
Section titled “Finding Code That Needs Updates”# Find compilation time usagegrep -rn "get_compilation_time" your_component/
# Find any App.get_ calls related to build infogrep -rn "App\.get_" your_component/Questions?
Section titled “Questions?”If you have questions about migrating your external component, please ask in:
- ESPHome Discord - #devs channel
- ESPHome GitHub Discussions
Related Documentation
Section titled “Related Documentation”Copyright © 2026 ESPHome - A project from the Open Home Foundation
Comments
Feel free to leave a comment here to discuss this post with others. You can ask questions, share your experience, or suggest improvements. If you have a question about a specific feature or issue, please consider using the ESPHome Discord. Stick to English and follow ESPHome's code of conduct. These comments exist on a discussion on GitHub, so you can also comment there directly if you prefer.