Hello,
I want to place mushroom template chips on a picture elements card. I know how to change the icon color and also how to change or remove the chip background (with card-mod). But I need also to change the color of the label/text of the chip. Here is what I have so far:
Yes, you’ll have to use the following entries. I provided an example card which is slightly different than your IF statement approach. Let me know if you nee help getting it to work on your card.
thanks for your help, I managed to make the example card like the one you indicated:
But I’m having trouble with what I need.
I think the problem is related to entities.
I am using template, with a switch entity to be able to act on On/off but then the information comes from a different entity, the power sensor, so the code written as you suggested does not work, because it does not find numbers, but only ON-OFF
I tried to replace your suggestion:
{% set power = states(config.entity)
whit my entity:
{% set power = states(config.sensor.presa_multimediale_cucina_power) | float%} {% if power < 5 %} --card-primary-color:grey;--card-secondary-color:blue;
But I think something is still not working because nothing happens in the colors of the two lines
Definitely due to my inexperience.
Since you were so kind, I have an even more difficult question for me, before banging my head I ask if it’s possible.
Now I have this well-made card that changes its icon and color:
green if on
red if off
(the icon in this case does not change, but I use it as a standard for other future cards where the icon can also change).
This card currently has the name written underneath and the consumption which may vary with consumption (primary and secondary info)
I would like to understand if it is possible to have the gray icon if the socket is on but there is no consumption detected by the socket so as now it indicates 0 watts.
This is my actual code:
type: custom:stack-in-card
mode: vertical
cards:
- type: custom:mushroom-template-card
primary: Presa Forno
secondary: '{{states.sensor.presa_forno_power.state}} W'
icon: >-
{% if is_state(entity, 'off') %} mdi:toaster-oven {%- else -%}
mdi:toaster-oven {% endif %}
icon_color: '{% if is_state(entity, ''off'') %} red {% else %} green {% endif %}'
fill_container: true
layout: vertical
tap_action:
action: more-info
entity: sensor.presa_forno_power
multiline_secondary: truee;
card_mod:
style: >
ha-card { {% set power =
states('sensor.presa_forno_power') | float%} {% if
power <= 0 %} --card-primary-color:grey;--card-secondary-color:grey;
{% elif power < 100 %}
--card-primary-color:white;--card-secondary-color:green; {% elif
power < 200 %}
--card-primary-color:white;--card-secondary-color:lime; {% elif
power < 500 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 800 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 1000 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 1500 %}
--card-primary-color:white;--card-secondary-color:orange; {% else %}
--card-primary-color:white;--card-secondary-color:red;
{% endif %}
Thanks, I’m trying to think through why the example I gave you wasn’t the best. The oven icon should be red if the socket is off, gray if on but without consumption, and green in other cases.
However, the oven socket is not the best example, because it does not have a switch, it is just an energy meter, therefore always on. I’ll try to think about another case in point and if I succeed I will write it with great happiness
now I’ve arrived here, everything is ok, I just need to be able to add the green icon status when there are consumptions greater than 20 for example (the basic consumption being around 10W when only some things are active, but not the TV for example)
type: custom:stack-in-card
mode: vertical
cards:
- type: custom:stack-in-card
mode: horizontal
cards:
- type: custom:mushroom-template-card
primary: Presa Multimediale Cucina
secondary: '{{states.sensor.presa_multimediale_cucina_power.state}} W'
icon: >-
{% if is_state(entity, 'off') %} mdi:power-plug-off-outline {%- else
-%} mdi:power-plug-outline {% endif %}
icon_color: >
{% if states('sensor.presa_multimediale_cucina_power') | int (0) <=
20 and states('switch.presa_multimediale_cucina') == 'on' %}
grey
{% else %}
red
{% endif %}
fill_container: true
layout: vertical
tap_action:
action: more-info
entity: switch.presa_multimediale_cucina
multiline_secondary: truee;
card_mod:
style: >
ha-card { {% set power =
states('sensor.presa_multimediale_cucina_power') | float%} {% if
power <= 0 %} --card-primary-color:grey;--card-secondary-color:grey;
{% elif power < 100 %}
--card-primary-color:white;--card-secondary-color:green; {% elif
power < 200 %}
--card-primary-color:white;--card-secondary-color:lime; {% elif
power < 500 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 800 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 1000 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 1500 %}
--card-primary-color:white;--card-secondary-color:orange; {% else %}
--card-primary-color:white;--card-secondary-color:red; {% endif %}
You were faster than me, but there’s a strange problem.
By doing this, everything is fine when the switch is off:
All fine when the switch is on, but with consumption below 20W:
I don’t understand why the icon turns red instead if consumption is greater than 20W, instead it should turn green
type: custom:stack-in-card
mode: vertical
cards:
- type: custom:stack-in-card
mode: horizontal
cards:
- type: custom:mushroom-template-card
primary: Presa Multimediale Cucina
secondary: '{{states.sensor.presa_multimediale_cucina_power.state}} W'
icon: >-
{% if is_state(entity, 'off') %} mdi:power-plug-off-outline {%- else
-%} mdi:power-plug-outline {% endif %}
icon_color: >
{% if states('switch.presa_multimediale_cucina') == 'off' %}
red
{% elif states('sensor.presa_multimediale_cucina_power') | int (0) <= 20 and
states('switch.presa_multimediale_cucina') == 'on' %}
grey
{% else %}
green
{% endif %}
fill_container: true
layout: vertical
tap_action:
action: more-info
entity: switch.presa_multimediale_cucina
multiline_secondary: truee;
card_mod:
style: >
ha-card { {% set power =
states('sensor.presa_multimediale_cucina_power') | float%} {% if
power <= 0 %} --card-primary-color:grey;--card-secondary-color:grey;
{% elif power < 100 %}
--card-primary-color:white;--card-secondary-color:green; {% elif
power < 200 %}
--card-primary-color:white;--card-secondary-color:lime; {% elif
power < 500 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 800 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 1000 %}
--card-primary-color:white;--card-secondary-color:yellow; {% elif
power < 1500 %}
--card-primary-color:white;--card-secondary-color:orange; {% else %}
--card-primary-color:white;--card-secondary-color:red; {% endif %}