🔹 Auto-entities - Automatically fill cards with entities

I achieve it by doing the following:

...
          filter:
            include:
              # washing machine completion time
              - entity_id: sensor.washing_machine_state
                state: "run"
                options:
                  entity: sensor.washing_machine_completion_time

So basically, if the washing machine state is run, it displays the state of sensor.washing_machine_completion_time

Thanks @ASNNetworks making me dig a bit :grinning:

2 Likes

I have a bunch of sensors named sensor.dals_*. Each of these have a attribute called script. I want to call that script when I click on the sensor in the lovelace card.

Any idea on how the code needs to look like?

Hi i will add a auto-entitie that the switch will show on workdays from 08:00 /08:30 But how i don’t now…

Uhm, so…noone has any hints/ideas?

I want to know how to do this as well…

how can I do this:

  - type: custom:auto-entities
    card:

    filter:
      include:
        - group: group.z_wave_switches
          options:
            type: vertical-stack
            cards:
              - type: custom:decluttering-card
                template: update_zwave_switches
                variables:
                  - id: *object _id of switch in the group*

this is a work in progress, so the top card is not yet set, (do I need the vertical stack there, or ?).

to give you an idea what the manually configured stack look like for a couple of entities:

  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: afzuigkap_zolder

      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: amp_right_auditorium

      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: dorm_studenten

      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: freezer_garage

      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: freezer_bijkeuken

where each decluttering card is a horizontal stack of 3 button cards :wink:

cut it short: I need to template the object_id’s of each group member and auto fill these in the decluttering card

something like this pseudo-code:

  - type: custom:auto-entities
    card:
      type: vertical-stack
      cards:
        - type: custom:decluttering-card
          template: update_zwave_switches
    filter:
      template: |
        {{ expand('group.z_wave_switches') | map(attribute='object_id') | list }}

hope this is clear…

Why not use grid card with column: 3 as option instead of vertical+horizontal? And then decluttering card as the card inside it using filter, which will give a grid with 3 button cards horizontally.

yes, I could do that too, my config is from before the grid card :wink:
will try and rebuild that, might be better. thanks for the suggestion.

but my main question is not about the layout, it is about the selection of the entities, and how to use the object_id in the auto-entities cards filter / decluttering-card

  - type: custom:auto-entities
    filter:
      include:
        - group: group.z_wave_switches
    card:
      type: vertical-stack
      cards:
        - type: custom:decluttering-card
          template: update_zwave_switches
          variables:
            - id: this.object_id

doesnt work but gives a better Idea maybe…

Use case: I have several custom:auto-entities inside an entities card. If none of the auto-entities show up, I have a blank entities card.

Q: How can I hide the whole card, if none of the auto-entities cards inside that card show anything?

example:

type: custom:auto-entities
card:
  type: entities
  title: 🚪 Türen, Fenster & Co
  state_color: true
  show_header_toggle: false
show_empty: false
entities:
  - type: custom:auto-entities
    [...]
  - type: custom:auto-entities
    [...]
  - type: custom:auto-entities
    [...]
    show_empty: false
    unique: true
    sort:
      method: last_changed
      reverse: true

If you want someone to help you, you should simplify a task.
200 lines in your code.
image
Start with TWO simple lists in your entities card.

The sense of the code is just to visualize what my words were talking about :smiley:
Should be much easier to read meanwhile. Now I´m sure the help will come shortly :wink:

Then do not put auto-entities INSIDE entities card:

  - type: custom:auto-entities
    card:
      type: entities
      title: some title
      state_color: true
    unique: false
    show_empty: false
    filter:
      include:
        - entity_id: sensor.ac68u_snmp_mem*
          options:
            secondary_info: last-changed
          sort:
            method: name
            reverse: false
            ignore_case: true
        - entity_id: sensor.cleargrass_1_*
          options:
            secondary_info: last-changed
          sort:
            method: state
            reverse: false
            numeric: true
        - entity_id: sensor.cleargrass_2_*
          options:
            secondary_info: last-changed
          sort:
            method: state
            reverse: false
            numeric: true

There are three lists inside.
In your case you will probably get an empty card since you do not have entities sensor.ac68u_snmp_mem*, sensor.cleargrass_1_*, sensor.cleargrass_2_*.

As I need a title for each list (for each custom:auto-entities) I think I need to put them inside an entities card. This is what you could (have) see(n) in my initial post with full yaml code (200 lines, you remember :-D).

