šŸ”¹ Auto-entities - Automatically fill cards with entities

Where do you want to use it?

In a card with all the containers from the Monitor Docker integration.
The goal is to have an on/off button to start/stop the containers.
For instance, for a container named gitea, this.entity_id will return ā€œsensor.docker_pve01_giteaā€. The switch to start/stop this container will be ā€œswitch.docker_pve01_giteaā€. So I needed something like switch.this.entity_name

I was doing it with several copy pasts entries (one for each container), but now I am trying to do it automagically with auto-entities. It is already working for the container information, but I need to find a solution for the start/stop command.

Hereā€™s an example:

  - card:
      show_header_toggle: false
      type: entities
    filter:
      include:
        - entity_id: sensor.docker_pve01_*
          attributes:
            status: '! '
          options:
            type: custom:multiple-entity-row
            show_state: false
            state_color: true
            secondary_info:
              attribute: status
              name: false
            entities:
              - attribute: memory
                name: false
                format: precision0
                unit: Mb
              - attribute: 1cpu_percentage
                name: false
                unit: '%'
                format: precision0
              - icon: mdi:power-standby
                state_color: true
                name: false
                toggle: true
                entity: this.entity_id
                tap_action:
                  action: toggle
                  confirmation:
                    text: 'Are you sure?'
    sort:
      method: last_changed
    show_empty: false
    type: custom:auto-entities```

So, you need to put ā€œswitchā€ entity instead of that ā€œthis.entityā€?

this.entity is always sensor.something1, sensor.something2, etc.

What I need is switch.something1 for the sensor.something1, switch.something2 for the sensor.something2, etc.

There are two options:

  1. Use a ā€œtemplateā€ option (find my example for multiple-entity-row here).
  2. Create a script and pass this.entity as an input variable. This script should use this variable to ā€œcreateā€ an entity_id for a switch and then toggle it.

I would choose the 1st option.

Is there a way to set the precision of entity-values ?

      - type: custom:fold-entity-row
        head:
          entity: sensor.em_qbus_l123_power
          name: Verlichting en domotica
          icon: mdi:lightbulb-on
        entities:
          - type: custom:auto-entities
            show_empty: true
            card:
              type: entities
            filter:
              include:
                - group: group.em_qbus_l123_power
            sort:
              method: name

All the entities in the group expand, but are shown with all the available digits, while the sensor in the head is with precision 0 (since I rounded this in the template that creates this sensor).

It would be nice that I can choose to set the precision for all the expanded entities also to 0.

Schermafbeelding 2022-06-12 om 10.12.44

In my groups.yaml I have

em_qbus_l123_power:
  name: QBus L1 L2 L3 Power
  icon: mdi:plus-box-outline
  entities:
    - sensor.em_qbus_l1_power
    - sensor.em_qbus_l2_power
    - sensor.em_qbus_l3_power

My template for the sensor in head:

sensor:
  - platform: template
    sensors:
      em_qbus_l123_power:
        friendly_name: QBus L1 L2 L3 Power
        unit_of_measurement: W
        device_class: power
        icon_template: mdi:plus-box-outline
        value_template: >
          {{expand('group.em_qbus_l123_power')|map(attribute='state')|map('float', 0)|sum|round(0)}}

The auto-entities card gathers items together - nothing more, like:

  1. Rows inside Entities card - conventional entity rows, custom rows like multiple-entity-row.
  2. Cards inside a stack.
  3. Graphs inside some graph card.
  4. Items inside Glance card.
  5. ā€¦

It is not supposed to customize a particular item - it may just pass ā€œoptionsā€ to this item.
What you are asking is just for a conventional entity rows - i.e. for customizing an item of a specific kind.
This functionality should be implemented as a part of a standard formatting. Currently it does not support a precision - then you may create an FR for HA frontend only (((.

Iā€™m pretty sure you can use another of Tomas LovĆ©nā€™s custom cards for this: template-entity-row.

It would allow you to template the entity state, and round the displayed value.

Hereā€™s an example I use to filter updater entities, where I use templates to change the display name, and show latest and available versions. The important bit for you to try to emulate would be under the options key, making use of the config.entity variable which is a feature of the template-entity-row card:

- type: custom:auto-entities
  card:
    type: entities
  show_empty: false
  filter:
    include:
      - domain: update
        entity_id: "*addon_*"
        state: "on"
        options:
          type: custom:template-entity-row
          name: "{{ state_attr(config.entity, 'friendly_name').split(':',1)[0] }}"
          state: "New: {{ state_attr(config.entity, 'latest_version') }}"
          secondary: "Current: {{ state_attr(config.entity, 'installed_version') }}"
  sort:
    method: name
1 Like

Another option could be just changing original template sensors (apply ā€œround(xxx)ā€).
If it is not a template sensor (i.e. a sensor from some integration) - then yes, using template-entity-row could be a better decision.

P.S. One thing which I like about template-entity-row - freedom for ā€œstateā€ & ā€œsecondaryā€ properties, you may write what you want.
And one thing which I dislike about template-entity-row - you need to specify labels like " W", " ago".
Two sides of one coin.

something like this?

      - type: custom:fold-entity-row
        head:
          entity: sensor.em_qbus_l123_power
          name: Verlichting en domotica
          icon: mdi:lightbulb-on
        entities:
          - type: custom:auto-entities
            card:
              type: entities
            show_empty: false
            filter:
              include:
                - group: group.em_qbus_l123_power
                  options:
                    type: custom:template-entity-row
                    name: >
                      {{state_attr('?????','name')}}
                    icon: >
                      {{state_attr('?????','icon')}}
                    state: >
                      {{ round ( ???? ) }}

I know Iā€™m missing key elements :slight_smile:
The thing is, since Iā€™m expanding a group, I really have no idea what to put thereā€¦

Btw, have you seen this?
There are 2 ways of using auto-entities inside fold-entity-row, your way will create kind of ā€œEntities card inside Entities cardā€ - i.e. with additional paddings.

Not 100% sure this will work, but try using the expand function on your group, and then replace your question marks with config.entity i.e.:

filter:
  include:
    -  template: {{ expand('group.em_qbus_l123_power') | map(attribute="entity_id") | list }}

For the entity state, it might be something like {{ states(config.entity) | round(1) }}. Unless you want to change the name and icon from the default for each entity, you can just leave those definitions out.

Thank you so much, everyone.

      - type: custom:fold-entity-row
        head:
          entity: sensor.em_qbus_l123_power
          name: Verlichting en domotica
          icon: mdi:lightbulb-on
        entities:
          - type: custom:auto-entities
            card:
              type: entities
            show_empty: false
            filter:
              include:
                - group: group.em_qbus_l123_power
                  options:
                    type: custom:template-entity-row
                    state: >
                      {{ states(config.entity) | round(0), ' W'}}
            sort:
              method: name

the one on top is the initial result, the one on the bottom after your help. Just adding 4 lines did the trick. :beer: for everyone !
Schermafbeelding 2022-06-12 om 14.32.53

2 Likes

Hi All,
I resolved a problem, but now I want to create a icon where there is the total / count light On, where it is exclude light type: browser_mod.
Is it possible ?
Thank You

type: custom:auto-entities
show_empty: true
card:
title: Light On
type: entities
entities: null
filter:
exclude:
- domain: light
attributes:
type: browser_mod
include:
- domain: light
state: ā€˜onā€™
sort:
method: name

Iā€™d like to create list of Plex media players and the time remaining on each.

Like this, but showing ā€œtime remainingā€ instead of show controls. Or in addition to controls, I donā€™t really care.

Hereā€™s how I created this:

As each new Plex client (e.g. iPhone, iPad, Roku, etc) on my network starts playing something, the Plex integration seems to dynamically create a new ā€œmedia_playerā€ device. That device doesnā€™t have a ā€œremaining_timeā€ attribute, but it DOES have a ā€œmedia_durationā€ attribute and a ā€œmedia_positionā€ attribute. I could just subtract ā€œpositionā€ from ā€œdurationā€ to get remaining. Easy enough, I guess. To get that to show up on a Lovelace dashboard, I THINK I need to create a template sensor. But how to do I dynamically create a new template sensor each time a new Plex device is discovered on my network ?

I guess Iā€™m supposed to create a new template sensor for each Plex media player, but feels laborious to do that because there could be 15-20 plex players on my network (e.g. iPhone, iPads, etc)

Feels like there must be a dynamic way to create a template sensor to calculate remaining time on each device ?

Cannot test it by myself - but imagine a card:

type: entities
entities:
  - entity: media_player.player_1
  - type: custom:template-entity-row
    state: >-
      template to calc "time remaining" for player_1

  - type: section

  - entity: media_player.player_2
  - type: custom:template-entity-row
    state: >-
      template to calc "time remaining" for player_2
  
  - type: section

  ... and so on

You should create 2 lines (for media_player & template-entity-row) in a loop (separated by a section) by using a ā€œtemplateā€ option of ā€œauto-entitiesā€.

I would also need the state, so script may not be the best option.

As for the template, I already tried but without success. Can someone help me with other examples? thanks.

Show us the code you tried.

I have nothing to show because I couldnā€™t find a way to use the template-entity-row inside the multiple-entity-row.

Surely it is not possible.
What I already advised you - create a list of multiple-entity-row by the template option and specify an entity for the action.

1 Like