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.
(...)
That Addon includes an extension called Home Assistant Config Helper which validates the syntax of Home Assistant’s implementation of YAML.
In the case where multiple versions of syntax are valid, it won’t necessarily guide you to use the latest version. Therefore what you originally posted contains valid syntax but is not an example of the latest valid syntax (which seem to be the entire point of your resurrection of this topic that has been dormant for a year; to post an example with updated syntax).
The documentation remains the authority for the latest information.
Developer Tools / Actions (rather than States where I’ve been living all this time), search for Get forecasts, set Targets to your weather source, set Forecast type to Daily, Perform Action, gives something like this (clipped for today and tomorrow):
So min / max for humidity, wind_speed, uv_index are also available.
Maybe Weather - Home Assistant could do with an example like this for Forecast type = Daily? (yet another rabbit hole, I can see Edit is available - is this just a Wiki free for all?! Or Provide Feedback, this page has had one feedback that seems to have gone stale / ignored)
Anyway, done my bit for now, thanks for the pointer @Didgeridrew, hope someone finds these extras useful.