I am trying to make the configuration of my Home Assistant somehow generic, to avoid code/configuration duplication. In a way, that when I am adding some entity, I want to have some behaviour preconfigured by a very simple way. For example, I want to have some sockets which are always on, some to turn off when no one is home, and turn on back on return, and some are irrelevant. This is achievable by creating a label, and on leaving/entering home zone switch off/on, with the target set to the label. Then when adding a new socket, I can just apply a label to it, and done.
It's more tricky when you want to do something with the UI. On the main screen I have an auto-entities card (from HACS) to display the location of the people - the name of the zone, or unknown. That part is simple. The magic happens, when you want to click on the entity, and instead of getting the default behaviour of showing a small pop-up widget with the location map, I want to either show a custom screen for given person, or a generic one, if the custom one has not been prepared. Some playing with templates, re-reading the documentation, and here we are.
Pre-requisities:
- install HACS
- install auto-entities from HACS
- create a dashboard, name does not matter, but it is important, that the URL is specified as dashboard-residents; you can have different value here, but then you need to modify the example below as appropriate
- under this dashboard create a view, the name nor URL does not matter, it is important, that this view if the 1st one on the dashboard, as it will contain a generic content, put whatever you want here
- under the same dashboard create views for each user you want to have a custom page for, it is important, that the URL matches the ID of the user
- on the home screen (or whenever you like) create a card as follows:
type: custom:auto-entities
card:
type: glance
filter:
template: |-
[{% for p in states.person %}
{'entity': 'person.{{ p.attributes.id }}',
'tap_action': {
'action': 'navigate',
'navigation_path': '/dashboard-residents/{{p.attributes.id}}'
}
},
{%- endfor %}]
Enjoy!
Now I wonder if it is possible to retrieve the URL on the generic page, to know for which user we want to generate the content, and pass it to some templates, to prepare something reasonable. But that's for another time. If you know the answer, please let me know, it will save me some time 😊
#HomeAssistant #HACS