TITLE FOR WHOLE CARD
- Subtitle (Title of auto-entities card)
... List elements
... List elements
...
- Subtitle (Title of auto-entities card)
... List elements
... List elements
...
- Subtitle (Title of auto-entities card)
... List elements
... List elements
...

Where´s the difference in your code snippet compared to mine?
You use single entities within ONE auto-entities card, I need to nest several of them because I visually combine several lists to one card.

Again, main question: How can I hide the whole card, if none of the auto-entities cards inside that card show anything?

Hope I described the issue good enough.

Strange you do not see the difference.
You got Auto-entities inside Auto-entities…
Dream inside a Dream (“Inception”)

Then there is no solution.

Surely you may put "type: section" rows before each list - but then only these rows are displayed if lists are empty - and then the card will be displayed too since the WHOLE list is not empty.

If it´s really not possible to hide the card when no lists elements exist (still doubt it)…

Why can auto-entities not realize there´s no element (consisting of nested, empty sub auto-entities) @thomasloven? This is working on the first level, so just wondering.

You may try to achieve this by using template option of auto-entities card.
Actually, LOT OF THINGS are possible with a template. Just learn & do…

Sorry for repost, but…

I have a question. I want to achieve somewhat simple setup. I want to have fold entities auto populated with auto entity like here:

obraz
But with toggles for the sections.

I played with static fold entity and was able to get what’s in the screenshot but I don’t know how to use auto-entity to get entities for the fold row.

I know I could have the toggle for the section if I would for example create light group with all entities for area but I was thinking if there is a way to do it without this step.

Just a tip… I tried to make more items fit in a small space.

FROM:


TO:
image

This is the css-mod item I added to the code:

type: custom:auto-entities
card:
  type: entities
  style: |
    #states > div {
      margin: -15px 0px;
    }

To capture the individual divs under <div id="state"> you have to add “> div” in the css.

Other example: with secondary info (note that the coloring does not work like this. the screenshot was colored with the browser inspector)

image

type: custom:auto-entities
card:
  type: entities
  style: |
    #states > div {
      margin: 0px 0px;
    }
    .secondary, ha-relative-time {
      color: #ed2323;
    }

Cheers
DJ

1 Like

I really love the idea of auto-entities and this is an awesome card!

I was creating a card in another thread using apexcharts-card and custom-config-card to create a dynamically changeable plot Dynamic selection.

The only downside being, that I have to manually define the input_select.sensors_to_show. I think this is were auto-entities could come in and make this far more convenient and future proof.

Would it be possible to use auto-entities to define variables on-the-fly?

My idea was:

  • Create an input_select with the includes for auto-entities (e.g. ‘area’, ‘sensors’, ‘devices’ etc.). These are static anyway and do not change when adding new devices.
  • Use this input_select as include parameter for auto-entities. Auto-entities would then create a list of e.g. all areas
  • Create a variable of the auto-entities list and forward it to the next card.

Would this be possible?
My current code is

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_select.days_back_to_show
        name: Number Of Days To Show
      - entity: input_select.sensors_to_show   #this is what auto-entities would need to supply
        name: Select Sensor
  - type: custom:config-template-card
    entities:
      - input_select.days_back_to_show
      - input_select.sensors_to_show
    variables:
      sensor: states['input_select.sensors_to_show'].state
      span: states['input_select.days_back_to_show'].state+'d'
      days: |
        -states['input_select.days_back_to_show'].state+'d'+'1d'
    card:
      type: custom:apexcharts-card
      graph_span: ${span}
      span:
        start: day
        offset: ${days}
      series:
        - entity: ${sensor}
          stroke_width: 2
          group_by:
            func: raw

EDIT:
I think it should be something along the lines of this, but I am not sure how auto-entities passes on the entities it uses, so I am not sure if it can populate a series.

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_select.days_back_to_show
        name: Number Of Days To Show
  - type: custom:auto-entities
    card:
      type: custom:config-template-card
      variables:
        sensor: states['input_select.sensors_to_show'].state
        span: states['input_select.days_back_to_show'].state+'d'
        days: |
          -states['input_select.days_back_to_show'].state+'d'+'1d'
      card:
        type: custom:apexcharts-card
        graph_span: ${span}
        span:
          start: day
          offset: ${days}
        series:
#          - entity: ${sensor}    this would need to be populated
            stroke_width: 2
            group_by:
              func: raw
              #duration: 1min
    entities:
      - input_select.days_back_to_show
    filter:
      include:
        - domain: sensor