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
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
// Before
float raw = id(my_sensor).raw_state;
// After
float 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
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
Replace all direct .raw_state access with get_raw_state():
// Before
float raw = id(my_sensor).raw_state;
float current = this->raw_state;
// After
float 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
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
- 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
# Find direct .raw_state access in your component
grep -rn '\.raw_state' your_component/
grep -rn '->raw_state' your_component/
Questions?
If you have questions about migrating your external component, please ask in:
- ESPHome Discord - #devs channel
- ESPHome GitHub Discussions
Related Documentation
Comments
Feel free to leave a comment here to discuss this post wth 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.