Hi,
I’m trying to create an automation for my cover entity based on an input_select change. The input_select exposes 4 modes and what I’m trying to do is match the position for each mode.
This is what I’ve tried:
And this is the error I get: 2023-02-04 12:51:33.686 ERROR (MainThread) [homeassistant.components.automation] Automation with alias 'Window Automation' could not be validated and has been disabled: template value should be a string for dictionary value @ data['action'][0]['data']. Got OrderedDict([('position', "{% if is_state(''input_select.window'', ''Open'') %} 100\n{% elif is_state(''input_select.window'', ''Half'') %} 65\n{% elif is_state(''input_select.window'', ''Sleep'') %} 35\n{% elif is_state(''input_select.window'', ''Close'') %} 5\n{% endif %}")])
still getting the same error.
Also, can you please explain how "{{ p.get(trigger.to_state.state, 5) }}" works? Would like to understand the syntax better…
The variable p is a dictionary containing keys (Open, Half, etc) with corresponding values (100, 65, etc).
trigger.to_state.state contains the value of of input_select.window that triggered the automation.
This template uses the value of trigger.to_state.state to find the matching key in the dictionary p. If it finds a matching key, it reports the key’s value. For example, if the key is Sleep it reports 35. If it can’t find a matching key, it reports its default value 5.