Custom:mushroom-entity-card icon color state not working

Hello there,

I’m trying to change the state of the icon based on whether the status is “on” or “off”. The icon should be amber or gray depending on whether the lights are on or off. Unfortunately, the icon stays blue. What am I doing wrong? I can’t figure it out.

Thanks in advance for any help.

type: custom:stack-in-card
mode: vertical
keep:
  outer_padding: false
  margin: true
cards:
  - type: custom:swipe-card
    mode: vertical
    keep:
      outer_padding: false
      margin: true
      box_shadow: false
      background: false
    cards:
      - type: horizontal-stack
        cards:
          - type: custom:mushroom-entity-card
            card_mod:
              style: |
                ha-card{
                 box-shadow: none;
                 }
            entity: input_boolean.on_state
            double_tap_action:
              action: none
            icon: mdi:lightbulb
            style:
              icon_color: >
                {% set state = states('sensor.lights_of_count')|float %} {% if
                state <= 0 %}
                  grey
                {% else %}
                  amber
                {% endif %}
            layout: vertical
            hold_action:
              action: none
            tap_action:
              action: navigate
              navigation_path: /lovelace/lights
            primary_info: none
            secondary_info: none
            name: Licht

Use a template card if you want to use templates, and icon_color doesn’t go under style.

type: custom:stack-in-card
mode: vertical
keep:
  outer_padding: false
  margin: true
cards:
  - type: custom:swipe-card
    mode: vertical
    keep:
      outer_padding: false
      margin: true
      box_shadow: false
      background: false
    cards:
      - type: horizontal-stack
        cards:
          - type: custom:mushroom-template-card
            card_mod:
              style: |
                ha-card{
                 box-shadow: none;
                 }
            entity: input_boolean.on_state
            icon: mdi:lightbulb
            icon_color: >
              {% set state = states('sensor.lights_of_count')|float %}
              {{ 'grey' if state <= 0 else 'amber' }}
            layout: vertical
            tap_action:
              action: navigate
              navigation_path: /lovelace/lights
            primary_info: none
            secondary_info: none
            name: Licht

I don’t know if it’s intentional or you just missed an “f”, but double check your sensor’s ID… sensor.lights_of_count

1 Like

This did the trick! Thank you so much for your help @Didgeridrew!
Again confirmed, coding is not my best skill!

Hello again @Didgeridrew and, of course, all other users.

Since you’ve been so great in helping me with my previous challenge, I’m taking the liberty to ask a follow-up question.

I’m struggling to program the “Hold Action” in a way that when I use it, all lights are turned off. I’ve found some information here and there, but it’s not working out yet. Perhaps there’s a simpler way to achieve this action. Any help is, of course, very much appreciated.

The situation so far.

      - type: horizontal-stack
        cards:
          - type: custom:mushroom-template-card
            card_mod:
              style: |
                ha-card{
                 box-shadow: none;
                 }
            entity: input_boolean.on_state
            icon: mdi:lightbulb
            icon_color: >
              {% set state = states('sensor.lights_of_count')|float %} {{ 'grey'
              if state <= 0 else 'amber' }}
            layout: vertical
            hold_action:
              action: call-service
              service: automation.trigger
              service_data:
                entity_id: automation.lights_off_long_press
            tap_action:
              action: navigate
              navigation_path: /lovelace/lights
            primary_info: none
            secondary_info: none
            name: Licht

The automation looks like,

automation:

  - id: lights_off_long_press
    alias: Turn Off Lights on Long Press
    trigger:
      platform: state
      entity_id: input_boolean.on_state  # Replace with the actual entity ID of your button
      to: 'on'
      for:
        seconds: 3  # Adjust the duration for a long press as needed
    action:
      - service: light.turn_off
        entity_id: all

As mentioned, perhaps I’m trying to make it too complicated. What I don’t understand in the ‘automation’ for example is the action ‘service: light.turn_off’.

Regards,
Herman

Can you explain your reasoning for the automation? Are there other inputs that you want to turn off all the lights? Are you planning on adding conditional logic to assess when and when not to turn off the lights? I ask because, if not, you’ve chosen a somewhat unusual structure. If you want a button that always turns off all the lights no matter what, there is no reason to route it through a script or automation.

As for the service call, it should be:

service: light.turn_off
target:
  entity_id: all

Was there a specific question you have about it, or maybe service calls in general?

Thanks again for the fast reply,

No specific reason for this approach. Google and chat-gpt pointed me there.

I just want to keep it simple and turn off all the lights when we go to bed early for example. Normally the lights are all turned off at 23.00. But as it happens, because we are aging, is that we go to bed at 10 :smile: Then the button comes in to be handy.

Cheers, Herman

Put your code into the card under the hold action. Unfortunately not working…

service: light.turn_off
target:
  entity_id: all

The card has a slightly different configuration for services:

      - type: horizontal-stack
        cards:
          - type: custom:mushroom-template-card
            card_mod:
              style: |
                ha-card{
                 box-shadow: none;
                 }
            entity: input_boolean.on_state
            icon: mdi:lightbulb
            icon_color: >
              {% set state = states('sensor.lights_of_count')|float %}
              {{ 'grey' if state <= 0 else 'amber' }}
            layout: vertical
            hold_action:
              action: call-service
              service: light.turn_off
              target:
                entity_id: all
            tap_action:
              action: navigate
              navigation_path: /lovelace/lights
            primary_info: none
            secondary_info: none
            name: Licht
1 Like

Great! It works! Thanks man! Was very close before. Must have missed details.

The Tap_action should be removed after the Hold_action tho.

Many thanks.
Herm