Open only Closed Covers vice a versa

Hi all,

What I am looking for but couldn’t find is to open only closed covers or close only open covers. Right now, I am using open_cover services and use “entity: all” however this method triggers all covers whether they are open or not.

Can we say open only closed covers and do nothing for open ones?

action:
  - service: cover.open_cover
    target:
      entity_id: "{{ states.cover | selectattr('state','eq','closed') | map(attribute='entity_id') | list | join(', ') }}"

Thank you so much

This worked if I call from service tool on developer page however not working for button tap action.

Errorcode is

Failed to call service cover/close_cover. Templates are not supported here. Got {‘type’: ‘call_service’, ‘domain’: ‘cover’, ‘service’: ‘close_cover’, ‘target’: {‘entity_id’: Template("{{ states.cover | selectattr(‘state’,‘eq’,‘open’) | map(attribute=‘entity_id’) | list | join(’, ') }}")}, ‘service_data’: {}, ‘id’: 1155}

type: custom:mushroom-template-card
primary: CLOSE
secondary: All Shutters
icon: mdi:window-shutter
tap_action:
  action: call-service
  service: cover.close_cover
  data: {}
  target:
    entity_id: >-
      {{ states.cover | selectattr('state','eq','open') |
      map(attribute='entity_id') | list | join(', ') }}
badge_icon: mdi:arrow-down-bold
badge_color: red
fill_container: true
multiline_secondary: false
icon_color: white
layout: horizontal
card_mod:
  style: |
    ha-card {
      height: 73px !important;
      --icon-size: 48px;
    }

You can’t use templates in nearly all core dashboard cards.

Unless you use something like this:

The other option is to put the action in a script and call the script as the tap action.

Thank you so much. One last question. How can i say “open covers which are not open”

I mean it can be open, closed, closing, unavailable… etc

action:
  - service: cover.open_cover
    target:
      entity_id: "{{ states.cover | rejectattr('state','eq','open') | map(attribute='entity_id') | list | join(', ') }}"
2 Likes

Using the following to close any open garage doors at 1:30 am via Ratgdo.

alias: Close open GDOs at night
description: close at open garage doors late at night
trigger:
  - platform: time
    at: "01:30:00"
condition: []
action:
  - service: cover.close_cover
    target:
      entity_id: >-
        {{ states.cover | rejectattr('state','eq','closed') |
        map(attribute='entity_id') | list | join(', ') }}
    data: {}
mode: single