Sun Cover - swap %

Dears,

First of all thanks to whole community for excellent work and help I’ve been able to dine within this community all these years…
Now coming to my question: I’ve recently installed a sun cover in my backyard… using a Shelly 2.5 as controller.
Everything is configured properly, but I have a question on the Lovelace cover template.
Long story short, I would like to have this setting:

  • Cover status “open” ( cover fully extended) → 100% as position.

  • Cover status “closed” ( cover fully retracted) → 0% as position.

Currently with default Lovelace template config I can only have:

Fully open cover with 0% as position (while even swapping Shelly controls and reverse direction is not providing desired setup).

Any help here from your side?
Sorry in advance if it’s a silly question but I have not found any solution navigating the forum…

Thanks!!

Heavily debated here: WHY THE HECK can't we freely configure a Cover to interpret its percentage value as "percentage open" or "percentage closed"?.

Or make your own template cover to invert the logic.

Thanks @parautenbach for your reply, I already went through that topic, but unfortunately not found useful takeaway.

Indeed I’ve also tried a custom template for cover, but I’m not getting the correct status I want:

Cover status “Closed” ( cover fully retracted) → 0 as position → Slider at 0%
Cover status “Open” for any position >0 (cover partially extended) → Slider at correct %
Cover status “Open” ( cover fully extended) → 100% as position → Slider at 100%

Is anyone able to assist me on the custom template coding?
Thanks in advance!

Don’t have such a sensor, but here is a start from the top of my head

binary_sensor:
  - name: cover_status
    state: >
      {% set shelly_value = states('sensor.shelly_status') %}
      {% if (shelly_value == 'Open' ) %} Close
      {% else %} Open
      {% endif %}
    icon: >
      {% if is_state("binary_sensor.cover_status", "Open") %}
        mdi:open-icon
      {% else %}
        mdi:cl;ose-icon
      {% endif %}

thanks @rekenaar !

let me try to share some pics to better describe the situation…
with below custom code:

cover:
- platform: template
  covers:
    tendina:
      friendly_name: Tendina
      unique_id: Tendina_Giardino
      position_template: "{{ 100 - (state_attr('cover.tenda', 'current_position') | int) }}"
      open_cover:
        service: cover.close_cover
        data:
          entity_id: cover.tenda
      close_cover:
        service: cover.open_cover
        data:
          entity_id: cover.tenda
      stop_cover:
        service: cover.stop_cover
        data:
          entity_id: cover.tenda
      set_cover_position:
        service: cover.set_cover_position
        data:
          entity_id: cover.tenda
          position: "{{ position }}"

I’m getting below result which is almost ok, but I would like to see “open at 90%
It’s an awning so to be fully extender shoud be 100%, while closed 0%…
but I cannot obtain that result unfortunately :frowning:

thanks again!

My bad, did not fully understand the problem, probably since I do not have such.

I saw someone else also inverting the position, other than that, won’t be able to assist further

        set_cover_position:
          service: cover.set_cover_position
          data_template:
            entity_id: cover.kitchen_blind_2_hidden
            position: >
              {{100 - position}}

Here is my inverted awning:

cover:
  - platform: template
    covers:
      patiocover_manual:
        friendly_name: "Terrasscherm handmatig"
        position_template: "{{ 100 - state_attr('cover.zonnescherm_level', 'current_position')|int(default=100) }}"
        open_cover:
          - service: cover.close_cover
            entity_id: cover.zonnescherm_level
        close_cover:
          - service: cover.close_cover
            entity_id: cover.zonnescherm_level
        set_cover_position:
          - service: cover.set_cover_position
            data:
              entity_id: cover.zonnescherm_level
              position: "{{ 100 - position|int(default=0) }}"
        stop_cover:
          - service: cover.stop_cover
            entity_id: cover.zonnescherm_level

thank you @Emphyrio , pretty similar to my custom entity, but indeed with same issue…
in this example I have the “open” and “closed” status still wrong…
and open % still wrong (opposite)… :frowning:
In the setup I’m trying to get, a fully extended awning should be 100% - Open… while with above code still shown like below pic:

image

What does your entity show when you look it up in Development Tools > States ?
This is mine, when the awning is fully extended / open:


The current position is 100. So this seems to be what you are looking for. I am not using a Shelly though, this is a Z-wave module.

Some modules have an internal option to invert the direction. Perhaps Shelly has this too?
Edit: another link here.

1 Like

Yes, this was actually the link I was looking for but couldn’t find.

Hello @Jpsy you described exactly the issue I’m facing… and apparently still not able to have the correct percentage and slider “in sync” with our logic when considering an awning opening :smiley:
Based on your last statement seems no solution yet, correct?
in the meantime thanks a ton for your help and exaustive reply!

Yepp. Currently you’ll get the voice assistants covered nicely, but the dashboard entities either show a wrong percentage or an unintuitive slider.