Increment shutter/cover position

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.

Automation action:

service: cover.set_cover_position
target:
  entity_id: cover.shelly_office
data:
  position: >-
    {{ [[state_attr("cover.shelly_office", "current_position") + 1, 0] | max, 100] | min }}

Error:

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?

it was a very little yaml syntax problem. without the hyphen after ‘>’ it works:

service: cover.set_cover_position
target:
  entity_id: cover.shelly_office
data:
  position: >
    {{ [[state_attr("cover.shelly_office", "current_position") + 1, 0] | max, 100] | min }}

“Hyphen: No newline at end (strip)”
So it looks like home assistant needs newline.

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 string 3 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).

The same is true without the newline.

Hi @keilr

thanks for this.

I want to know for decrement would it be the following:

data:
  position: <
    {{ [[state_attr("cover.shelly_office", "current_position") - 1, 100] | max, 0] | min }}