The forecast attribute was deprecated more than 7 months ago. In order to get that information you must use the weather.get_forecasts service if the weather integration you use has not updated to provide the sensors you want.
For Met.no you can use the following:
template:
- trigger:
- platform: time_pattern
hours: /1
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
target:
entity_id: weather.home
data:
type: daily
response_variable: result
sensor:
- name: Temperatur Morgen
unique_id: max_temperatur_morgen
device_class: temperature
unit_of_measurement: °C
state: >
{{ result['weather.home'].forecast[1]['temperature'] }}
- name: Temperatur Heute
unique_id: max_temperatur_heute
device_class: temperature
unit_of_measurement: °C
state: >
{{ result['weather.home'].forecast[0]['temperature'] }}
Note that trigger-based template sensors need to be configured under the template integration, not under the sensor integration like your previous sensors. If you simply copy paste the above configuration into sensors.yaml, it will not work.
Thank you very much for your help.
The script already looks great.
But I still have a small problem integrating the script into my conf. I’m not sure how to position it. If I simply paste it in, my config reports an error.
All your state-based sensors can be a single “item” in the list, the trigger-based sensor will be another “item”. You use hyphens to indicate the start of the configuration for each item in the list of template entities:
template:
- trigger:
- platform: time_pattern
hours: /1
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
target:
entity_id: weather.home
data:
type: daily
response_variable: result
sensor:
- name: Temperatur Morgen
unique_id: max_temperatur_morgen
device_class: temperature
unit_of_measurement: °C
state: >
{{ result['weather.home'].forecast[1]['temperature'] }}
- name: Temperatur Heute
unique_id: max_temperatur_heute
device_class: temperature
unit_of_measurement: °C
state: >
{{ result['weather.home'].forecast[0]['temperature'] }}
- sensor:
- name: Heizung Esszimmer Temperatursensor
state: "{{state_attr('climate.smart_thermostat_2109301685957490857248e1e978bea9','current_temperature')}}"
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
#Make sure to indent the rest of your state-based sensors so they line up with Heizung Esszimmer Temperatursensor above.
#If you have other domain template entities like binary sensors, their block will need a hyphen too.
(...)