Loop through areas

Hey guys,

i need your help. How can i loop through all areas in my HASS setup and create these auto-entities for all those areas? There is a lot of code duplication as you see in the following example for two areas:

# AREA 1
  - type: "custom:button-card"
    template: "card_title"
    label: "HWR"

  - type: "custom:auto-entities"
    card:
      type: "custom:layout-card"
      layout_type: "custom:grid-layout"
      layout:
        grid-template-rows: "min-content"
        grid-template-columns: "1fr 1fr 1fr"
        mediaquery:
              "(max-width: 1400px)":
                grid-template-columns: "1fr 1fr"
    card_param: "cards"
    filter:
      include:
        - domain: "switch"
          area: HWR
          options:
            type: "custom:button-card"
            template: "card_power_outlet"
      exclude:
        - state: "unavailable"
        - hidden_by: "*"

# AREA 2
  - type: "custom:button-card"
    template: "card_title"
    label: "Flur"

  - type: "custom:auto-entities"
    card:
      type: "custom:layout-card"
      layout_type: "custom:grid-layout"
      layout:
        grid-template-rows: "min-content"
        grid-template-columns: "1fr 1fr 1fr"
        mediaquery:
              "(max-width: 1400px)":
                grid-template-columns: "1fr 1fr"
    card_param: "cards"
    filter:
      include:
        - domain: "switch"
          area: Flur
          options:
            type: "custom:button-card"
            template: "card_power_outlet"
      exclude:
        - state: "unavailable"
        - hidden_by: "*"
1 Like

Have you come up with a solution for this yet? I’ve been wanting to do something very similar but I’m having difficulties getting the auto-entities card to do anything with the areas list.

Nope, sorry :confused:

I want exactly this.
Maybe it needs some additional helper, but I really want to do this. I don’t want to reconfigure my dashboard everytime I rename an area or add a new one

I’ve been working on something like this with my dashboard. I use Decluttering Card from HACS and provide it with the specific entities/values that my template would need.

type: custom:decluttering-card
template: popup_template
variables:
  - hash_url: "#bathroom"
  - area_name: Bathroom
  - entity_prefix: bathroom
  - icon: toilet
  - light_group: light.bathroom

My actual template is still a mess so I won’t post that, but hopefully that is enough to go on. I also utilize Auto Entities for a lot of my template, using the area_name value to target things like lights, outlets, media players, etc.