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

Hey all. Any idea why this filter is including items with the status ā€œReplaceā€, but not those with the status ā€œyellowā€ or ā€œoffā€? Iā€™ve double and triple checked in the dev tools state to make sure I was using exactly the right string as what I defined, but it just seems to like some and not others.

  - type: custom:auto-entities
    show_empty: false
    card:
      type: entities
      title: Devices Reporting Problems
      show_header_toggle: false
    filter: 
      include: 
        - entity_id: "*nest*"
          state: "unavailable"
          state: "Warning"
          state: "grey"
          state: "yellow"
          state: "off"
          state: "dead"
          state: "disconnected"
          state: "warning"
          state: "critical"
          state: "failing"
          state: "access error"
          state: "Replace"

Only the last "state" works.
Try kind of this:

filter:
  include:
    - entity_id: "*nest*"
      or:
        state: "unavailable"
        state: "Warning"
        state: "grey"
...
1 Like

Thank you! That got me on the right track! It turns out that the correct syntax ends up being:

  - type: custom:auto-entities
    show_empty: false
    card:
      type: entities
      title: Devices Reporting Problems
      show_header_toggle: false
    filter: 
      include: 
        - entity_id: "*nest*"
          or: 
            - state: "unavailable"
            - state: "Warning"
            - state: "grey"
            - state: "yellow"
            - state: "off"
            - state: "dead"
            - state: "disconnected"
            - state: "warning"
            - state: "critical"
            - state: "failing"
            - state: "access error"
            - state: "Replace"
    show_empty: false
1 Like

@thomasloven The following works.

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - type: custom:fold-entity-row
      head: binary_sensor.system_ready
      entities:
        - input_boolean.allow_automation_execution
        - sensor.hx711_custom
        - sensor.mba_humidity
        - sensor.mba_temperature
    - entity_id: sensor.pen*
  exclude: []
sort:
  method: none

But is it possible to use wildcards inside the folded row by changing:

        - sensor.mba_humidity
        - sensor.mba_temperature

to

        - sensor.mba_*

Need help with a template.

Here is an auto-entities list of "device_tracker" entities with "card_mod":
image

  - type: custom:auto-entities
    card:
      type: entities
      title: fixed color
    filter:
      template: |
        {% for DEVICE in states.device_tracker -%}
          {%- if is_state_attr(DEVICE.entity_id,"source_type","router") -%}
            {{
              {
                'entity': DEVICE.entity_id,
                'card_mod':
                  {
                  'style':
                    ':host {
                      --paper-item-icon-color: red;
                    }'
                  }
              }
            }},
          {%- endif -%}
        {%- endfor %}
    sort:
      count: 7

Now letā€™s try to create a conditional color, something like this:

                :host {
                  --paper-item-icon-color:
                  {% if ... %}
                  brown;
                  {% elif ... %}
                  red;
                  {% else %}
                  green;
                  {% endif %}
                }

This "if ... else ..." code cannot be used inside a "{{ ... }}" template.
So letā€™s define the color outside the "{{ ... }}" template.
First, letā€™s use some fixed color defined by using "set".
image

  - type: custom:auto-entities
    card:
      type: entities
      title: conditional color
    filter:
      template: |
        {% for DEVICE in states.device_tracker -%}
          {%- set COLOR = 'red' -%}
          {%- if is_state_attr(DEVICE.entity_id,"source_type","router") -%}
            {{
              {
                'entity': DEVICE.entity_id,
                'card_mod':
                  {
                  'style':
                    ':host {
                      --paper-item-icon-color: COLOR;
                    }'
                  }
              }
            }},
          {%- endif -%}
        {%- endfor %}
    sort:
      count: 7

Does not work. Letā€™s check in in the ā€œTemplatesā€ window:

{'entity': 'device_tracker.00_17_5a_23_94_49', 'card_mod': {'style': ':host {\n                      --paper-item-icon-color: COLOR;\n                    }'}},
......

Seems that the "COLOR" variable is not recognized as a variable - it is recognized as a string ā€œCOLORā€ - probably because of using '.
The question - how to pass this "COLOR" value inside the template as a variable?

This code works - for the "name" property (here I do not need to use the '):

        {% for DEVICE in states.device_tracker -%}
          {%- set COLOR = 'red' -%}
          {%- if is_state_attr(DEVICE.entity_id,"source_type","router") -%}
            {{
              {
                'entity': DEVICE.entity_id,
                'name': COLOR
              }
            }},
          {%- endif -%}
        {%- endfor %}

Also tried this, gives an error:

        {% for DEVICE in states.device_tracker -%}
          {%- set COLOR = 'red' -%}
          {%- if is_state_attr(DEVICE.entity_id,"source_type","router") -%}
            {{
              {
                'entity': DEVICE.entity_id,
                'card_mod':
                  {
                  'style':
                    ':host {
                      --paper-item-icon-color: '}} {{COLOR}} {{';
                    }'
                  }
              }
            }},
          {%- endif -%}
        {%- endfor %}

