Skip to content

Conversation

@marsteel
Copy link

  • Replace all 17 occurrences across 5 YAML files
  • watermeter.yaml: 3 replacements
  • water-resistor.yaml: 3 replacements
  • s0-watermeter.yaml: 4 replacements
  • gaspuls.yaml: 4 replacements
  • tcrt5000.yaml: 3 replacements

The current_option() method returns const char* directly, so no .c_str() conversion is needed.

This fixes ESPHome deprecation warnings for Select components.

What does this implement/fix? / Wat implementeert/repareert dit?

Proposed change / Voorgestelde verandering.

Types of changes / Soorten wijzigingen .

  • Bugfix (fixed change that fixes an issue) / Bugfix (vaste wijziging die een probleem verhelpt)
  • New feature (thanks!) / Nieuwe functie (bedankt!)
  • Breaking change (repair/feature that breaks existing functionality) / Breaking change (reparatie/functie waardoor bestaande functionaliteit kapot gaat)
  • Other / Ander
  • Website of github readme file update
  • Github workflows

Test Environment / Test Omgeving

  • Water meter / Watermeter
  • S0 counter / S0 teller
  • ESPHome version / ESPHome versie ````ESPHome version 2025.12.6 ```
  • Home Assistant version / Home Assistant versie ````Core 2026.1.1 ```
  • Website of github readme file update

Additional information / Aanvullende info

  • This PR fixes or closes the issue: fixes / Deze PR repareert of sluit het probleem: fixes warning: 'esphome:: select: :Select::state' is deprecated #286
  • This PR is related to an issue or discussion / Deze PR is gerelateerd aan een probleem of discussie:
  • Link to pull request for documentation / Link naar pull-aanvraag voor documentatie:

Supplying a configuration snippet / Voorbeeld invoer voor configuration.yaml:

# Example configuration.yaml

Checklist / Checklijst:

  • The code change has been tested and works locally / De codewijziging is getest en werkt lokaal.
  • The code change has not yet been tested / De codewijziging is nog niet getest.

