Bonjour,
Je débute dans home assistant (j’ai débuté samedi dernier) et je cherche à simplifier le code pour le modifier qu’à un seul endroit (variable, macro, template, …). C’est cette partie de code ci dessous
[[[
if (states['remote.nvidia_shield'].state == 'on')
return 'green';
else
return 'grey';
endif
]]]
voici une partie de la vue de la télécommande (coupé car trop long)
views:
- title: Télécommande
type: custom:layout-card
layout_type: custom:grid-layout
layout:
width: 100%
max_cols: 3
grid-template-columns: 1fr 1fr 1fr
grid-template-rows: auto
grid-template-areas: |
"btn_power btn_remote btn_remote"
". btn_up ."
"btn_left btn_enter btn_right"
"btn_back btn_down btn_home"
"btn_first btn_pause btn_last"
"btn_no_sound btn_dec_sound btn_up_sound"
"btn_youtube btn_netflix btn_molotov"
"btn_statut btn_statut btn_statut"
"btn_info btn_info btn_info"
cards:
- type: custom:button-card # power
entity: switch.prise_tv
view_layout:
grid-area: btn_power
icon: mdi:power
tap_action:
action: toggle
styles:
icon:
- color: >
[[[
if (states['switch.prise_tv'].state == 'off')
return 'red';
else
return 'green';
]]]
- type: custom:button-card # remote
entity: remote.nvidia_shield
view_layout:
grid-area: btn_remote
name: Etat de la télécommande
show_label: false
label: |
[[[
return '#' + states['remote.nvidia_shield'].state + '#';
]]]
styles:
card:
- height: 100%
name:
- justify-self: middle
- font-weight: bold
icon:
- color: >
[[[
if (states['remote.nvidia_shield'].state == 'on')
return 'green';
else
return 'grey';
endif
]]]
- type: custom:button-card # up
icon: mdi:arrow-up-bold
view_layout:
grid-area: btn_up
aspect_ratio: 1/1
tap_action:
action: perform-action
perform_action: remote.send_command
data:
command: DPAD_UP
target:
entity_id: remote.nvidia_shield
hold_action:
action: none
styles:
icon:
- color: >
[[[
if (states['remote.nvidia_shield'].state == 'on')
return 'green';
else
return 'grey';
endif
]]]
- type: custom:button-card # left
icon: mdi:arrow-left-bold
view_layout:
grid-area: btn_left
aspect_ratio: 1/1
tap_action:
action: perform-action
perform_action: remote.send_command
data:
command: DPAD_LEFT
target:
entity_id: remote.nvidia_shield
hold_action:
action: none
styles:
icon:
- color: >
[[[
if (states['remote.nvidia_shield'].state == 'on')
return 'green';
else
return 'grey';
endif
]]]
J’ai essaye en macro, je n’ai pas réussi.
J’ai essayé un template, idem
Je ne pense pas qu’avec un script ça pourrait le faire.
Merci pour votre aide.
hervé