Cover set_position

I would like to set the cover position depending on the current_position. I struggle to format correctly the code.

domain: cover
entity_id: cover.rho1_cover
type: set_position
position: >-
{% if state_attr('cover.rho1_cover', 'current_position') | int == 100 %}
            0
          {% else %}
             100
          {% endif %}

My code here doesn’t work, pretty sure is the formatting

Here is what I do sometimes…Goto the UI->Developer Tools->Services
then select the service, in this case: cover.set_cover_position.
Then goto “UI Mode” where it will help provide the needed information that you can fill out, like selecting your entity and position value, then go back to “YAML Mode”.
It will show you something like the following:

service: cover.set_cover_position
data:
  position: 51
target:
  entity_id: cover.bonus_room_blinds

I haven’t used set_cover_position before, but I think the following template will work for you…

Since you want to use a template for the position, you would probably use position_template instead. The template may look something like:

position_template: >-
  {% if  is_state_attr('cover.rho1_cover', 'current_position', 100) %}
    0
  {%- else -%}
    100
  {%- endif %}
1 Like

When I try with the developper tools I get:
Failed to call service cover/set_cover_position. expected int for dictionary value @ data[‘position’]

So it seems it doesn’t recognize the 0 or 100 as int ? I also tried with position_template, it says extra keys not allowed on position_template

entity_id: cover.rho1_cover
position: >-
  {% if  is_state_attr('cover.rho1_cover', 'current_position', 100) %}
      0
    {%- else -%}
      100
    {%- endif %}

In developer tools: States
When you put in entity: cover.rho1_cover
What does the state attributes say?

My Zigbee controller says this:

current_position: 100
calibration: 'OFF'
calibration_time: 38.3
linkquality: 231
motor_reversal: 'ON'
moving: STOP
position: 100
friendly_name: Zonwering Woonkamer
supported_features: 15
1 Like

developper: State for rho1_cover:
State: open

current_position: 4
friendly_name: Store chambre
supported_features: 15
device_class: shade

I made it work, changing the domain:cover and type: set_position to a call service as below.

service: cover.set_cover_position
    entity_id: cover.rho1_cover
    data:
      position: |-
        {% if is_state_attr('cover.rho1_cover', 'current_position', 100) %}
        0
        {% else %}
        100
        {% endif %}
1 Like

Is it possible to give a cover a standard maximum opening for like 80% ?