Trouble with exposing value via template sensor

Dear community of HomeAssistant experts!

I have been pulling my hair over this for hours now, but I can’t for the life of me get this to work.

My goal is to expose the likelihood of rain in the next hour in HA, pick it up via ESPHome, and display it on a small display. I think I am 99% there, but I struggle with getting the value correctly exposed via a template sensor. Here is my configuration:

template:
  - trigger:
      - trigger: time_pattern
        seconds: /30
      - trigger: homeassistant
        event: start
    action:
      - action: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.home
        response_variable: hourly_forecast
      - action: system_log.write
        data:
          message: "Sensor refresh triggered. Response could be evaluated to {{ hourly_forecast['weather.home'].forecast[0].precipitation_probability }}"
          level: debug
  - sensor:
      - name: "Rain Probability"
        unique_id: rain_probability
        state: "{{ now().isoformat() }}"
        attributes:
          precipitation_probability: "{{ hourly_forecast['weather.home'].forecast[0].precipitation_probability }}"

From my logs I can see that the action (weather.get_forecast) gets indeed triggered every 30 seconds. This high cadence is for testing only, though.

I can also see in my logs that I can access the actions response and properly evaluate the attribute. However, this seems to be limited to the scope of the action. When I try to access the response_variable (hourly_forecast) from within the sensor section, it always evaluates as ‘unavailable’.

I have been reading through docs and googling for a while, and I just don’t see what I am missing here. Any ideas?

Highly appreciate any hints and help!

Best,
Chris

Replace the - in front of sensor: with a space.

1 Like

Thank you so much, petro, for you quick response. That solved the issue. Highly appreciate your help!

Best,
Chris