Hi,
I’m struggling here a bit with using automation condition that tests a state of a list item attribute based on Met.no weather forecast integration.
The goal is simple - turn on the garden sprinkler only if it’s not forecasted to rain the next day.
I’ve done some template debugging in the Developer Tools and it all seems to work well there, but whatever I try I can’t make it work as an automation condition.
These are the state attributes for my weather.home
entity:
temperature: 22.7
humidity: 52
pressure: 1018.5
wind_bearing: 128.6
wind_speed: 2.9
forecast:
- condition: partlycloudy
precipitation: 0.4
temperature: 23.5
templow: 11
datetime: '2022-06-16T11:00:00+00:00'
wind_bearing: 176
wind_speed: 12.2
- condition: sunny
precipitation: 0
temperature: 26.3
templow: 13
datetime: '2022-06-17T11:00:00+00:00'
wind_bearing: 197.7
wind_speed: 20.5
- condition: cloudy
precipitation: 3
temperature: 27.2
templow: 17.5
datetime: '2022-06-18T11:00:00+00:00'
wind_bearing: 64
wind_speed: 23
- condition: partlycloudy
precipitation: 6.2
temperature: 15.9
templow: 10.9
datetime: '2022-06-19T11:00:00+00:00'
wind_bearing: 42.5
wind_speed: 26.3
- condition: partlycloudy
precipitation: 0
temperature: 19.3
templow: 11.8
datetime: '2022-06-20T11:00:00+00:00'
wind_bearing: 56.5
wind_speed: 18
attribution: >-
Weather forecast from met.no, delivered by the Norwegian Meteorological
Institute.
If I use State type automation condition for the current day using just the entity’s state, everything works fine:
condition: state
entity_id: weather.home
state: sunny
If I however want to use tomorrow or any subsequent days, I can’t make it work, whatever I use getting into lists and their attributes.
I’ve tested this template in Developer Tools for tomorrow’s forecast. It correctly returns true:
{{ state_attr('weather.home', 'forecast')[0].condition != 'rainy' }}
If I try to use the same template in the Automation Condition type Template:
condition: template
value_template: >-
"{{ state_attr('weather.home', 'forecast')[0].condition !=
'rainy' }}"
I receive the error:
template value should be a string for dictionary value @ data[‘value_template’]. Got None
With or without double quotes, I’ve tried various brackets at various places, it never works.
I’ve also tested these two templates in Developer Tools for tomorrow’s forecast. Both correctly return partlycloudy :
{{ states.weather.home.attributes.forecast[0].condition }}
{{ state_attr('weather.home','forecast')[0].condition }}
If I try to use State type condition with the list attribute as:
condition: state
entity_id: weather.home
attribute: forecast[0].condition
state: 'partlycloudy'
It always returns false, despite that list index state being 'partlycloudy'
Any ideas what I’m doing wrong?
Thanks