Updated: SOLVED!!!

                'card_mod':
                  {
                  'style':
                    ':host {
                      --paper-item-icon-color:' + COLOR + ';
                    }'
                  }
2 Likes

since you are not using a color template, and simply always return ā€˜redā€™, why not use

                'card_mod':
                  {
                  'style':
                    ':host {
                      --paper-item-icon-color: red;
                    }'
                  }

?

btw, I believe I used this before in another place, doesnt that work anymore:

                style: |
                  :host {
                    --paper-item-icon-color:
                      {% set id = config.entity.split('.')[1] %}
                      {% set repo = 'input_boolean.' + id %}
                      {{'gold' if is_state(repo,'on') else 'green'}}
                      ;
                   }

As I wrote above, I wanted to use a conditional color:

                :host {
                  --paper-item-icon-color:
                  {% if ... %}
                  brown;
                  {% elif ... %}
                  red;
                  {% else %}
                  green;
                  {% endif %}
                }

But I cannot write smth like (template in template):

...
{{
...
                :host {
                  --paper-item-icon-color:
                  {% if ... %}
                  brown;
                  {% elif ... %}
                  red;
                  {% else %}
                  green;
                  {% endif %}
                }
...
}}
..

So I need to define the "COLOR" outside the "{{ ... }}" code.
And I started with a simple case:

...
{%- set COLOR = 'red' -%}
...
{{
... use COLOR
}}
...

The final goal is:

..
{%- if ... -%}
{%- set COLOR = 'brown' -%}
{%- elif ... -%}
{%- set COLOR = 'red' -%}
{%- else -%}
{%- set COLOR = 'green' -%}
{%- endif -%}
...
{{
... use COLOR
}}
...
1 Like

think I remember now. the card-mod I posted above did work just fine, but only on refresh of the view. I think.

using custom-ui makes it instantaneous ā€¦

    sensor.github_*:
      templates:
        icon_color: >
          var id = entity.entity_id.split('.')[1];
          var repo = 'input_boolean.' + id;
          if (entities[repo] && entities[repo].state == 'on') return 'gold';
          return 'green';

Good point of using something like Custom UI to define things like icon, iconā€™s color in ONE place solves a lot of problem - I do not need to code a style everywhere.
Have not started yet to learn Custom UI - will ask for your advice regarding it a bit later when will be ready, thank you very much for help))

I have a rather challenging question. Is it possible (maybe with a template) to filter out entities based on name BUT only show the first match?

For example: when I pair a Zigbee device, like a button or light, it has multiple entities with extra sensors. They all share the first part of the name, for example 0x0017880108f72158. But they all has something behind it, like 0x0017880108f72158_action and 0x0017880108f72158_battery.

What I would like to do is to catch the first entity/name that matches the friendly name that has that part in the name. It doesnā€™t matter which one matches, as long as it just takes ONE and ignores the rest.

Now here is the challenging part: the name 0x0017880108f72158 is different each time. So I want to use:

filter:
  include:
    - name: 0x*

But then filter so it only shows the first one that matches a name, that the others also have. For now I use the sort option count, but then I only get one if there are multiple devices (so that have a completely different name starting with 0x*.

Is something like this possible? Basically: match 0x* but only one per match, if that makes any sense.

Hello!

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.

Nonetheless, fantastic work as always. I just love to get back to some of the cards and see how far theyā€™ve come since last time I played with them :slight_smile:

1 Like

Can someone please tell me why I get a no service has been selected with this code?

      - type: custom:auto-entities
        show_empty: false
        card:
          type: entities
          title: Sensors
        filter:
          include:
            - entity_id: "sensor.dals_*"
              state: "on" # Remember that "on" and "off" are magic in yaml, and must always be quoted
              options:
                tap_action:
                  action: call-service
                  service_template: "{{ state_attr('this.entity_id', 'script') }}"             ```

Because, just like it says, no service has been selected. You have an action and a service_template. You still need to add a service veriable in the tap_action: Scripts - Home Assistant

Hello,

I would like to display an entity only if another entity has a specific state (here, I would like to display my washing machineā€™s completion time only if the washing machine is running).

Here is a small example/try:

        - type: custom:auto-entities
          card:
            type: entities
            ...
          filter:
            include:
              - entity_id: sensor.washing_machine_completion_time
                state: "{{ is_state('sensor.washing_machine_state', 'run') }}"

I tried to filter with state or template, but this is not working. As far as I understand, there is no way to do that, but Iā€™m wondering if somebody did it ?

Thanks,

Thomas

Why do you use auto-entities for this if your goal is to show one specific entity based of the state of one other specific entity? Just use conditional card instead.

If you want multiple entities to show based on the state of one specitic entity, use a conditional card and then the auto-entities card as the card in there.

Well, this is just a minimal example, I have about 20 others filter (like low battery, low signal, HA updates, meteoalarm, etc.)

You could try using a conditional card inside the auto-entities as one of the includes. If that doesnā€™t work, you can always try config-template-card, which allows you to pass on variables through any card. I use that myself for some cards that donā€™t allow templating.

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ā€¦