I started seeing these warnings on my ESPHome devices:
warning: ‘esphome::select::Select::state’ is deprecated: Use current_option() instead of .state. Will be removed in 2026.5.0
I managed to find that this change was introduced in the November 2025 release.
See “Select state:” entry.
The change makes a ton of sense, but I was struggling to figure out how to use “current_option()” correctly in my lambda’s
Turns out the documentation was updated, but I kinda missed that:
So I thought I would post a specific example for others that might be searching on how to fix this issue.
I had several conditionals that used a lambda to check the current selection of a “Select Component”. The code was like:
lambda: 'return (id(my_select_condition).state == “Something”);’
I thought I could just change that to:
lambda: ‘return (id(my_select_condition).current_option() == “Something”);’
But that now throws new warnings:
warning: comparison with string literal results in unspecified behavior
Turns out you need to use the string compare function - strcmp, like this:
lambda: ‘return ( strcmp( id(my_select_condition).current_option(), “Something”) == 0 );’
This essentially is calling the string compare function and gives it the current_option string and compares it to the value you provide. Strcmp returns a 0 if the strings match.
Anyway, this is all spelled out reasonably well in documentation, I just failed to see it. Hopefully this post will help someone else that is searching based on the compiler warning messages!