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
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.
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.
Thanks @michaelblight !
Got the proper code
styles:
icon:
- width: 26px
- color: |
[[[
if (entity.attributes.current_position == 60)
return "red";
else
return "green";
]]]