Please post code in the topic rather than via a link.
You’re doing this:
conditions:
- condition: numeric_state
entity_id: sensor.openweathermap_temperature
above: 50
- condition: numeric_state
entity_id: sensor.openweathermap_wind_speed
below: 15
- condition: template
value_template: |
{% set rain_in_3_days = daily_forecast['weather.openweathermap'][:3]
| selectattr('precipitation', 'defined')
| selectattr('precipitation', '>', 0)
| list %}
{{ rain_in_3_days | length == 0 }}
actions:
- alias: Get forecast for the next 3 days
data:
type: daily
target:
entity_id: weather.openweathermap
response_variable: daily_forecast
action: weather.get_forecasts
The problem here is that you’re trying to refer to the daily_forecast variable in your third condition, which is before it exists, and outside the scope in which it will later exist.
Solution options are:
- Create a template sensor that contains the forecast and refer to that in the condition; or
- Move the condition test into the actions section after it’s been defined.
I’d go with the first option, as you can then use the forecast data elsewhere in your system.