I’m really new to programming, both with YAML and CSS. I’ve been able to successfully code a few cards with similar situations, but for some reason can’t get this one to work. I’m not sure what the problem is. All I want is if the door is locked, for the border to turn green. Any other state (ie unlocked) and it should be red. But all I get is red, no matter what the state is. I’ve tried two different versions of the code, and got the same result with both of them. Can anyone see what the problem is?
Version 1:
cards:
- show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: lock.en_front_door_lock
style: |
:host {
--ha-card-border-color: {% if is_state('lock.en_front_door_lock', 'Locked') %} green {% else %} red {% endif %};
}
show_state: true
icon_height: 40px
name: Front Door
Version 2:
cards:
- show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: lock.en_front_door_lock
style: |
:host {
--ha-card-border-color:
{% set sensor = states('lock.en_front_door_lock') %}
{% if sensor == 'Locked' %}green
{% else %}red
{% endif %}
}
show_state: true
icon_height: 40px
name: Front Door