#Automaticially Populate Light Cards

1 messages · Page 1 of 1 (latest)

keen sonnet
#

Is there a way to use auto-entities to show a custom card for each relevant entity? Similar to the code below:

card:
  type: custom:mushroom-light-card
filter:
  include:
    - domain: light
      state: "on"
  exclude: []
sort:
  method: friendly_name
show_empty: false
exotic flame
#
type: custom:auto-entities
card:
  type: grid
  square: false
  columns: 2
card_param: cards
filter:
  include:
    - domain: light
      state: "on"
      options:
        type: custom:mushroom-light-card
  exclude:
    - entity_id: "*screen*"
    - entity_id: light.all_lights
sort:
  method: friendly_name
show_empty: false
#

For my set-up, I use yaml filter: include: - entity_id: light.*_lights This shows only the light groups that I've set-up and the entity_ids end in _lights. This way I don't see all of the individual lights.

keen sonnet
#

Thank you!!!

keen sonnet
exotic flame
#

What you have there is JavaScript and that would probably work with the custom:button-card; most other cards use Jinja.
The Mushroom Light Card itself cannot use Jinja templates. The Mushroom Template Card can but it doesn't have the same styling and features as the MLC.
I wonder, though, if the auto-entities card can handle the appropriate template and pass it to the MLC. I'll try to play with it and see what I can figure out.

exotic flame
#

So... This turned out to not be as simple as what I was hoping for. The name: for the Mushroom Light Card via the auto-entities card would not handle a template. In order to use a template the include: had to be replaced with template: and the entire thing had to be written out. I found similar questions in the forum, took bits and pieces of a couple of examples and came up with (what I believe) is something that works. This examples finds all lights that are on and have Lights in the friendly_name and shows each entity in a Mushroom Light Card.

#
type: custom:auto-entities
card:
  square: false
  columns: 2
  type: grid
card_param: cards
filter:
  template: |-
    {% for x in states.light -%}
      {%- if x.state == 'on' and state_attr(x.entity_id, 'friendly_name') | regex_search(" Lights") -%}
        {{
          {
            'type': 'custom:mushroom-light-card',
            'entity': x.entity_id,
            'name': state_attr(x.entity_id, 'friendly_name') | replace( ' Lights', '')
          }
        }},
      {%- endif -%}
    {%- endfor %}
  exclude:
    - entity_id: "*screen*"
    - entity_id: light.all_lights
    - integration: demo
show_empty: false
sort:
  method: friendly_name
#

In this screenshot, the top three cards is the original version; bottom three cards is the template version.
(Note: I also excluded the lights from the Demo integration that I run so the card looks less cluttered. This probably won't apply to you, but it's the reason why the screenshot shows less lights than the other one I posted above.)