If user-visible functionality or configuration variables are added/modified / Als door de gebruiker zichtbare functionaliteit of configuratievariabelen worden toegevoegd/gewijzigd :

  • Documentation added/updated in the readme file / Documentatie toegevoegd/bijgewerkt in de readme file.
  • Added/updated documentation for the web page / Documentatie toegevoegd/bijgewerkt voor de webpagina (s0tool.nl)[https://s0tool.nl].

- Replace all 17 occurrences across 5 YAML files
- watermeter.yaml: 3 replacements
- water-resistor.yaml: 3 replacements
- s0-watermeter.yaml: 4 replacements
- gaspuls.yaml: 4 replacements
- tcrt5000.yaml: 3 replacements

The current_option() method returns const char* directly,
so no .c_str() conversion is needed.

This fixes ESPHome deprecation warnings for Select components.
@huizebruin huizebruin added bugfix Fixing a bug. esphome ESPHome-specific issue labels Jan 17, 2026
@huizebruin
Copy link
Owner

I'm going to test it out.
thanks for the fix

@huizebruin
Copy link
Owner

I got by the esphome 2026.1.x
now errors when i use the above code.
image

i'm testing this right now

filters:
    lambda: return x * atof(id(Select_pulse_water).current_option().c_str()) * 1000;    #2026.1 update
      ```
and
lambda: return id(initial_water_usage) + (id(total_water_pulses) * atof(id(Select_pulse_water).current_option().c_str()));   #2026.1 update
      

@marsteel
Copy link
Author

marsteel commented Jan 23, 2026

Related to esphome/esphome#13095

I run same error when I try to update to ESPHome 2026.1.1

INFO ESPHome 2025.12.6
INFO Reading configuration /config/esphome/esphome-web-ebc3c8.yaml...
INFO Detected timezone 'Europe/Amsterdam'
INFO Generating C++ source...
INFO Compiling app... Build path: /data/build/esphome-web-ebc3c8
Processing esphome-web-ebc3c8 (board: esp32-s3-devkitc-1; framework: espidf; platform: https://github.com/pioarduino/platform-espressif32/releases/download/55.03.31-2/platform-espressif32.zip)
--------------------------------------------------------------------------------
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
 - contrib-piohome @ 3.4.4 
 - framework-espidf @ 3.50501.0 (5.5.1) 
 - tool-cmake @ 4.0.3 
 - tool-esp-rom-elfs @ 2024.10.11 
 - tool-esptoolpy @ 5.1.0 
 - tool-mklittlefs @ 3.2.0 
 - tool-ninja @ 1.13.1 
 - tool-scons @ 4.40801.0 (4.8.1) 
 - toolchain-xtensa-esp-elf @ 14.2.0+20241119
Reading CMake configuration...
Dependency Graph
|-- ArduinoJson @ 7.4.2
Compiling .pioenvs/esphome-web-ebc3c8/src/main.cpp.o
/config/esphome/esphome-web-ebc3c8.yaml: In lambda function:
/config/esphome/esphome-web-ebc3c8.yaml:128:60: error: request for member 'c_str' in 'Select_pulse_water->esphome::template_::TemplateSelect::esphome::select::Select.esphome::select::Select::current_option()', which is of non-class type 'const char*'
  128 | 
      |                                                            ^    
/config/esphome/esphome-web-ebc3c8.yaml: In lambda function:
/config/esphome/esphome-web-ebc3c8.yaml:153:118: error: request for member 'c_str' in 'Select_pulse_water->esphome::template_::TemplateSelect::esphome::select::Select.esphome::select::Select::current_option()', which is of non-class type 'const char*'
  153 | 
      |                                                                                                                      ^    
/config/esphome/esphome-web-ebc3c8.yaml: In lambda function:
/config/esphome/esphome-web-ebc3c8.yaml:54:72: error: request for member 'c_str' in 'Select_pulse_water->esphome::template_::TemplateSelect::esphome::select::Select.esphome::select::Select::current_option()', which is of non-class type 'const char*'
   54 |             value: !lambda "return ( meter_value * atof(id(Select_pulse_water).current_option().c_str()) );"
      |                                                                        ^~~~~
In file included from src/esphome/components/binary_sensor/filter.h:3,
                 from src/esphome/components/binary_sensor/binary_sensor.h:5,
                 from src/esphome/core/application.h:30,
                 from src/esphome/components/api/api_frame_helper.h:13,
                 from src/esphome/components/api/api_connection.h:5,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h: In instantiation of 'esphome::TemplatableValue<T, X>::TemplatableValue(F) requires !(invocable<F, X ...>) [with F = setup()::<lambda(float)>; T = float; X = {float}]':
src/esphome/components/globals/globals_component.h:135:3:   required from 'void esphome::globals::GlobalVarSetAction<C, Ts>::set_value(V) [with V = setup()::<lambda(float)>; C = esphome::globals::RestoringGlobalsComponent<float>; Ts = {float}]'
   40 |   template<typename V> void set_##name(V name) { this->name##_ = name; }
/config/esphome/esphome-web-ebc3c8.yaml:164:43:   required from here
  164 |   - platform: template
src/esphome/core/automation.h:55:5: error: cannot convert 'std::remove_reference<setup()::<lambda(float)>&>::type' {aka 'setup()::<lambda(float)>'} to 'float' in initialization
   55 |     new (&this->value_) T(std::move(value));
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*** [.pioenvs/esphome-web-ebc3c8/src/main.cpp.o] Error 1
========================== [FAILED] Took 7.71 seconds ==========================

Same yaml works well with 2025.12.6 I will look into it.
image

My yaml

esphome:
  name: esphome-web-ebc3c8
  friendly_name: ESPHome Web ebc3c8
  min_version: 2025.5.0
  name_add_mac_suffix: false

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

# ⬇ Enable logging ⬇ #
logger:
  level: debug #INFO
  tx_buffer_size: 200  #16-07-2025 tx_buffer_size to 200 bytes for ESPHome v2025.7.x
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Enable web server
web_server:
  port: 80
  version: 3

ota:
  - platform: esphome
    id: ota_esphome
  # - platform: http_request
  #   id: ota_http_request

http_request:
  verify_ssl: false

time:
  - platform: homeassistant
    id: time_homeassistant
    #on_time_sync:
     # - component.update: S0tool_uptime_timestamp

# Delen en bewerken mag maar laat deze eerste regels staan.
# Bron : https://www.huizebruin.nl
# Bron File : https://github.com/huizebruin/s0tool/tree/main/esphome
# © Huizebruin.nl
#  # ⬇ Enable Home Assistant API ⬇ #
api:
  services:
    - service: meterstand_water
      variables:
        meter_value: float
      then:
        - globals.set:
            id: initial_water_usage
            value: !lambda "return ( meter_value * atof(id(Select_pulse_water).current_option()) );"
        - globals.set:
            id: total_water_pulses
            value:  "0"



globals:
  - id: initial_water_usage
    type: float
    restore_value: yes
    initial_value: '0'
  - id: total_water_pulses
    type: int
    restore_value: yes
    initial_value: '0'

select:
  # ⬇ water per m3 rate ⬇ #
  - platform: template
    name: "Pulsrate water per m3"
    id: Select_pulse_water
    optimistic: true
    options:
      - "0.0001"
      - "0.0005"
      - "0.001"
      - "0.01"
      - "0.1"
    initial_option: "0.001"
    restore_value: yes
    # on_value:
    #   then:
    #     - logger.log:
    #         format: "Chosen option: %s (index %d)"
    #         args: ["x.c_str()", "i"]#------------------------# Watermeter #------------------------#
    
binary_sensor:
  - platform: gpio
    id: water_sensor_status
    name: "Water sensor status"
    internal: false
    use_interrupt: false
    pin:
      number: GPIO4
      allow_other_uses: true
      inverted: true
      mode:
        input: true
        pullup: true
    on_press:
      - then:
          lambda: id(total_water_pulses) += 1;

sensor:
#------------------------# Watermeter #------------------------#
# ⬇ watermeter pulsen ⬇ #
  - platform: pulse_meter #pulse_counter
    internal_filter_mode: "PULSE"
    internal_filter: 50ms
    pin:
      number: GPIO4
      allow_other_uses: true
      mode:
        input: true
        pullup: true
    id: watermeter_flow
    name: "watermeter flow"
    state_class: measurement
    unit_of_measurement: "l/min"
    accuracy_decimals: 1
    icon: "mdi:water-pump"
    filters:
      lambda: return x * atof(id(Select_pulse_water).current_option()) * 1000;

# ⬇ Totaal watermeter ⬇ #
    total:
      id: sensor_pulse_meter_total
      name: "watermeter Totaal"
      state_class: "total_increasing"
      device_class: water
      icon: mdi:water
      unit_of_measurement: "m³"
      accuracy_decimals: 3
      filters:
        - multiply: 0.001


# ⬇ Watermeter stand bij benadering ⬇ #
  - platform: template
    id: watermeter_total
    name: "watermeter stand"
    state_class: "total_increasing"
    device_class: water
    icon: mdi:water
    unit_of_measurement: "m³"
    update_interval: 30s
    accuracy_decimals: 3
    lambda: return id(initial_water_usage) + (id(total_water_pulses) * atof(id(Select_pulse_water).current_option()));

# ⬇ Waterpulses  only web interface for debugging ⬇ #
  - platform: template
    id: watermeter_flow_totaal
    name: "watermeter flow totaal"
    state_class: "total_increasing"
    accuracy_decimals: 0
    lambda: return id(total_water_pulses);
    internal: True

# ⬇ Totaal watermeter in liter ⬇
  - platform: template
    name: "watermeter Totaal (L)"
    unit_of_measurement: "L"
    accuracy_decimals: 0
    icon: mdi:water
    lambda: |-
      return id(sensor_pulse_meter_total).state * 1000;
    update_interval: 10s
    state_class: "total_increasing"
    device_class: water

  - platform: uptime
    name: "Uptime"
  - platform: wifi_signal
    name: "Wi-Fi Signal"
    update_interval: 60s

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "IP Address"
    ssid:
      name: "Wi-Fi SSID"
    bssid:
      name: "Wi-Fi BSSID"
  - platform: version
    name: "ESPHome Version"
    hide_timestamp: true

- Store current_option() result in auto variable before calling .c_str()
- Fixes compatibility with ESPHome PR #13095 (StringRef return type)
- Updated 5 files with 17 lambda expressions total:
  * gaspuls.yaml: 4 fixes
  * s0-watermeter.yaml: 4 fixes
  * tcrt5000.yaml: 3 fixes
  * water-resistor.yaml: 3 fixes
  * watermeter.yaml: 3 fixes

This follows the migration guide from ESPHome PR #13095 where
current_option() now returns StringRef instead of const char*.
@marsteel
Copy link
Author

marsteel commented Jan 23, 2026

I've updated all 5 YAML files that were modified in commit 3d4bf57 to properly handle the new StringRef return type from current_option() as per ESPHome PR #13095.

Files Updated:

✅ gaspuls.yaml- 4 lambda expressions fixed
✅ s0-watermeter.yaml - 4 lambda expressions fixed
✅ tcrt5000.yaml - 3 lambda expressions fixed
✅ water-resistor.yaml - 3 lambda expressions fixed
✅ watermeter.yaml - 3 lambda expressions fixed

What Changed:

Before (commit 3d4bf57):

yaml

lambda: return x * atof(id(Select_pulse_water).current_option()) * 1000;

After (new fix for StringRef):

yaml

lambda: |
  auto option = id(Select_pulse_water).current_option();
  return x * atof(option.c_str()) * 1000;

Why This Fix is Needed:

The previous commit replaced .state.c_str() with .current_option(), which worked when current_option() returned const char*. However, ESPHome PR #13095 changed the return type to StringRef, which requires:

  1. Store the result in an auto variable
  2. Call .c_str() on that StringRef to get the C string for atof()
    This pattern follows the official migration guide and ensures compatibility with newer ESPHome versions (2025.10.0+).
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixing a bug. esphome ESPHome-specific issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

warning: 'esphome:: select: :Select::state' is deprecated

2 participants