Voilà ce que ça peut donner avec un timer et un script pour l’appui sur le bouton :
Le code :
type: custom:button-card
aspect_ratio: 3/1
entity: input_boolean.position_garage
name: Garage
icon: |
[[[
if (states['input_boolean.position_garage'].state == 'off')
return 'mdi:garage';
else if (states['input_boolean.position_garage'].state == 'on')
return 'mdi:garage-open';
]]]
show_label: true
label: |
[[[
if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'idle')
return '<font color= "green"><b>fermé</font>';
else if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'active')
return '<font color= "orange"><b>fermeture</font>';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'idle')
return '<font color= "red"><b>ouvert</font>';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'active')
return '<font color= "orange"><b>ouverture</font>';
]]]
styles:
name:
- font-size: 0.9em
- justify-self: middle
- align-self: end
- color: rgba(255,255,255,0.6)
card:
- background-color: rgba(64,64,64,0.8)
- box-shadow: 4px 4px 4px 0px rgba(32,32,32,0.5)
- border: 2px rgba(211,211,211,1.0) outset
icon:
- border-radius: 50%
- border: none
- box-shadow: 0px 0px 5px 5px rgba(0,128,0,0.5)
- box-shadow: |
[[[
if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'idle')
return '0px 0px 5px 5px rgba(0,128,0,0.5)';
else if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'active')
return '0px 0px 5px 5px rgba(255,140,0,0.5)';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'idle')
return '0px 0px 5px 5px rgba(255,0,0,0.5)';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'active')
return '0px 0px 5px 5px rgba(255,140,0,0.5)';
]]]
- background-color: |
[[[
if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'idle')
return 'rgba(0,128,0,0.5)';
else if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'active')
return 'rgba(255,140,0,0.5)';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'idle')
return 'rgba(255,0,0,0.5)';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'active')
return 'rgba(255,140,0,0.5)';
]]]
- width: 60px
- height: 60px
- color: |
[[[
if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'idle')
return 'rgba(0,255,0,1.0)';
else if (states['input_boolean.position_garage'].state == 'off' && states['timer.essai_timer'].state == 'active')
return 'rgba(255,140,0,1.0)';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'idle')
return 'rgba(255,0,0,1.0)';
else if (states['input_boolean.position_garage'].state == 'on' && states['timer.essai_timer'].state == 'active')
return 'rgba(255,140,0,1.0)';
]]]
- animation: |
[[[
if (states['timer.essai_timer'].state == 'active')
return 'blink 2s ease infinite';
]]]
tap_action:
action: call-service
service: script.essai_garage
hold_action:
action: none
Le script :
alias: essai_garage
sequence:
- service: timer.start
metadata: {}
data: {}
target:
entity_id: timer.essai_timer
- if:
- condition: state
entity_id: input_boolean.position_garage
state: "on"
then:
- service: input_boolean.turn_off
metadata: {}
data: {}
target:
entity_id: input_boolean.position_garage
else:
- service: input_boolean.turn_on
metadata: {}
data: {}
target:
entity_id: input_boolean.position_garage
mode: single