Sensor .raw_state Deprecated in Favor of get_raw_state()
Direct access to the sensor .raw_state member is now deprecated. Use get_raw_state() instead. The .raw_state member will be removed in ESPHome 2026.10.0.
This is a breaking change for external components in ESPHome 2026.4.0 and later.
Background
Section titled “Background”PR #15094: Deprecate .raw_state, guard raw_callback_ behind USE_SENSOR_FILTER
This follows the same pattern as the text_sensor .raw_state deprecation. Accessor methods allow future optimizations to the internal storage without breaking callers.
Additionally, raw_callback_ is now guarded behind USE_SENSOR_FILTER, saving 4 bytes per sensor instance when no filters are configured.
What’s Changing
Section titled “What’s Changing”// Beforefloat raw = id(my_sensor).raw_state;
// Afterfloat raw = id(my_sensor).get_raw_state();The .state member is not deprecated — it remains a valid public member. However, examples in the docs now show get_state() to encourage the accessor pattern.
Who This Affects
Section titled “Who This Affects”External components and lambda users that directly access .raw_state on sensor instances.
The deprecated member still works but emits a compiler warning. It will be removed in 2026.10.0.
Migration Guide
Section titled “Migration Guide”Replace all direct .raw_state access with get_raw_state():
// Beforefloat raw = id(my_sensor).raw_state;float current = this->raw_state;
// Afterfloat raw = id(my_sensor).get_raw_state();float current = this->get_raw_state();Important: Nothing outside of Sensor::publish_state() should ever write to raw_state. If your component does this, it is a bug — use publish_state() instead.
Supporting Multiple ESPHome Versions
Section titled “Supporting Multiple ESPHome Versions”get_raw_state() has been available since before this deprecation (it was previously defined in .cpp), so you can simply switch to it without a version guard:
float raw = id(my_sensor).get_raw_state();Timeline
Section titled “Timeline”- ESPHome 2026.4.0 (April 2026):
.raw_statedeprecated with compiler warning - ESPHome 2026.10.0 (October 2026):
.raw_statemember removed
Finding Code That Needs Updates
Section titled “Finding Code That Needs Updates”# Find direct .raw_state access in your componentgrep -rn '\.raw_state' your_component/grep -rn '->raw_state' 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.