I have followed this thread and tried a number of examples. I am new to HA and I am getting something wrong, but for the life of me I am not sure why it doesn’t work.
I want to change the ICON based on the state of the door sensor, and the COLOR based on the state of that sensor and light sensor, as follows:
if sensor.garage_door == OPEN then
set icon to open garage
set color to red
else
set icon to closed garage
if sensor.garage_lights == ON then
set color to orange
else
set color to green
endif
endif
I started slow, and I got icons and colors to change based on one sensor:
cards:
- show_name: true
show_icon: true
type: custom:button-card
entity: binary_sensor.garage_door_kiabmw
name: Garage
tap_action:
action: navigate
navigation_path: /dashboard-garage
state:
- value: 'on'
icon: mdi:garage-open-variant
color: red
- value: 'off'
icon: mdi:garage-variant
color: green
Now, I am close, and all I need to do is change that last “color: green” depending on the state of the lights. I tried the following (only showing the replacement for the last line above, so as not to make the post too long):
color: >
[[[
if (states['light.garage_light_all'].state == 'on') return "orange";
else return "green";
]]]
But nothing would happen. I thought the problem was with the conditional, so I tried the following:
color: '[[[ return "green"; ]]]'
and
color: >
[[[
return "green";
]]]
But none of it worked, for some reason.
Then I took a different approach, and I used the following:
cards:
- show_name: true
show_icon: true
type: custom:button-card
entity: binary_sensor.garage_door_kiabmw
name: Garage
tap_action:
action: navigate
navigation_path: /dashboard-garage
icon: >
[[[
if (entity.state == 'on')
return "mdi:garage-open-variant";
else
return "mdi:garage-variant";
]]]
color: >
[[[
if (entity.state == 'on')
return "red";
else if (states['light.garage_light_all'].state == 'on')
return "orange";
else
return "green";
]]]
And the icon part worked perfectly well, but the color part didn’t. That is, color did not change.
Not sure what I am doing wrong… Any advice much appreciated. Thanks