Mushroom Cards - Build a beautiful dashboard easily 🍄 (Part 2)

I’m working on creating a reusable room control card for my Home Assistant setup. To avoid repetition, I’m utilizing the decluttering_templates feature and embedding mushroom cards within them.

My goal is to make the room control card dynamic based on the specific entities present in each room. For example, some rooms have ceiling fans, while others don’t. I’d like to pass in the fan entity (e.g., input_select.living_room_fan_mode) as a parameter to my decluttering template.

The challenge I’m facing is conditionally displaying a mushroom chip (specifically a template chip that would trigger a fan control popup) only when the fan_entity parameter is actually passed into the decluttering template for a particular room.

From what I’ve seen with the standard conditional chip in mushroom, it seems to primarily work based on the state of an entity. I need a way to conditionally show the chip based on whether the fan_entity parameter even exists within the context of the rendered card.

For example, let’s say I have two rooms: “Living Room” and “Bedroom”.

  • For the “Living Room”, I would call my decluttering template and pass in the fan_entity:
- type: custom:decluttering-card
  template: room_control_template
  variables:
    room_name: "Living Room"
    light_entity: light.living_room_lights
    fan_entity: input_select.living_room_fan_mode
    # ... other entities
  • For the “Bedroom”, I would call the same template but without the fan_entity:
- type: custom:decluttering-card
  template: room_control_template
  variables:
    room_name: "Bedroom"
    light_entity: light.bedroom_lights
    # ... other entities (no fan_entity)

I want my room_control_template to render a mushroom chip for the fan only in the “Living Room” card (because the fan_entity was passed in). The “Bedroom” card should not display any fan-related chip.

I am looking for a generalized solution. This isn’t limited to fans, some rooms have shades, others have automation I want to associate with a chip, etc. For a bit more context, the room card I am talking about looks a lot like this one.

  • Is there a way within a mushroom card (or perhaps in conjunction with the decluttering template) to conditionally display a chip based on the existence or non-existence of a passed-in variable/parameter?

  • Are there alternative approaches I should consider to achieve this dynamic chip display based on available entities?

Edit: There may be a better and cleaner way to do this, but this is what I have done for now and seems to at least work.

  • I added to the template a set of “show_” parameters, e.g. show_fan, show_scene, show_covers.
  • I created an input boolean called “false” and one called “true”, false is off, true is on.
  • I created a conditional chip that looks at the “show_” parameter and if it is on, shows it.

The defaults end up looking like this:

default:
      - climate_action: '[[climate]]'
      - humidity: 'False'
      - show_fan: input_boolean.false
      - fan: input_boolean.false
      - show_scene_entity: input_boolean.false
      - show_scene_entity_state: 'on'
      - scene_icon: none
      - scene: none

Then when implementing the card, you end up with this:

          - type: custom:decluttering-card
            template: room_card
            variables:
              - name: Family Room
              - group: group.family_room
              - climate: climate.living_room
              - climate_action: climate.livingroom
              - dashboard: /family-room
              - lights: light.family_room_lights
              - show_fan: input_boolean.true
              - fan: fan.family_room_fan
              - show_scene_entity: sensor.home_sun_phase
              - show_scene_entity_state: night
              - scene_icon: mdi:moon-waxing-crescent
              - scene: scene.nighttime_tv

I don’t like that I have to have a separate show_ parameter, but it does seem to work.