Cover completely reverse/invert

Probably won’t be able to help, but I’m also just curious: can you share screenshots of the buttons when the cover is all the way open, half open, and all the way closed? As well as describe the difference between what is being shown and what you expect?

I come to the following conclusion:
the buttons of the template cover do no work good.
the slider works but I think it is not working on 0 and 100. thus only 1-99
using the buttons in the template cover does nothing… in the template cover. the realcover does move opposite though.
When I open the cover with the template cover it closed the realcover (as expected) but the slider of the templatecover does not change?

Why the heck is this so frikking complex? Just to turn around up and down in a cover!?!

You’re inverting hardware functionality, it’s going to be complex. If you didn’t have the slider, this would have been already done.

Add the value template back and set it to

        value_template: "{{ (100 - state_attr('cover.realcover_r', 'position')) > 95 }}"

As for the moving of the slider position, that will only update if your cover.realcover_r updates the position when you open and close it.

then the template cover in unavailable


Logger: homeassistant.helpers.event
Source: helpers/template.py:400
First occurred: 18:38:52 (2 occurrences)
Last logged: 18:38:52

Error while processing template: Template("{{ (100 - state_attr('cover.realcover_r', 'position')) > 95 }}")
Error while processing template: Template("{{ 100 - state_attr('cover.realcover_r', 'position') }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 398, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1698, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 514, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 400, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'

look in your logs and look for an error, I’m assuming you messed up the indentation and the error will point that out. Or you possibly deleted a character somewhere.

if the template itself is erroring, then safety needs to be built in

value_template: "{{ (100 - state_attr('cover.realcover_r', 'position') | int(100)) > 95 }}"
Logger: homeassistant.helpers.event
Source: helpers/template.py:400
First occurred: 18:47:15 (1 occurrences)
Last logged: 18:47:15

Error while processing template: Template("{{ 100 - state_attr('cover.realcover_r', 'position') }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 398, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1698, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 514, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 400, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:73
Integration: Template (documentation, issues)
First occurred: 18:47:15 (1 occurrences)
Last logged: 18:47:15

TemplateError('TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'') while processing template 'Template("{{ 100 - state_attr('cover.realcover_r', 'position') }}")' for attribute '_position' in entity 'cover.r_reversed'

that error is referring to the other template, which is why the position was never getting updated when you turn it on or off.

change to

        position_template: "{{ 100 - state_attr('cover.realcover_r', 'position') | int(100) }}"

No more error.

Now template cover buttons dont work.

Ah… think the buttons do work but slider and buttons in template cover is not updated…

that means your cover that you’re inverting does not have a slider… Does it have a slider?

yes for sure

post a picture of the cover in dev tools → states with the slider all the way open, and all the way closed. Make sure to include the attributes. Not the template slider, the slider you are trying to invert.

should “position” be “current_postition” in the code?

Yes if that’s the name of the attribute

I think that’s it… :see_no_evil: :sweat_smile:

The working code for the archive:

  - platform: template
    covers:
      cover_r_reversed:
        friendly_name: "Cover R Reversed"
        position_template: "{{ 100 - state_attr('cover.realcover_r', 'current_position') | int(100) }}"
        value_template: "{{ (100 - state_attr('cover.realcover_r', 'current_position') | int(100)) > 95 }}"
        open_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.realcover_r
        close_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.realcover_r
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: cover.realcover_r
        set_cover_position:
          service: cover.set_cover_position
          data:
            position: "{{100-position}}"
            entity_id: cover.realcover_r
        icon_template: >-
          {% if is_state('cover.realcover_r', 'closed') %}
            mdi:blinds-open
          {% else %}
            mdi:blinds
          {% endif %}

one more question about this… whats the 95 in value_template: "{{ (100 - state_attr('cover.realcover_r', 'current_position') | int(100)) > 95 }}" for?

3 Likes

Well, anything over 95 on the slider will consider it open

EDIT: You can remove that now probably. I added it based on your previous comments but it turns out the attribute was just wrong.

liket his:
value_template: "{{ (100 - state_attr('cover.realcover_r', 'current_position') | int(100)) }}"

?

no remove the whole line

  - platform: template
    covers:
      cover_r_reversed:
        friendly_name: "Cover R Reversed"
        position_template: "{{ 100 - state_attr('cover.realcover_r', 'current_position') | int(100) }}"
        open_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.realcover_r
        close_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.realcover_r
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: cover.realcover_r
        set_cover_position:
          service: cover.set_cover_position
          data:
            position: "{{100-position}}"
            entity_id: cover.realcover_r
        icon_template: >-
          {% if is_state('cover.realcover_r', 'closed') %}
            mdi:blinds-open
          {% else %}
            mdi:blinds
          {% endif %}
4 Likes