Hi all - this template thing, with embedded actions and the need to use this to extract weather forecast data, is beyond my limits it appears. I have looked through threads I found on this, tried many things, even involved ChatGPT, but I need more help.
What I want to do is make this template definition work (configuration.yaml), so that I get a numer in dwd_echt_templow:
template:
- trigger:
- platform: time
at: "00:00:00"
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
action:
- service: weather.get_forecast
target:
entity_id: weather.stuttgart_echt_stuttgart_echt_2
data:
type: daily
response_variable: daily_forecast
sensor:
- name: dwd_echt_datetime
state: "{{ daily_forecast['weather.stuttgart_echt_stuttgart_echt_2'].forecast[0].datetime }}"
- name: dwd_echt_temperature
state: "{{ daily_forecast['weather.stuttgart_echt_stuttgart_echt_2'].forecast[0].temperature }}"
- name: dwd_echt_templow
state: "{{ daily_forecast['weather.stuttgart_echt_stuttgart_echt_2'].forecast[0].templow }}"
binary_sensor:
- name: dwd_echt_needheating
state: "{{ daily_forecast['weather.stuttgart_echt_stuttgart_echt_2'].forecast[0].templow < 10 }}"
Running the get_forecast() action manually gives me this output:
weather.stuttgart_echt_stuttgart_echt_2:
forecast:
- datetime: "2024-09-16T00:00:00Z"
condition: rainy
wind_bearing: NW
wind_gust_speed: 25.9
uv_index: 1
precipitation_probability: 73
temperature: 13
templow: 9
wind_speed: 14.8
precipitation: 4.9
- datetime: "2024-09-17T00:00:00Z"
condition: rainy
wind_bearing: SO
wind_gust_speed: 27.8
uv_index: 2
precipitation_probability: 62
temperature: 17
templow: 12
wind_speed: 14.8
precipitation: 3.5
(and so on)
I managed to make this work in the Dev-tools template editor:
{% set daily_forecast =
{
"weather.stuttgart_echt_stuttgart_echt_2": {
"forecast": [
{
"datetime": "2024-09-16T00:00:00Z",
"condition": "rainy",
"wind_bearing": "NW",
"wind_gust_speed": 25.9,
"uv_index": 1,
"precipitation_probability": 73,
"temperature": 13,
"templow": 9,
"wind_speed": 14.8,
"precipitation": 4.9
},
{
"datetime": "2024-09-17T00:00:00Z",
"condition": "rainy",
"wind_bearing": "SO",
"wind_gust_speed": 27.8,
"uv_index": 2,
"precipitation_probability": 62,
"temperature": 17,
"templow": 12,
"wind_speed": 14.8,
"precipitation": 3.5
},
]
}
}
%}
{{ daily_forecast['weather.stuttgart_echt_stuttgart_echt_2'].forecast[0].templow }}
But when I try to make this work in configuration.yaml (see above), I don’t get any data in the sensors I’m defining there.
What am I missing? Any help would be really appreciated!