Hallo zusammen,
ich würde gerne den Fensterzustand (offen, gekippt und geschlossen) in einer Button Card darstellen. Ich verwende einen binary_sensor für offen und geschlossen und einen Template Sensor für den gekippten Zustand.
Um die beiden Sensoren in der Button Card zu verwenden,benutze ich Variablen. Leider klappt die Variable nicht in der if- Gleichung. Um Farbe, Icon und Text zu ändern.
Dies schein das Problem zu sein:
{% elif states('[[[ return "sensor.fenster_" + variables.geraet_entity_name + "_gekippt" ]]]') == '1' %}
Hier der Code:
type: custom:button-card
entity: binary_sensor.fenster_gastezimmer
variables:
geraet_name: |-
[[[ return `${entity.attributes.friendly_name.replace("Fenster","")}`
]]]
geraet_entity_name: >-
[[[ return
`${entity.entity_id.replace("","").replace("binary_sensor.fenster_","")}`
]]]
device_power_entity: '[[[ return `${entity.entity_id.replace("_kwh_daily","_leistung")}` ]]]'
device_entity_icon: '[[[ return `${entity.entity_id.replace("","")}` ]]]'
show_name: false
show_state: false
show_icon: false
styles:
card:
- padding: 3px
- background: none
- border: none
- box-shadow: none
grid:
- grid-template-areas: '"device"'
- grid-template-columns: auto
custom_fields:
device:
card:
type: custom:stack-in-card
mode: vertical
card_mod:
style: |
ha-card {
padding: 0px;
border: none;
box-shadow: none;
}
keep:
background: true
border_radius: true
box_shadow: true
margin: true
outer_padding: true
cards:
- type: horizontal-stack
cards:
- type: grid
columns: 1
square: false
cards:
- type: custom:mushroom-chips-card
chips:
- type: template
content: '[[[ return variables.geraet_name ]]]'
entity: '[[[ return variables.device_entity_icon ]]]'
icon: '{{ state_attr(entity,"icon") }}'
tap_action: none
card_mod:
style: |
ha-card {
background: none !important;
border: none !important;
box-shadow: none !important;
font-size: 3.5rem !important;
}
- type: custom:mushroom-chips-card
chips:
- type: template
content: '[[[ return variables.fenster_geoffnet_friendly_name ]]]'
entity: '[[[ return variables.device_entity_icon ]]]'
icon: '{{ state_attr(entity,"icon") }}'
tap_action: none
card_mod:
style: |
ha-card {
background: none !important;
border: none !important;
box-shadow: none !important;
font-size: 3.5rem !important;
}
- type: grid
columns: 2
square: false
cards:
- type: custom:mushroom-template-card
entity: >-
[[[ return "binary_sensor.fenster_" +
variables.geraet_entity_name ]]]
icon: >-
{% if states(entity) == 'off' %}
mdi:window-closed-variant
{% elif states(entity) == 'on' %}
mdi:window-open-variant
{% elif states('[[[ return "sensor.fenster_" +
variables.geraet_entity_name + "_gekippt" ]]]') == '1'
%}
mdi:window-closed-variant
{% endif %}
icon_color: >-
{% if states(entity) == 'off' %}
green
{% elif states(entity) == 'on' %}
red
{% elif states('[[[ return "sensor.fenster_" +
variables.geraet_entity_name + "_gekippt" ]]]') == '1'
%}
orange
{% endif %}
primary: >-
[[[ return
`${entity.attributes.friendly_name.replace("Fenster","")}`
]]]
secondary: >-
{% if states(entity) == 'off' %}
geschlossen
{% elif states(entity) == 'on' %}
geöffnet
{% elif states('[[[ return "sensor.fenster_" +
variables.geraet_entity_name + "_gekippt" ]]]') == '1'
%}
gekippt
{% endif %}
tap_action:
action: none
hold_action:
action: none
double_tap_action:
action: none