Weird esphome compilation error due to template sensor config

When I compile my project, it errors out and references template sensor. If i comment out the temperature rise template sensor, it compiles fine. I can’t see the error and am hoping someone can point me in the right direction.

# Supply temp/pressure
  - platform: bmp280_i2c
    i2c_id: bus_supply
    # address: 0x77
    # temperature: 
    #   accuracy_decimals: 2
    #   id: supply_bmp_temp
    #   name: "Supply - BMP Temperature"
    pressure: 
      id: supply_press
      name: "Supply - Pressure"
    update_interval: 10s
  
  - platform: aht10
    i2c_id: bus_supply
    # address: 0x38
    temperature: 
      id: supply_temp
      name: "Supply - Temperature"
    humidity: 
      id: supply_rh
      name: "Supply - Humidity"
    update_interval: 10s

  # Return temp/pressure
  - platform: bmp280_i2c
    i2c_id: bus_return
    # address: 0x77
    # temperature: 
    #   accuracy_decimals: 2
    #   id: return_bmp_temp
    #   name: "Return - BMP Temperature"
    pressure: 
      id: return_press
      name: "Return - Pressure"
    update_interval: 10s
  
  - platform: aht10
    i2c_id: bus_return
    # address: 0x38
    temperature: 
      id: return_temp
      name: "Return - Temperature"
    humidity: 
      id: return_rh
      name: "Return - Humidity"
    update_interval: 10s

  # Temperature Rise
  - platform: template
    name: "Temperature Rise"
    id: temp_rise
    unit_of_measurement: "°C"
    lambda: |-
      if (isnan(id(supply_temp).state) || isnan(id(return_temp).state)) {
        return NAN;
      } else {
        return id(supply_temp).state - id(return_temp).state;
      }
    update_interval: 10s

Here is the compilation error:

Compiling .pioenvs/esp-furnace/src/main.cpp.o
In file included from src/esphome/components/esp32_rmt_led_strip/led_strip.h:12,
                 from src/esphome.h:27,
                 from src/main.cpp:3:
/data/cache/platformio/packages/framework-espidf/components/driver/deprecated/driver/rmt.h:18:2: warning: #warning "The legacy RMT driver is deprecated, please use driver/rmt_tx.h and/or driver/rmt_rx.h" [-Wcpp]
   18 | #warning "The legacy RMT driver is deprecated, please use driver/rmt_tx.h and/or driver/rmt_rx.h"
      |  ^~~~~~~
Linking .pioenvs/esp-furnace/firmware.elf
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/esp-furnace/src/main.cpp.o:(.literal._Z5setupv+0x3dc): undefined reference to `_ZTVN7esphome9template_14TemplateSensorE'
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/esp-furnace/src/main.cpp.o:(.literal._Z5setupv+0x3e0): undefined reference to `_ZTVN7esphome9template_14TemplateSensorE'
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/esp-furnace/src/main.cpp.o:(.literal._Z5setupv+0x4a4): undefined reference to `_ZN7esphome9template_14TemplateSensor12set_templateEOSt8functionIFNS_8optionalIfEEvEE'
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/esp-furnace/src/main.cpp.o: in function `_ZN7esphome5aht1014AHT10Component22set_temperature_sensorEPNS_6sensor6SensorE':
/data/build/esp-furnace/src/esphome/components/aht10/aht10.h:22: undefined reference to `_ZN7esphome9template_14TemplateSensor12set_templateEOSt8functionIFNS_8optionalIfEEvEE'
collect2: error: ld returned 1 exit status
*** [.pioenvs/esp-furnace/firmware.elf] Error 1
========================= [FAILED] Took 18.91 seconds =========================

Seems there may be an issue with esp idf, s3 boards and template/lambdas:

Seems to be related:

the RMT warning should be fixed in a future release due to esp idf 5. That warning still exists when the template sensor is commented out and the compilation/linking is successful.

You need to clean the build before recompiling with the added template.

1 Like

Thanks, that did the trick. I haven’t added just a template sensor by itself before, so I haven’t seen this behaviour.

It’s a bug probably in platformio. It used to happen when adding a new component, that has been fixed, but adding a new platform still triggers it with ESP-IDF.