Error in Lambda using HA sensor

I am trying to use a HA sensor value within ESPHome.

I am obviously missing something here - any help appreciated :slight_smile: Thank you!

sensor:
  - platform: homeassistant
    entity_id: sensor.solcast_pv_forecast_forecast_today
    id: energy_prediction_today

time:
- platform: homeassistant
  id: hatime
  timezone: NZST-12NZDT,M9.5.0,M4.1.0/3

  on_time:
      - seconds: 0
        minutes: 0
        hours: 6
        then:
          - if:
              condition:
                lambda: 'return id(energy_prediction_today)  > 40.0;'        
              then:
                - logger.log: "lambda is true"

Error:

/config/esphome/hwc-monitor.yaml: In lambda function:
/config/esphome/hwc-monitor.yaml:396:41: error: expected primary-expression before 'float'
  396 |                 lambda: 'return (id(energy_prediction_today) | float ) > 40.0;'
      |                                         ^~~~~
/config/esphome/hwc-monitor.yaml:396:40: error: expected ')' before 'float'
  396 |                 lambda: 'return (id(energy_prediction_today) | float ) > 40.0;'
      |                                        ^~~~~~
      |                                        )
*** [.pioenvs/hwc-monitor/src/main.cpp.o] Error 1

I’m not an ESPHome expert, but I think you just need to tell it to retrieve the state:

...
lambda: "return id(energy_prediction_today).state  > 40.0;"
....

Thank you! Did not see that for looking….