Cover completely reverse/invert

Thanks! Gone in 60 minutes - posts.

CU next time :-). Keep the spoon ready.

Thanks a lot to you both. Been using this thread to completely reverse buttons & positions in Home Assistant, for Tuya curtain modules that work fine, but display reversed status & position values in hass.io

I included all this in a “covers.yaml” file, and added just the include at the end of configuration.yaml:

cover: !include covers.yaml
1 Like

Hey everyone
When I try this, I get an error that “position is undefined”
I get that same error in the template editor if I paste in your version too.

My version:

      bedroom_large_left:
        friendly_name: "Bedroom Blinds Large Left"
        position_template: "{{ 100 - state_attr('cover.bedroom_blinds_c_left', 'current_position') | int(100) }}"
        value_template: "{{ (100 - state_attr('cover.bedroom_blinds_c_left', 'current_position') | int(100)) > 95 }}"
        open_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.bedroom_blinds_c_left
        close_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.bedroom_blinds_c_left
        set_cover_position:
          service: cover.set_cover_position
          data:
            position: "{{100-position}}"
            entity_id: cover.bedroom_blinds_c_left
        icon_template: >-
          {% if is_state('cover.bedroom_blinds_c_left', 'closed') %}
            mdi:blinds-open
          {% else %}
            mdi:blinds
          {% endif %}

You shouldn’t get that error in your configuration. You’ll get that error in the template editor area because position doesn’t exist in the template editor.

Your comment made YouTube. FINALLY! A CHEAP Zigbee SOLAR POWERED Smart Blind Motor - YouTube skip to 6:30

1 Like

Yep, I know.

1 Like

My “created” template code from above does not actually always work. E.g. when I have the cover half open and restart HA, It lost it’s state and I need to fully open or close it to reflect the actual state.

I admit: I am not a coder (templates). However I am a very enthusiastic HA user that like things working, even if that means I need to ask for help here.

Although I think, given the amount of questions and topics on templates, and especially this one, it is not easy at all.

1 Like

What’s the attribute current_position value at startup on cover.bedroom_blinds_c_left?

I have been playing with this for hours and I can’t make it work. My version does reverse the blind but I can’t restart HA, I always get the error:

The system cannot restart because the configuration is not valid: Error loading /config/configuration.yaml: mapping values are not allowed here in “/config/covers.yaml”, line 2, column 11

Here is mine (content of covers.yaml), it’s just a paste of the above but with my blind:

- platform: template
    covers: 
      dining_room_blind_reversed:
        friendly_name: "Dining room blind reversed"
        position_template: "{{ 100 - state_attr('cover.dining_room_blind_cover', 'current_position') | int(100) }}"
        open_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.dining_room_blind_cover
        close_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.dining_room_blind_cover
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: cover.dining_room_blind_cover
        set_cover_position:
          service: cover.set_cover_position
          data:
            position: "{{100-position}}"
            entity_id: cover.dining_room_blind_cover
        icon_template: >-
          {% if is_state('cover.dining_room_blind_cover', 'closed') %}
            mdi:blinds-open
          {% else %}
            mdi:blinds
          {% endif %}

I’m happy to have a bash at stuff but this is all new to me, I’m not a coder

  - platform: template
    covers: 
1 Like

Thank you. I can’t believe it’s that simple!

Thanks for the solution which is quite perfect in my case to swap the buttons.
However, it has a problem: it is based on the position_template.

I’m attaching a view of the normal and inverted (reversed) cover:

The reversed buttons and the icons are perfect with your solution, but I would like to invert also the slider percentage. I don’t think this is possible, right?

Just want to say that the solution provided worked perfectly for my tuya zigbee blinds, thanks! I got the blind motor installed and HA seeing the device with minimal effort, the only issue was HA showing the inverted state of the blinds and nothing I did could change it.

I think it helped that I didnt want the slider, just up and down.

How would I create the “opening” and “closing” status on this cover, independent of the original cover?

you can make a template binary sensor w/ device_class: door or opening

Sorry, I didn’t express myself well. If the question is simple, sorry,
I’m new to this, I’ll rephrase the question. I need the “opening” and “closing” statuses of the cover, but they are inverted. My code worked until a specific condition, resulting in the table below.

