Custom button card that will open curtains on 60%

Hi!
I have an entity cover.curtain_controller with state (open | closed) and attribute current_position.
Attribute current_position can take value from 1 to 100.
How to correctly define tap_action on the buton to set current_position attribute to 60?

I’d suggest that you create and trigger a script with the action cover.set_cover_position

Or you could use the custom card shutter-row, if you have enough space, and use multiple predefined positions.

Thanks! Will dig into scripts. I thought there is an easy way with tap_action.

- action: cover.set_cover_position
  entity: cover.xxx
  data:
    position: 60

From within a button:

- type: button
  name: 'set shade to 60%'
  tap_action:
    action: perform-action
    perform_action: cover.set_cover_position
    entity: cover.xxx
    data:
      position: 60
1 Like

I normally use a script, mainly because it allows me to carry out the same (set of) action(s) from different ā€˜triggers’, e.g. a widget on my Android screen, a physical button, another automation, and I only have to adjust the ā€˜position value’ in one place.

1 Like

I’ve just made a script and it works perfectly.
Now I’m trying to figureout how to read current_position value and if the value == 60 change the background.

I thought about something like…

styles:
  icon:
    - width: 26px
    - color: >-
        {% if state_attr('cover.curtain_controller', 'current_position') == 60}
          return "rgb(186, 216, 182)";
        {% else %}
          return "rgb(146, 200, 102)";
        {% endif %}

But it doesn’t work.

The code you’ve posted is a mix of broken jinja (there’s a missing %) and javascript. Assuming you’re using button card, you use javascript-only, surrounded by ā€œ[[[ā€ and ā€œ]]]ā€ (see here). There’s an example of setting icon color included.

1 Like

Thanks @michaelblight !
Got the proper code

    styles:
      icon:
        - width: 26px
        - color: |
            [[[
              if (entity.attributes.current_position == 60)
                return "red";
              else
                return "green";
            ]]]