I’m trying to increment/decrement the position of my shutter. Position needs to be between 0 (closed) and 100 (fully open). Unfortunately there isn’t a cover increment/step service so I tried to accomplish this by using jinja template. The template itself works as expected within the dev tools (template editor) but doesn’t work in the automation action.
Jun 26 10:20:59 home-assistant hass[28120]: File "./homeassistant/lib/python3.8/site-packages/homeassistant/helpers/config_validation.py", line 142, in validate
Jun 26 10:20:59 home-assistant hass[28120]: raise vol.Invalid("must contain at least one of {}.".format(", ".join(keys)))
Jun 26 10:20:59 home-assistant hass[28120]: TypeError: sequence item 0: expected str instance, Optional found
Isn’t it possible to use templates inside actions? How can I increment the position of a cover/shutter?
That’s unlikely. If it were true it would represent a bug unique to the cover.set_cover_position service call.
Home Assistant converts the template’s output to a typed value (i.e. it infers the value’s type based on its appearance). The presence/absence of a terminating newline has no bearing on the inference. In other words, if the template’s result is the string3 it won’t matter if it does/doesn’t have a terminating newline because the string value is converted to an integer.
In the following screenshot, notice how a string containing 3 and whitespace, concatenated with a newline, results in a value whose type is integer (number).