Link cover position and input_number

Hello there,

The tile card with the cover-position feature is too bulky for my liking.
image

So I wanted to show just an input_number for all my covers.
image

I did an automation so when the input number change, the cover service to set_cover_position is called

description: ""
trigger:
  - platform: state
    entity_id:
      - input_number.position_volet_bureau_gauche
    id: bureau_gauche
  - platform: state
    entity_id:
      - input_number.position_volet_chambre_parents
    id: chambre_parents
[...]
condition: []
action:
  - service: cover.set_cover_position
    data:
      position: |
        {{ states('input_number.position_volet_' + trigger.id) }}
    target:
      entity_id: |
        {{ "cover." + trigger.id }}
mode: single

I like it so far, it is working as I wanted.

Here is the tricky part: it is also possible to use the remote of each cover.
And I’d like the input_number to reflect the position when it has change with the remote

But then I’m in a forever automation loop.
cover change → input_number change → cover change → …

How can I make one in sync with the other?

Use a condition to only perform the actions of the two values are different.

Good proposition but I’m still confused.

While the cover.set_cover_position is running, the current_position attribute is changing but not at the same pace.
It is taking a few seconds for the service to end and the current_position to update.

So, if someone is pushing the remote button, the current_position will become different than the input_number. This is your advise, right?

But the current_position will also be different than the input_number while the cover.set_cover_position is running.

I should maybe update the input_number when current_position did not change for a few seconds.

As the state remains open and only the attribute is updated, I’m wondering if I can use the last_updated or last_changed of

What I’ve done so far (in another automation, so I can re-use the trigger.id trick). It is working, you just have to wait for the next 1 minute and 15 seconds (maximum) for it to sync

description: ""
trigger:
  - platform: template
    value_template: >-
      {{ ( now()|as_timestamp() -
      states['cover.chambre_parents'].last_updated|default(0,true)|as_timestamp()|default(0,true))
      > 15 and 
         state_attr('cover.chambre_parents', 'current_position') | float(0) != states('input_number.position_volet_chambre_parents') | float(0) and
         ( now()|as_timestamp() - states['input_number.position_volet_chambre_parents'].last_updated|default(0,true)|as_timestamp()|default(0,true)) > 60 
      }}
    id: chambre_parents

[…]

condition: []
action:
  - service: input_number.set_value
    data:
      value: |
        {{ state_attr('cover.' + trigger.id, 'current_position') | int(100) }}
    target:
      entity_id: |
        {{ 'input_number.position_volet_' + trigger.id }}
mode: single

The 3 conditions are:

  • cover was not updated in the last 15 seconds (stable position)
  • attribute current_position is different than the input_number (out-of-sync)
  • input_number is updated for more than 60 seconds (explanation bellow)

The last condition is to avoid that moving the slider will reset it to the cover position value instantly.
That was generating a weird behavior of the cover, starting to move up then down or the opposite.