I was looking for a way to show / hide information based on states or attributes of an entity. Example use cases:
Optional:
Required:
Use the developer tools to find out more information about your devices which will help with the setup.
Create a manual card and switch to the code view. The starting point below defines the type of card (auto-entities) and the look and feel of the entities to be listed. These can be customised to anything you’d like within the documentation
type: 'custom:auto-entities'
card:
type: entities
title: Windows and Doors
filter:
include:
show_empty: true
The example above uses the entities card and sets a title. Add the filters and include directive to the card so it can be saved. These will be explained below.
The show_empty will only make the card visible when there are entities listed. If there are none, it will be as if the card was never there outside of the edit mode.
The main focus are the filters. The sensor I want to bring into this are of a certain device class. All my windows and door entites are binary sensors (on/off) and part of the device class “door” or “window”. With this pattern in mind, I can add two parameters to my “include” filter:
filter:
include:
- domain: binary_sensor
attributes:
device_class: window
- domain: binary_sensor
attributes:
device_class: door
Saving the above should list all entities which are binary sensors with door or window device class.
Next, filter the entities for entities which are only open. This is stored in Home Assistant as a state and verified using the state developer tool.
filter:
include:
- domain: binary_sensor
state: 'on'
attributes:
device_class: window
- domain: binary_sensor
state: 'on'
attributes:
device_class: door
Lastly,
Building on the above, a card that shows low battery entities adds a little bit more complexity. This will use the same starting part of the card.
filter:
include:
- domain: sensor
options:
secondary_info: last-changed
attributes:
device_class: battery
state: <= 15
The above changes to only pick up from sensors which are of class battery. The secondary info displays additional information in an entities card of when the state was last changed.
the state under the domain section filters on the a value reported back by the entity. In the example above, anything with 15(%) or less will be included in the auto-entities card. Along with the show_empty: false the card will only be visible if there is an entity with 15% or less.
Next is to sort the entities in descending (reverse) order so that entities with the lowest battery will appear at the top.
sort:
method: state
reverse: true
nurmeric: true
The should above sets the sort order based on the state, in reverse order and the thing it is sorting on (state) is a number.
The addon is a little more complicated than some of the out of the box cards but it is also very powerful once you can see how the filters and sorting work. Additional things I've used it for are where there is water detected when there should not be and when lights are turned on.
Open windows and doors:
type: 'custom:auto-entities'
card:
type: entities
title: Open Entrances
filter:
include:
- domain: binary_sensor
options:
secondary_info: last-changed
state: 'on'
attributes:
device_class: window
- domain: binary_sensor
options:
secondary_info: last-changed
state: 'on'
attributes:
device_class: door
exclude:
- entity_id: '*blind*'
show_empty: true
sort:
method: state
ignore_case: true
type: 'custom:auto-entities'
card:
type: entities
title: Low Batteries
filter:
include:
- domain: sensor
options:
secondary_info: last-changed
attributes:
device_class: battery
state: <= 15
show_empty: false
sort:
method: state
reverse: true
ignore_case: true
nurmeric: true