A script that returns the forcasted outside temperature

I am trying to make a script which you input hour as a field and it would return the forecasted outside temperature.
I am not an expert in HA, I found a template:

{{ state_attr(‘weather.home’, ‘forecast’)[2].temperature }}

I suppose this can me parametic-ized but I could not figure where to put it. I would appreciate if someone could point me the direction.
Thanks up front!

something like this and do note that weather.home no longer has forecast since 2024.4

{{ (state_attr('sensor.weather_something', 'forecast')|selectattr('datetime', 'eq', (today_at('18:00').astimezone(utcnow().tzinfo)).isoformat())|list|first).temperature }}

you only need to change the 15:00 by a input sensor

1 Like

thank you very much, if it will not be much of a trouble, can you also tell me where to put this? it is a rookie question I am sorry.

Use a template where you can use the above for ‘state’
For the 18:00 part you have have to refer to the state of a input helper, you can use input text and type in 18:00 there or an input number which you limit between 0 and 23.

Input Number - Home Assistant (home-assistant.io)

Template - Home Assistant (home-assistant.io)

Not sure if you progressed but here is some further help so I can close this off :slight_smile:
I will not explain how to organise template/sensor/etc. in yaml files (lots of other posts out there)… so for now I will assume you put this in configuration.yaml and restart HA.

The first bit is creating a sensor with hourly forecast values, using an existing (do check if you have that) weather entity weather.forecast_home, with me this is generated through the met.no integration but this could be any …just make sure the name is correct with your situation
The second part is creating a sensor that gets the forecasted value of that first sensor based on an input helper. I create a time-helper called input_datetime.time_for_weather_forecast…again…your choice on how you name this but jsut make sure they match below
In the end you have a sensor.weather_forecast_today_time which you can combine with the input helper to get the forecast at your choice today (!).

  - trigger:
      - platform: time_pattern
        minutes: /10
      - service: weather.get_forecasts
          type: hourly
          entity_id: weather.forecast_home
        response_variable: forecast
      - name: Weather Forecast Home Hourly
        unique_id: weather_forecast_home_hourly
        state: "{{ now().isoformat() }}"
          forecast: "{{ forecast['weather.forecast_home'].forecast }}"    

      - name: Weather Forecast Today Time
        unique_id: weather_forecast_today_time
        state: "{{ now().isoformat() }}"
          forecast: "{{ (state_attr('sensor.weather_forecast_hourly', 'forecast')|selectattr('datetime', 'eq', (today_at(states('input_datetime.time_for_weather_forecast')).astimezone(utcnow().tzinfo)).isoformat())|list|first).temperature }}"
1 Like

Thank you!