
Voici un exemple fonctionnel avec custom:button-card.
Voici le code :
type: custom:button-card
name: Porte Garage
label: |
[[[
if (states['timer.essai_timer'].state === 'active') return 'Fermeture';
if (states['input_boolean.essai_capteur_garage'].state === 'off') return 'Ouverte';
if (states['input_boolean.essai_capteur_garage'].state === 'on') return 'Fermée';
return 'État inconnu';
]]]
show_label: true
custom_fields:
my_icon:
card:
type: custom:button-card
icon: |
[[[
if (states['timer.essai_timer'].state === 'active') return 'mdi:window-shutter-cog';
if (states['input_boolean.essai_capteur_garage'].state === 'off') return 'mdi:window-shutter-open';
if (states['input_boolean.essai_capteur_garage'].state === 'on') return 'mdi:window-shutter';
return 'mdi:window-shutter-alert';
]]]
styles:
card:
- background-color: rgba(44,44,44,1)
- border-radius: 50%
- width: 60px
- height: 60px
- display: flex
- align-items: center
- justify-content: center
- pointer-events: none
- cursor: default
icon:
- color: |
[[[
if (states['timer.essai_timer'].state === 'active') return 'orange';
if (states['input_boolean.essai_capteur_garage'].state === 'off') return 'red';
if (states['input_boolean.essai_capteur_garage'].state === 'on') return 'green';
return 'lightgray';
]]]
- animation: |
[[[
return states['timer.essai_timer'].state === 'active' ? 'blink 1.5s infinite' : 'none';
]]]
- width: 40px
button_up:
card:
type: custom:button-card
icon: mdi:arrow-up
tap_action:
action: call-service
service: script.essai_garage_ouverture
styles:
card:
- background-color: rgba(44,44,44,1)
- width: 105px
- height: 42px
- pointer-events: |
[[[
return states['input_boolean.essai_capteur_garage'].state === 'on' ? 'auto' : 'none';
]]]
- cursor: |
[[[
return states['input_boolean.essai_capteur_garage'].state === 'on' ? 'pointer' : 'default';
]]]
icon:
- color: |
[[[
return states['input_boolean.essai_capteur_garage'].state === 'on' ? 'rgba(255,255,255,0.8)' : 'rgba(255,255,255,0.1)';
]]]
button_down:
card:
type: custom:button-card
icon: mdi:arrow-down
tap_action:
action: call-service
service: script.essai_garage_fermeture
styles:
card:
- background-color: rgba(44,44,44,1)
- width: 105px
- height: 42px
- pointer-events: |
[[[
return states['input_boolean.essai_capteur_garage'].state === 'off' ? 'auto' : 'none';
]]]
- cursor: |
[[[
return states['input_boolean.essai_capteur_garage'].state === 'off' ? 'pointer' : 'default';
]]]
icon:
- color: |
[[[
return states['input_boolean.essai_capteur_garage'].state === 'off' ? 'rgba(255,255,255,0.8)' : 'rgba(255,255,255,0.1)';
]]]
styles:
card:
- height: 130px
- width: 250px
- background-color: rgba(28, 28, 28, 1)
- border-radius: 12px
- box-shadow: none
- border: 1px solid rgba(44,44,44,1)
- pointer-events: |
[[[
return (['Ouverte', 'Fermée'].includes(states['input_select.essai_garage'].state)) ? 'none' : 'auto';
]]]
- cursor: |
[[[
return (['Ouverte', 'Fermée'].includes(states['input_select.essai_garage'].state)) ? 'default' : 'pointer';
]]]
grid:
- grid-template-areas: >-
"my_icon n" "my_icon l" "button_up button_down" "timer_status
timer_status"
- grid-template-columns: 70px auto
- grid-template-rows: 30px 40px 42px 42px
- align-items: flex-start
- padding-left: 10px
name:
- font-size: 14px
- font-weight: bold
- color: rgba(255,255,255,0.8)
- justify-self: start
- text-align: left
label:
- font-size: 12px
- color: |
[[[
const s = states['timer.essai_timer'].state;
return s === 'active' ? 'orange' : 'rgba(255,255,255,0.8)';
]]]
- justify-self: start
- text-align: left
- margin-top: 4px
custom_fields:
button_up:
- position: absolute
- top: 80px
- left: 15px
button_down:
- position: absolute
- top: 80px
- right: 15px
Pour l’utiliser, il te faut custom:button-card et copier le code complet dans une nouvelle carte.
Il faudra remplacer timer.essai_timer
par ton propre minuteur. input_boolean.essai_capteur_garage
par ton capteur de fermeture de ta porte du garage et input_select.essai_garage
par ta liste déroulante.
Par ailleurs, il te faudra un script pour la fermeture et un script pour l’ouverture :
sequence:
- action: timer.start
metadata: {}
data: {}
target:
entity_id: timer.essai_timer
- action: input_select.select_option
metadata: {}
data:
option: Fermeture
target:
entity_id: input_select.essai_garage
alias: essai_garage_fermeture
description: ""
sequence:
- action: input_boolean.turn_off
metadata: {}
data: {}
target:
entity_id: input_boolean.essai_capteur_garage
- action: input_select.select_option
metadata: {}
data:
option: Ouverte
target:
entity_id: input_select.essai_garage
alias: essai_garage_ouverture
description: ""
Si tu as des questions, n’hésites pas.