My problem…
I have duplicate code . 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!