Application Name and Friendly Name Now Return StringRef
App.get_name() and App.get_friendly_name() now return const StringRef & instead of const std::string &. Most code compiles unchanged because StringRef provides .c_str(), .size(), .empty(), and implicit conversion to std::string. However, binding the result to const std::string & silently creates a heap-allocated temporary — update these references to const auto & to avoid the allocation.
This is a breaking change for external components in ESPHome 2026.3.0 and later.
Background
Section titled “Background”PR #14532: Application name and friendly_name return StringRef
The application name and friendly name are set once at boot and never change. Storing them as std::string wastes heap memory for the string object overhead and its dynamic allocation. StringRef is a lightweight reference to a string with static lifetime — it avoids the heap allocation entirely.
Memory savings
Section titled “Memory savings”| Platform | Flash savings | RAM savings |
|---|---|---|
| ESP8266 | 752 bytes | 176 bytes |
| RP2040 | 2,508 bytes | — |
What’s Changing
Section titled “What’s Changing”// Beforeconst std::string &get_name() const;const std::string &get_friendly_name() const;
// Afterconst StringRef &get_name() const;const StringRef &get_friendly_name() const;StringRef provides:
.c_str()— null-terminated C string pointer.size()— string length.empty()— true if emptyoperator std::string()— implicit conversion tostd::stringoperator==— comparison with string literals and other strings
Most code compiles unchanged. The key issue is when the return value is bound to const std::string & — this triggers an implicit conversion that heap-allocates a temporary std::string.
Who This Affects
Section titled “Who This Affects”External components that:
- Store
App.get_name()orApp.get_friendly_name()in aconst std::string &variable - Pass the result to functions expecting
const std::string &(triggers implicit conversion)
Standard YAML configurations are not affected.
Migration Guide
Section titled “Migration Guide”Fix silent heap allocation
Section titled “Fix silent heap allocation”// Before — compiles but silently heap-allocates a temporary:const std::string &name = App.get_name();
// After — zero allocation:const auto &name = App.get_name();Passing to functions expecting std::string
Section titled “Passing to functions expecting std::string”If you need to pass the name to a function that takes const std::string &, the implicit conversion works but allocates. If the function also accepts const char *, prefer .c_str():
// Heap-allocates (implicit conversion to std::string)some_function_taking_string(App.get_name());
// Zero allocationsome_function_taking_cstr(App.get_name().c_str());Logging
Section titled “Logging”// Works — c_str() returns null-terminated stringESP_LOGD(TAG, "Name: %s", App.get_name().c_str());Supporting Multiple ESPHome Versions
Section titled “Supporting Multiple ESPHome Versions”Using const auto & works on all versions — it binds to const std::string & on older versions and const StringRef & on 2026.3.0+:
// Safe on all versionsconst auto &name = App.get_name();ESP_LOGD(TAG, "Name: %s", name.c_str());If you need to explicitly handle both:
#if ESPHOME_VERSION_CODE >= VERSION_CODE(2026, 3, 0) const StringRef &name = App.get_name();#else const std::string &name = App.get_name();#endifTimeline
Section titled “Timeline”- ESPHome 2026.3.0 (March 2026): Return type changed
- No deprecation period — this is a signature change
Finding Code That Needs Updates
Section titled “Finding Code That Needs Updates”# Find std::string references to App.get_name()grep -rn 'std::string.*get_name\|std::string.*get_friendly_name' your_component/
# Find any usage of App.get_name() or App.get_friendly_name()grep -rn 'App\.get_name\|App\.get_friendly_name\|get_name()\.c_str\|get_friendly_name()\.c_str' 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.