Template based on tomorrow's temperature

Hello, I want to create a sensor to further use it in automation. I need to get tomorrow’s temperature and I am almost in the end with

  • platform: template
    sensors:
    forecast_tomorrow:
    friendly_name: “Tomorrow temperature”
    unit_of_measurement: ‘C’
    value_template: “{{ state_attr(‘weather.domov’, ‘temperature’) }}”

The only thing I need to obtain temperature from tomorrow (forecast: temperature). As you can see below. How to substitute “temperature” then?
Snímek obrazovky 2021-07-06 v 21.15.40

You need to grab the forecast list, index into it, and grab the value of the temperature key:

{{ state_attr('weather.domov', 'forecast')[0].temperature }}

I have seen some changes in HA, looks like this method its not working anymore. Can someone explain where did i get wrong?
image

I have tried with the [0] also, same error.
image

You need to enclose the line with ".

value_template: "{{.....}}"

Not sure your .0. will work. I think it has to be as posted above in the thread.

1 Like

It’s actually a standard way to index JSON (it’s the same as [0]). I did a quick test and it works in the template editor.

1 Like

Oh! Thanks, i spend a lot of time trying do get it work, and it was just that. :slight_smile:

It’s #1 here: Templating - Home Assistant

I recommend checking out the others, too :slight_smile:

This has stopped working in 2024.4
Can’t figure out how to make a template with the newer weather service.

Any ideas/ suggestions?

where were you using it?

I created a template sensor in Yaml (although now it’s easier to do with helper)
It was like this :
“{{ state_attr(‘weather.home_gw’,‘forecast’).0.wind_speed }}”

It gave me the wind speed for tomorrow as a sensor. K had the same for tomorrow’s temperature. It was pretty convinent to have it. But now this doesn’t work anymore ? How can I create a template sensor now that shows me the value of tomorrow’s wind or temperature. ? Is it even possible with new changes ?

Thank you :slight_smile:

I had this as a TTS to give me the forecast for tomorrow in an evening report. Its not working now of course, how do I accomplish the same using the Weather: Get Forecasts service?

    Tomorrow, it is expected to be {{ state_attr("weather.home_2", "forecast")
    [1].temperature  }} and {{ state_attr("weather.home_2", "forecast")
    [1].condition  }}

post the full automation

Not much to see…
Here is the morning version:

alias: Downstairs Morning report
description: ""
trigger:
  - platform: state
    entity_id: input_boolean.wake_up_has_run
    to: "on"
    id: Start Timer
  - type: motion
    platform: device
    device_id: 027442816a2fcfca695ae32cef26fa84
    entity_id: binary_sensor.lumi_lumi_motion_ac02_iaszone
    domain: binary_sensor
    id: Run Report
  - platform: state
    entity_id:
      - binary_sensor.great_room_occupation
    to: "on"
    id: Run Report
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Start Timer
        sequence:
          - service: timer.start
            data:
              duration: "120"
            target:
              entity_id: timer.morning_report_timer
      - conditions:
          - condition: trigger
            id: Run Report
          - condition: state
            entity_id: timer.morning_report_timer
            state: active
        sequence:
          - service: script.simple_tts
            data:
              who: media_player.chromecast9871
              message: >-
                Good morning.  Currently outside it is {{
                states("weather.home_2")}} and  {{
                states("sensor.outside_temp_temperature")}} degrees. It is
                expected to be a high of {{ state_attr("weather.home_2",
                "forecast") [0].temperature  }} degrees and {{
                state_attr("weather.home_2", "forecast") [0].condition  }} . 
                Tomorrow, it is expected to be {{ state_attr("weather.home_2",
                "forecast") [1].temperature  }} and {{
                state_attr("weather.home_2", "forecast") [1].condition  }}
mode: single

          - service: weather.get_forecasts
            target:
              entity_id: "weather.home_2"
            data:
              type: daily
            response_variable: response
          - service: script.simple_tts
            data:
              who: media_player.chromecast9871
              message: >-
                Good morning.  Currently outside it is {{ states("weather.home_2")}} and {{  states("sensor.outside_temp_temperature")}} degrees. It is
                expected to be a high of {{ response["weather.home_2"].forecast[0].temperature }} degrees and {{ response["weather.home_2"].forecast[0].condition }}. 
                Tomorrow, it is expected to be {{ response["weather.home_2"].forecast[1].temperature }} and {{ response["weather.home_2"].forecast[1].condition }}.

awesome, Thanks.
Much simpler than I was thinking it was.