Weather forecasts response variable undefined

Hey!!

I’ve been trying to get the data from weather.get_forecasts but have been unable to.

I can can sucessfully the service and it returns the data.

However if i try to use this data inside a template, it doesn’t seem that the response variable is being populated.

This is my template:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.home
        response_variable: hourly
    sensor:
      - name: Temperature forecast next hour
        unique_id: temperature_forecast_next_hour
        state: "{{ hourly['weather.home'].forecast[0].temperature }}"
        unit_of_measurement: °C

To which i’m getting UndefinedError: ‘hourly’ is undefined

Is there something wrong in my script?

Thanks

Are you testing this in the template editor? If yes, the error is correct, hourly is not defined because the only template in that is {{ hourly['weather.home'].forecast[0].temperature }}. The rest is yaml which is not jinja and yaml does not resolve in the template editor.

Yeah i was testing in the template editor.

I wasn’t aware than only the jinja would get evaluated.

Tested just the jinja there and added it to my automation and it worked.

Thanks!