Cover Template open/close

I am using:

cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
          service: script.pulse_gate
        close_cover:
          service: script.pulse_gate

With:

pulse_gate:
  alias: pulse_gate
  sequence:
  - service: switch.turn_on
    data: {}
    entity_id: switch.tuin_v_poort_e1_schakelaar_1188
  - delay: '1'
  - service: switch.turn_off
    data: {}
    entity_id: switch.tuin_v_poort_e1_schakelaar_1188
  mode: single
  icon: mdi:gate

resulting in:
image

This works well in usage!

But I cannot use this in an automation.

If I do call a service t open cover or close a cover it can easily do the opposite.

So if the cover is closed, If I open it, it opens. But if is already open and I call service to open it closes!
this way it is not reliable in an automation (or in node-red).

What is wrong with this behavior? Did I miss any setting?

You probably need to adapt yours like I have mine; only open the cover if the current status is closed, and vice versa.

        open_cover:
          service_template: >
            {% if is_state('cover.garage_door', 'closed') %}
              cover.open_cover
            {% else %}
              script.do_nothing
            {% endif %}
          entity_id: cover.left_garage
        close_cover:
          service_template: >
            {% if is_state('cover.garage_door', 'open') %}
              cover.close_cover
            {% else %}
              script.do_nothing
            {% endif %}

Mine was more of a security concern. You could tell Google Assistant to ‘close the garage door’ when it was closed, to make it open without a security pin. Pretty bad if someone decides to tell the GA speaker to do that whilst you are out.

1 Like

Thank you. I have to look in.

What I find strange is that when the “cover” is already closed/opened" and I call service to close/open I would expect no action when the state is already the same.

Is that a correct assumption?!

Unfortunately not, no.

HA does not check whether something is already open or not, it just runs the command. For items that use the same button for open and close, this will actually toggle the state incorrectly.

The above, will filter out that behavior.

Ok, lost…

I am not good in scripting and I do not fully understand what I am doing… I tried to make:

cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
		  service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'closed') %}
              script.pulse_gate
            {% else %}
              script.do_nothing
            {% endif %}
        close_cover:
          service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'open') %}
              script.pulse_gate
            {% else %}
              script.do_nothing
            {% endif %}

But this is not correct?

What is this code part of? Of the cover or a script?

This gives an error:

cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
          service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'closed') %}
              cover.open_cover
            {% else %}
              script.do_nothing
            {% endif %}
#          entity_id: cover.left_garage
        close_cover:
          service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'open') %}
              cover.close_cover
            {% else %}
              script.do_nothing
            {% endif %}

Cover is real-life open but shows closed then. When trying to open:
Error:
image

EDIT:
This gets rid of the error but no response when pressing button. And state not correct…

cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
          service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'closed') %}
              cover.open_cover
            {% else %}
              script.do_nothing
            {% endif %}
          entity_id: cover.tuin_voor_poort_cover
        close_cover:
          service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'open') %}
              cover.close_cover
            {% else %}
              script.do_nothing
            {% endif %}

You can’t open a cover from itself, its a circular reference. You need to incorporate my script above for your use case. It should be something like,

cover:
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.tuin_v_poort_sensor_956', 'on') }}"
        open_cover:
          service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'closed') %}
              script.pulse_gate
            {% else %}
              script.do_nothing
            {% endif %}
        close_cover:
          service_template: >
            {% if is_state('cover.tuin_voor_poort_cover', 'open') %}
              script.pulse_gate
            {% else %}
              script.do_nothing
            {% endif %}

You also need a script called do_nothing, with nothing in it, or it will also cause an error when you run it.

2 Likes

I think I have it running!

So cool…!

Thank you!

1 Like

4 years later…

Change service to action and it works again.

Ok still something wrong:

Logger: homeassistant.helpers.config_validation
Source: helpers/config_validation.py:1200
First occurred: 20:37:52 (1 occurrences)
Last logged: 20:37:52

The cover integration does not support any configuration parameters, got [{‘platform’: ‘template’, ‘covers’: {‘tuin_voor_poort_cover’: {‘device_class’: ‘gate’, ‘friendly_name’: ‘Tuin Poort’, ‘value_template’: “{{ is_state(‘binary_sensor.door_windows_sensor_blauwe_hekje’, ‘on’) }}”, ‘open_cover’: {‘action’: “{% if is_state(‘cover.tuin_voor_poort_cover’, ‘closed’) %}\n script.pulse_open_gate\n{% else %}\n script.do_nothing\n{% endif %}\n”}, ‘close_cover’: {‘action’: “{% if is_state(‘cover.tuin_voor_poort_cover’, ‘open’) %}\n script.pulse_close_gate\n{% else %}\n script.do_nothing\n{% endif %}”}}}}]. Please remove the configuration parameters from your configuration.

Trying this for a few days:

#OLD
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.door_windows_sensor_blauwe_hekje', 'on') }}"
        open_cover:
          action: >
            {% if is_state('cover.tuin_voor_poort_cover', 'closed') %}
              script.pulse_open_gate
            {% else %}
              script.do_nothing
            {% endif %}
        close_cover:
          action: >
            {% if is_state('cover.tuin_voor_poort_cover', 'open') %}
              script.pulse_close_gate
            {% else %}
              script.do_nothing
            {% endif %}	
			
#NEW
  - platform: template
    covers:
      tuin_voor_poort_cover:
        device_class: gate
        friendly_name: "Tuin Poort"
        value_template: "{{ is_state('binary_sensor.door_windows_sensor_blauwe_hekje', 'on') }}"
        open_cover:
          action: script.pulse_open_gate
        close_cover:
          action: script.pulse_close_gate