Can't compile with new ESP home

upgraded to new ESPhome 2022.5.0

and now I can’t compile old code which worked before

here is the error

INFO Reading configuration /config/esphome/HRVFAN.yaml...
INFO Detected timezone 'America/New_York'
INFO Generating C++ source...
INFO Compiling app...
Processing hrvfan (board: d1_mini; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB 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
|-- <Wire> 1.0
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/api_connection.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/api_frame_helper.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/api_pb2.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/api_pb2_service.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/api_server.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/list_entities.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/proto.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/subscribe_state.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/api/user_services.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/binary_sensor/automation.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/binary_sensor/binary_sensor.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/binary_sensor/filter.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/captive_portal/captive_portal.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/dallas/dallas_component.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/dallas/esp_one_wire.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/debug/debug_component.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/esp8266/core.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/esp8266/gpio.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/esp8266/preferences.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/fan/fan.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/fan/fan_helpers.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/fan/fan_state.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/gpio/switch/gpio_switch.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/homeassistant/time/homeassistant_time.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/i2c/i2c.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/i2c/i2c_bus_arduino.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/i2c/i2c_bus_esp_idf.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/logger/logger.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/md5/md5.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/mdns/mdns_component.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/mdns/mdns_esp32_arduino.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/mdns/mdns_esp8266.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/mdns/mdns_esp_idf.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/network/util.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/ota/ota_backend_arduino_esp32.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/ota/ota_backend_arduino_esp8266.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/ota/ota_backend_esp_idf.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/ota/ota_component.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/output/automation.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/output/float_output.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/pcf8574/pcf8574.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/sensor/automation.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/sensor/filter.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/sensor/sensor.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/socket/bsd_sockets_impl.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/socket/lwip_raw_tcp_impl.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/socket/socket.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/speed/fan/speed_fan.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/switch/automation.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/switch/switch.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/template/binary_sensor/template_binary_sensor.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/time/automation.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/time/real_time_clock.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/web_server_base/web_server_base.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/wifi/wifi_component.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/wifi/wifi_component_esp32_arduino.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/wifi/wifi_component_esp8266.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/components/wifi/wifi_component_esp_idf.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/application.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/color.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/component.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/component_iterator.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/controller.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/entity_base.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/helpers.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/log.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/scheduler.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/esphome/core/util.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/src/main.cpp.o
Generating LD script /data/hrvfan/.pioenvs/hrvfan/ld/local.eagle.app.v6.common.ld
Compiling /data/hrvfan/.pioenvs/hrvfan/lib975/ESPAsyncTCP-esphome/AsyncPrinter.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/lib975/ESPAsyncTCP-esphome/ESPAsyncTCP.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/lib975/ESPAsyncTCP-esphome/ESPAsyncTCPbuffer.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/lib975/ESPAsyncTCP-esphome/SyncClient.cpp.o
/config/esphome/HRVFAN.yaml: In lambda function:
/config/esphome/HRVFAN.yaml:112:3: error: control reaches end of non-void function [-Werror=return-type]
  112 |     on_state:
      |   ^
Compiling /data/hrvfan/.pioenvs/hrvfan/lib975/ESPAsyncTCP-esphome/tcp_axtls.c.o
Compiling /data/hrvfan/.pioenvs/hrvfan/libaf0/Hash/Hash.cpp.o
Archiving /data/hrvfan/.pioenvs/hrvfan/lib975/libESPAsyncTCP-esphome.a
Compiling /data/hrvfan/.pioenvs/hrvfan/lib67b/ESP8266WiFi/BearSSLHelpers.cpp.o
Compiling /data/hrvfan/.pioenvs/hrvfan/lib67b/ESP8266WiFi/CertStoreBearSSL.cpp.o
cc1plus: some warnings being treated as errors
*** [/data/hrvfan/.pioenvs/hrvfan/src/main.cpp.o] Error 1
========================= [FAILED] Took 104.60 seconds =========================

here is how it looks


  - platform: template
    name: "Pause Vent"
    id: fan_pause
    internal: false
    lambda: |-
      if (id(ac_state).state && id(hrv_fan).state) {
        id(pausefan) = true;
        return true;
      }
      if (!id(ac_state).state) {
        return false;
      }
      if (id(ac_state).state && id(pausefan)) {
        return true;
      }
    on_state:
      then:
        - if:
            condition:
              lambda: 'return(id(fan_pause).state);'
            then:
              - logger.log: "Stop Venting"
              - fan.turn_off: hrv_fan
        - if:
            condition: 
              lambda: 'return(!id(fan_pause).state && id(pausefan));'
            then:
              - logger.log: "AC now off, restoring state"
              - lambda: 'id(pausefan) = false;'
              - fan.turn_on: hrv_fan

I don’t think on state is a valid trigger. It’s likely on_value.

I’m not familiar with this use of an exclamation point, is it meant to be there?

'return(!id(fan_pause).
1 Like

The current version of the C++ compiler is “stricter” than the previous version and the lambda above the on_state causes this error. This lambda (assuming it is a Template Binary Sensor) should always return a true or false. In your case the lambda returns theoretically “nothing” if all the if condition statements are evaluated to be false, so the compiler marks this as an error.

You can change the lambda to:

    lambda: |-
      bool rc = false; // default return value is false

      if (id(ac_state).state && id(hrv_fan).state) {
        id(pausefan) = true;
        rc = true;
      }
      if (id(ac_state).state && id(pausefan)) {
        rc = true;
      }
      return rc;

Thank you, it worked