when the cover is fully closed and is operated to open. it physically opens, but the status remains “closed”. To adjust this I thought about creating the “opening” and “closing” status for “cover1 reversed” differently from the way I did it in my code. But I was unsuccessful.


Correct

set action cover1 (action) cover1 (status) cover1 reversed (action) cover1 reversed (status)
set open close closing open opening
set close open opening close closing

Correct:
current position cover1 (status) cover1 reversed (status)
0 closed closed
>0 open open

Error:
current position set_action physical motion cover1 (status) cover1 reversed (status)
0 (closed) set open opening closed closed
100 (open) set_close closing open open

  - platform: template
    covers:
      cover1_reversed:
        friendly_name: "Cover1 Reversed"
        position_template: "{{state_attr('cover.cover1', 'current_position') | int(100) }}"
        open_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.cover1
        close_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.cover1
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: cover.cover1
        set_cover_position:
          service: cover.set_cover_position
          data:
            position: "{{position}}"
            entity_id: cover.cover1
        value_template: >-
          {% if state_attr('cover.cover1', 'current_position') == 0 %}
            closed
          {% elif state_attr('cover.cover1', 'current_position') == 100 %}
            open
          {% elif is_state('cover.cover1', 'closed') %}
            closed
          {% elif is_state('cover.cover1', 'closing') %}
            opening
          {% elif is_state('cover.cover1', 'opening') %}
            closing
          {% else %}
            open
          {% endif %}
        icon_template: >-
          {% if state_attr('cover.cover1', 'current_position') == 0 %}
            mdi:roller-shade-closed
          {% elif state_attr('cover.cover1', 'current_position') == 100 %}
            mdi:blinds-open
          {% elif is_state('cover.cover1', 'closed') %}
            mdi:roller-shade-closed
          {% elif is_state('cover.cover1', 'closing') %}
            mdi:arow-up-box
          {% elif is_state('cover.cover1', 'opening') %}
            mdi:arow-down-box
          {% else %}
	        mdi:blinds-open
          {% endif %}


I was just doing something similar. The code below works for me with the caveat that for my use-case the active/inactive status would ideally not be reversed. I really wish that all of the logic for covers was in the back end rather than some of it living the front end.

cover:
- platform: template
  covers:
    cover_screen_reversed:
      friendly_name: "Screen Reversed"
      position_template: "{{ 100 - state_attr('cover.screen', 'current_position') | int(100) }}"
      value_template: >-
        {% if is_state('cover.screen', 'closing') %}
          opening
        {% elif is_state('cover.screen', 'opening') %}
          closing
        {% else %}
          none
        {% endif %}
      open_cover:
        service: cover.close_cover
        data: {}
        target:
          entity_id: cover.screen
      close_cover:
        service: cover.open_cover
        data: {}
        target:
          entity_id: cover.screen
      stop_cover:
        service: cover.stop_cover
        data: {}
        target:
          entity_id: cover.screen
      set_cover_position:
        service: cover.set_cover_position
        data:
          position: "{{100-position}}"
          entity_id: cover.screen
      icon_template: >-
        {% if is_state('cover.screen', 'closed') %}
          mdi:projector-screen-variant-off-outline
        {% elif is_state('cover.screen', 'closing') %}
          mdi:arrow-up-box
        {% elif is_state('cover.screen', 'opening') %}
          mdi:arrow-down-box
        {% else %}
          mdi:projector-screen-variant-outline
        {% endif %}

Hope that it makes sense to post this here - the forum is warning me that this thread is now closed but your post looks relatively recent.

Hello, sorry I´m new into this but I have been able to add the code and it started to work. But I have a problem. The code created me 2 devices in the control panel.
The issues is that as soon as I activate the first one (with your code) it start fine but 2 seconds later start the old device starts and change the direction.
Can you help me to undertand what I´m doing wrong?
image

thanks for ther solution… I have the same problem in tuya cloud connected shutters (on tuya app the buttons are fine)…Im worried that if I do coding for the buttons that tuya at some point fix it and now it will be a problem as Im doing automation to close the shutters automatically at midnight …now it will be opened wide open for any one at mid night…any permanent fix with tuya or something like that? why on the first place something like that happens?

there is another problem here as this automation even if I reverse the action…it randomly do the opposite