Lovelace config-template-card entities based on logged in user

My problem…

I have duplicate code :frowning: . My goal is to adhere to the DRY principle by using the config-template-card.

// NOTE: {{ something }} is just a placeholder.  
// I'm NOT using jinja templates in the actual config

views:
  - title: {{ user_name }} 
    badges: 
    visible: {{ user_id }}   
    cards:
      - type: grid
        columns: 1
        square: false
        cards:
          - type: entities
            entities:
              - entity: {{ domain }}.{{ user[#] }}_{{ entity }}
             ...
// Repeated for every new user

So, I’d love to simply things by using the config-template-card.

My plan is…

  • create new user
  • create a person to store the user_name
  • use the config-template-card to fill in the user_name and user_id variables

User: Display name points to person name(friendly_name)
Person: Id stores the username which is used to build the entity_id

Example:
Display name is Joe. Create a person with name: Joe, id: user1, and user_id set to the users id.

Then, in the template checker
{{ state_attr('person.Joe, 'id') }}
will return “user1”

// NOTE: {{ something }} is just a placeholder.  
// I'm NOT using jinja templates in the actual config

  - type: custom:config-template-card
    variables:
      USERNAME: user.name // used for view title
      USER_ID: user.id // used for view visible
      USER_NUM: >-
        states['person.' + states['person.' + USERNAME.toLowerCase()].attributes.friendly_name].attributes.id  // used for building out entities and entity, respectively.

    entities:
      - {{ domain }}.USER_NUM_{{ entity }}
     ...
    card:
      type: entities
      entities:
        - entity: input_boolean.USER_NUM_{{ entity }}
          name: Boolean
       ...

I got this to work to return the id of ‘user1’ with the display name of User1, person name of user1 and person id of user1…

entities:
  - type: custom:config-template-card
    variables:
      ID: >-
        states['person.' + states['person.' +
        user.name].attributes.friendly_name.toLowerCase()].attributes.id
    entities:
      - input_boolean.user1_test
    row:
      type: section
      label: ${ID}

I need some direction on is how to fill out the whole view with this approach as I can’t seem to figure out the right syntax. Is it even possible to use the card variables in the view config? Maybe there is another card better suited for my goal that I’m not aware of?

Thanks!

Made some progress!!!

User display name: Joe
Person name: Joe
Person id: user1

type: 'custom:config-template-card'
variables:
  - ('Joe') // users display name
  - states['person.' + states['person.' + vars[0].toLowerCase()].attributes.friendly_name.toLowerCase()].attributes.id
entities:
  - ${'input_boolean.' + vars[1] + '_test'}
  - ${'input_boolean.' + vars[1] + '_test1'}
card:
  type: entities
  entities:
    - entity: ${'input_boolean.' + vars[1] + '_test'}
      name: 'Test'
    - entity: ${'input_boolean.' + vars[1] + '_test1'}
      name: 'Test1'

Just need to figure out how to handle…

views:
  - title: {{ user_name }} 
    badges: 
    visible: {{ user_id }}   
    cards:
      ...

After some thought…

I don’t think I need the title: or visible: sections as the user will only have a single view (so the view: title won’t show in the header) and only entities belonging to the user will be shown.

I’ll post a follow up when I have more to show. Maybe someone will benefit from it.

This is where I have been looking towards going with my set up! Good luck. If I get anywhere with it, I’ll come back and share!