How to limit value template?

Yes you can.

  position: >
    {{ [ 0, [state_attr('cover.sun_screen', 'position') | int +
        trigger.payload_json.action_angle | int / 2,
        100] | min ] | max }}

However there is a smarter way.

  position: >
      {{ ([0, state_attr('cover.sun_screen', 'position') | int, 100]|sort)[1] }}

This sorts the list of your position, 0 and 100 in increasing order and picks the middle value.

Kudos to 123 for sharing this idea.

2 Likes