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";
            ]]]