Error in Lambda code since upgrade

Hi all.

Some time ago I installed a sprinkler control system that has been working flawlessly. Several ESPHome updates ago, I started getting errors similar to below when I try to install to the ESP8266. The repository is not being maintained any longer, so I can’t ask the owner. I was hoping the more experienced coders might be able to point me in the right direction to fix the code. I assume something was deprecated and the format has changed?

INFO Reading configuration /config/esphome/sprinkler.yaml...
WARNING ESP8266: Pin 9 (9-10) might already be used by the flash interface in QUAD IO flash mode.
WARNING ESP8266: Pin 10 (9-10) might already be used by the flash interface in QUAD IO flash mode.
INFO Generating C++ source...
INFO Compiling app...
Processing sprinkler (board: esp01_1m; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <DNSServer> 1.1.1
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
Compiling /data/sprinkler/.pioenvs/sprinkler/src/main.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:1085:66: error: reference to 'optional' is ambiguous
 1085 |   sensor_lambdafilter = new sensor::LambdaFilter([=](float x) -> optional<float> {
      |                                                                  ^~~~~~~~
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
                 from src/esphome/core/component.h:4,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: 'template<class _Tp> class std::optional'
   60 |     class optional;
      |           ^~~~~~~~
In file included from src/esphome/core/component.h:7,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note:                 'template<class T> class esphome::optional'
   36 | template<typename T> class optional {  // NOLINT
      |                            ^~~~~~~~
src/main.cpp:1085:74: error: expected '{' before '<' token
 1085 |   sensor_lambdafilter = new sensor::LambdaFilter([=](float x) -> optional<float> {
      |                                                                          ^
src/main.cpp:1085:75: error: expected primary-expression before 'float'
 1085 |   sensor_lambdafilter = new sensor::LambdaFilter([=](float x) -> optional<float> {
      |                                                                           ^~~~~
/config/esphome/sprinkler.yaml:703:47: error: reference to 'optional' is ambiguous
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
                 from src/esphome/core/component.h:4,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: 'template<class _Tp> class std::optional'
   60 |     class optional;
      |           ^~~~~~~~
In file included from src/esphome/core/component.h:7,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note:                 'template<class T> class esphome::optional'
   36 | template<typename T> class optional {  // NOLINT
      |                            ^~~~~~~~
/config/esphome/sprinkler.yaml:703:55: error: expected '{' before '<' token
/config/esphome/sprinkler.yaml:703:56: error: expected primary-expression before 'bool'
/config/esphome/sprinkler.yaml:180:47: error: reference to 'optional' is ambiguous
  180 |     lambda: return id(relay2).state;
      |                                               ^       
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
                 from src/esphome/core/component.h:4,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: 'template<class _Tp> class std::optional'
   60 |     class optional;
      |           ^~~~~~~~
In file included from src/esphome/core/component.h:7,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note:                 'template<class T> class esphome::optional'
   36 | template<typename T> class optional {  // NOLINT
      |                            ^~~~~~~~
/config/esphome/sprinkler.yaml:180:55: error: expected '{' before '<' token
  180 |     lambda: return id(relay2).state;
      |                                                       ^
/config/esphome/sprinkler.yaml:180:56: error: expected primary-expression before 'bool'
  180 |     lambda: return id(relay2).state;
      |                                                        ^   
/config/esphome/sprinkler.yaml:195:47: error: reference to 'optional' is ambiguous
  195 |     lambda: return id(relay3).state;
      |                                               ^       
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
                 from src/esphome/core/component.h:4,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: 'template<class _Tp> class std::optional'
   60 |     class optional;
      |           ^~~~~~~~
In file included from src/esphome/core/component.h:7,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note:                 'template<class T> class esphome::optional'
   36 | template<typename T> class optional {  // NOLINT
      |                            ^~~~~~~~
/config/esphome/sprinkler.yaml:195:55: error: expected '{' before '<' token
  195 |     lambda: return id(relay3).state;
      |                                                       ^
/config/esphome/sprinkler.yaml:195:56: error: expected primary-expression before 'bool'
  195 |     lambda: return id(relay3).state;
      |                                                        ^   
/config/esphome/sprinkler.yaml:355:53: error: reference to 'optional' is ambiguous
  355 |     id: irrigation_zone2_remaining
      |                                                     ^       
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
                 from src/esphome/core/component.h:4,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: 'template<class _Tp> class std::optional'
   60 |     class optional;
      |           ^~~~~~~~
In file included from src/esphome/core/component.h:7,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note:                 'template<class T> class esphome::optional'
   36 | template<typename T> class optional {  // NOLINT
      |                            ^~~~~~~~
/config/esphome/sprinkler.yaml:355:61: error: expected '{' before '<' token
  355 |     id: irrigation_zone2_remaining
      |                                                             ^
/config/esphome/sprinkler.yaml:355:62: error: expected primary-expression before 'float'
  355 |     id: irrigation_zone2_remaining
      |                                                              ^    
/config/esphome/sprinkler.yaml:370:53: error: reference to 'optional' is ambiguous
  370 |     id: irrigation_zone3_remaining
      |                                                     ^       
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
                 from src/esphome/core/component.h:4,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: 'template<class _Tp> class std::optional'
   60 |     class optional;
      |           ^~~~~~~~
In file included from src/esphome/core/component.h:7,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note:                 'template<class T> class esphome::optional'
   36 | template<typename T> class optional {  // NOLINT
      |                            ^~~~~~~~
/config/esphome/sprinkler.yaml:370:61: error: expected '{' before '<' token
  370 |     id: irrigation_zone3_remaining
      |                                                             ^
/config/esphome/sprinkler.yaml:370:62: error: expected primary-expression before 'float'
  370 |     id: irrigation_zone3_remaining
      |                                                              ^    
/config/esphome/sprinkler.yaml:385:53: error: reference to 'optional' is ambiguous
  385 |   # Retrieve list of times from the Home Assistant UI.
      |                                                     ^~      
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
                 from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
                 from src/esphome/core/component.h:4,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: 'template<class _Tp> class std::optional'
   60 |     class optional;
      |           ^~~~~~~~
In file included from src/esphome/core/component.h:7,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note:                 'template<class T> class esphome::optional'
   36 | template<typename T> class optional {  // NOLINT
      |                            ^~~~~~~~
/config/esphome/sprinkler.yaml:385:61: error: expected '{' before '<' token
  385 |   # Retrieve list of times from the Home Assistant UI.
      |                                                             ^
/config/esphome/sprinkler.yaml:385:62: error: expected primary-expression before 'float'
  385 |   # Retrieve list of times from the Home Assistant UI.
      |                                                              ^    
*** [/data/sprinkler/.pioenvs/sprinkler/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.29 seconds ==========================

Thanks,
Glenn.

The Arduino framework version was upgraded in ESPHome v2022.2.x and this framework version uses a newer version of the compiler.

You can try to compile your device with the old version by adding the previous version number in your yaml file.

esphome:
  name: sprinkler

esp8266:
  board: esp01_1m
  framework:
    version: 2.7.4

Thank you for replying. It says framework is an invalid option.

I think the option you are looking for is arduino_version:

Thank you. That fixed it until I can dig further into the code to bring it up to speed. :slight_smile:

Did you find any long term resolution to the compilation error?

When I tried to downgrade the Aurdino version the ESP looses kontact with the API after a few seconds and reboots, when I comment on the version it fails to compile in the main.ccp but in my case in the WiFi modules, so it seems like the root cause is similar but it is random in which module it shows up.

Hi there. No, I have just left it set to the earlier version and it seems happy. I took a look at the code, but it is a little beyond my skill set at present.

Ok, thank you for responding.

I’ll leave it there too for the time being, and will focus om the API going unresponsive and then shutting down the connection to the Sonoff.

The API probelem was resolved by upgrading to the latest ESPHome - I hade not noticed the switch from native/supported Add-On to separate, manually installed Add-On. The Sonoff is now stable.