Hi,
I have seen some other topics on this subject, but I have not been able to use the info in these to get a colour change working. Here’s my code for the chip:
- type: entity
entity: sensor.hot_water_temperature
icon: mdi:thermometer-water
name: Hot Water
use_entity_picture: false
icon_color: |-
{% set hwstatus = states(sensor.hot_water_state)}
{% if hwstatus = "On"}
red
{% else %}
black
{% endif %}
sensor.hot_water_state is a template to pull a nested attribute out of the entity and has the values On or Off. I have tried a few syntax options without success. Can anyone see what I am doing wrong?
On a side note, whenever I save changes to the yaml, >- gets changed to |- and the line break between the set and if statements gets deleted. Is this related?
Many thanks.
tykeal
(Andrew Grimberg)
March 18, 2024, 1:20pm
2
Looks like you aren’t properly closing your braces. You have a }
ending your first two lines when it should be %}
As for the change between >-
and |-
you want the second not the first for a block like that.
See this site for why and to play around with the different multi-line styles for YAML.
WallyR
(Wally)
March 18, 2024, 1:22pm
3
>-
and |-
seems to be mutually interchangeable just like '
and "
so that is probably not it.
The rearranging of the lines happens all the time and it should have no general impact, except when you want to set or remove extra line break in the output, which is not the case here.
I can’t seem to find an attribute called icon_color. Where did you find the documentation on that?
Thanks all.
icon_color seems to be a standard attribute. Here’s another chip from the same card:
- type: entity
entity: switch.bedroom_upright_lamp
name: Bedroom
icon: mdi:lightbulb
icon_color: blue
I tried changing the braces to %}, but that didn’t seem to help.
WallyR
(Wally)
March 18, 2024, 1:57pm
5
Ahh, found it.
# Entity card
![Entity light](../images/entity-light.png)
![Entity dark](../images/entity-dark.png)
## Description
A entity card allows you to display an entity.
## Configuration variables
All the options are available in the lovelace editor but you can use `yaml` if you want.
| Name | Type | Default | Description |
| :------------------ | :-------------------------------------------------- | :---------- | :---------------------------------------------------------------------------------- |
| `entity` | string | Required | Entity |
| `icon` | string | Optional | Custom icon |
| `icon_color` | string | `blue` | Custom color for icon when entity is state is active |
| `name` | string | Optional | Custom name |
| `layout` | string | Optional | Layout of the card. Vertical, horizontal and default layout are supported |
This file has been truncated. show original
But it looks like it is only a string and it might not be templateable (if that work exist )
Perhaps that’s the problem. The same(ish) question has been asked on other threads:
Hello,
this is my script for my chips card on top of my dashboard. I would like the color of the battery icon to change, based on its sensor’s state:
- type: custom:mushroom-chips-card
chips:
- type: entity
entity: sensor.tabingresso_battery_level
double_tap_action:
action: none
use_entity_picture: false
hold_action:
action: none
icon_color: >-
{% set level = state('sensor.tabingresso_battery_level') %}
…
Hello
I’m trying to create a mushroom state card that changes color based on the state. There are no errors but the icon does not change color. Any ideas?
type: custom:mushroom-entity-card
entity: sensor.nordpool_kwh_dk1_dkk_3_01_025
name: Elpris
fill_container: false
icon: mdi:lightning-bolt
icon_color: >
if (state > 4) return 'rgb(0,0,0)'; if (state > 3) return
'rgb(0,0,204)'; if (state > 1) return 'rgb(255,255,0)'; if (state < 1)
return 'rgb(0,204,102)';
State:
2.532
The icon stays…
And there were a lot of suggestions, but I have not been able to make them work.
WallyR
(Wally)
March 18, 2024, 2:19pm
7
I use card_mod for that, but I do not know how mushroom cards react with that.
You could test it.
If you use a template chips card, you can change the icon color with a template, this is one of mine:
- type: custom:mushroom-chips-card
chips:
- type: template
entity: sensor.toilet_current_temperature
icon: mdi:thermometer
icon_color: >-
{% if states ('sensor.toilet_state') == "ON" %}
red
{% endif %}
content: '{{ states ("sensor.toilet_current_temperature") }}°C'
WallyR
(Wally)
March 18, 2024, 7:31pm
9
Just noticed that to do a compare the OP used a = instead of ==
@jbarrett-fmad There are two main mushroom threads
Hello gentlemen,
could you please help me out, I’m trying to rotate 90 degrees a custom:mushroom-title-card. Thanks for your time.
type: custom:mushroom-title-card
title: Rollo Küche
alignment: center
card_mod:
style: |
ha-card {
rotate: 90deg;
}