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

So, it looks like you are trying to get a count of lights that are on. But, you start with a list of areas with lights on.

I believe you have two areas with lights on. So, for each of those in the loop, you will get a count for {{ entities | length }}.

Your first area has 5 lights on and the second has 1 light on.

If you are going to keep this path of doing it, you will need a counter to add each length to.

If you do just want to get a count of lights on, you could use

{% set lights_on = states.light | selectattr('state','eq', 'on') | list | length -%}
{{ lights_on }}

You could put your reject entity list back in there. I kept it out to be clean.

so how would i do this?

It depends on what you want your final output to be. You will need to explain that for an answer.

i want to have the exact same script that i posted.
and the output should be a single number instead of one number for every area.

so even if i would have 3 areas it should still be a single number.

otherwise i would need a script to get the count of all lights which have the state ā€˜onā€™ and are assigned to an area (not to none)

i think your script would give me all lights even if they are not assigned to an area

{%- set ns = namespace(lights_on = 0) -%}
{%- set areas = states.light | selectattr('state','eq', 'on') | map(attribute='entity_id') | unique | reject('none')  | list -%}
{%- for area in areas  -%}
  {%- set entity_filter = '' -%}
  {% set entities = states.light | selectattr('state','eq', 'on') | selectattr('entity_id', 'in', area_entities(area)) | rejectattr('entity_id', 'in', entity_filter) | list -%}
  {%- set ns.lights_on = ns.lights_on + entities | length -%}
  {%- for entity in entities -%}
  {%- endfor -%}
{%- endfor -%}
{{ ns.lights_on }}

This thread might give you another path or idea though
Templating: filter list of entities by area? - Configuration - Home Assistant Community (home-assistant.io)

this gives me an outout of 0. so i think its not working.

i think i know where to look around with that namespace. i will give it a try and test around. but would still be cool if you could check your code.

Oops. I pulled something out of yours when testing.

Try

{%- set ns = namespace(lights_on = 0) -%}
{%- set areas = states.light | selectattr('state','eq', 'on') | map(attribute='entity_id') | map('area_name') | unique | reject('none')  | list -%}
{%- for area in areas  -%}
  {%- set entity_filter = '' -%}
  {% set entities = states.light | selectattr('state','eq', 'on') | selectattr('entity_id', 'in', area_entities(area)) | rejectattr('entity_id', 'in', entity_filter) | list -%}
  {%- set ns.lights_on = ns.lights_on + entities | length -%}
  {%- for entity in entities -%}
  {%- endfor -%}
{%- endfor -%}
{{ ns.lights_on }}
1 Like

this works :slight_smile: thank you!

1 Like

hi just me again. do you know how i can change the card of the output in that template?

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: >-
    {% set ns = namespace(entity_and_area=[]) -%} {%- for entity in states.light
    | selectattr('state','eq','on') -%}
      {%- set entity_id = entity.entity_id -%}
      {%- set area = area_name(entity.entity_id) -%}
      {%- set entity_and_area = ({'entity_id':entity_id,'area':area}) -%}
      {%- set ns.entity_and_area = ns.entity_and_area + [entity_and_area] -%}
    {%- endfor -%} {%- set sorted_list = (ns.entity_and_area) |
    rejectattr('area','eq',none) | sort(attribute='area') | map(attribute='entity_id') | list -%}  
     {{sorted_list}}

image

so it shouldnt be a simple entity card but the type custom:mushroom-light-card for example?

EDIT: got it by putting a for loop under it

Hi All,

I posted this on the mushroom card pages as my question relates to combining a few different pieces - not sure if I should be posting here, but will try the author of the unavailable-entities if no luck here.
What Iā€™m trying to achieve is a combination of using the auto-enties card, with a sensor template listing unavailable entities along with a mushroom card and card-mod formatting.
Here is the (current) code Iā€™ve tried along with a screenshot of the result:

type: custom:auto-entities
card:
  type: entities
filter:
  template: "{{ state_attr('sensor.unavailable_entities','entity_id') }}"
options:
  type: custom:mushroom-entity-card
  vertical: true
  tap_action: null
  action: more-info
  card_mod:
    style:
      mushroom-shape-icon$: |
        .shape {
            outline: var(--disabled-text-color) 1.5px solid;
           --icon-color: orange !important;
           --icon-color-disabled: var(--disabled-text-color) !important;
           --shape-color-disabled: var(--primary-background-color) !important;
           --shape-color: rgb(35,35,41) !important;
        }    
      sort:
      method: state

Any variation of code either results in the layout in the SS or an error saying no card configuredā€¦Iā€™ve spent several hours looking at other posts on the various pages, some which have seemed relevant, but none that I could get to workā€¦
Iā€™d really apprecaiate if someone could point me in the right directionā€¦
thanks in advance

Or, make it simple

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - domain: light
      state: 'on'
      area: '*'
      options:
        type: custom:mushroom-light-card

first: you have a wrong indent: (look at action:)
secondly: seems like you as above poster neither read the github-documentation
third: you donā€™t have any include, your mushroom wont be applied, beside your card-mod does nothing.
fourth: Use The Power of Auto-entities ( thatā€™s what itā€™s build for )

  include:
    - entity_id: '*'
      state: 'unavailable'

Hopefully somebody can help me out here because Iā€™m beating my head against a wall.

I want to have a hold action on my scenes to add/remove them from a favorites list.
I can easily add the hold_action option when I use the ā€œincludeā€ filter. But for the life of me I canā€™t figure out how to do this for a template.

Here is my card yaml:

type: custom:auto-entities
card:
  type: entities
  title: Favorite Scenes
filter:
  template: >
    {% set scene_options = state_attr('input_select.favorite_scenes', 'options') %} 
    {% for option in scene_options %}
      scene.{{ option | replace(' ', '_') | lower }}
    {% endfor %}

Is there a way I can add a hold action to this template?

Thanks!

thanks for taking the time to reply - much appreciated

first: you have a wrong indent: (look at action:) - thanks again, had not picked that up :frowning:

secondly: seems like you as above poster neither read the github-documentation - if youā€™re referring to the auto-entities github, then yes I have read it, but do not claim to understand all of it - is there a particular section that youā€™re referring to?

third: you donā€™t have any include, your mushroom wont be applied, beside your card-mod does nothing - correct it does not have an include - Iā€™m trying to build the code based on this example, which does work, and also does not have an include

fourth: Use The Power of Auto-entities ( thatā€™s what itā€™s build for ) - as above I have the ā€œincludes & excludesā€ in a template sensor - just trying to streamline the yaml

Ok, however your code, doesnā€™t looks anywhere near/like the code-example you refers to. ( i.e no mushroom-card(s), however a "base-card / type: custom:fold-entity-row "
It also donā€™t have an ā€œoptionā€ tag

And i believe there are simple example codes, in the cards-github-page, which people can start with, to get an understanding of how the card works.
Beside if you look at my answer to you, and above poster, you got all ā€œingredientsā€ to accomplice, what your are asking for.

Yes iā€™ve seen other examples where people using template-sensors ( free choice ) and not needed for i.e a simple solution, as you are asking for

Top to Bottom , donā€™t scroll to fast through the examples, they tell/show in pictures whats stated in the text

PS: try to ā€œtabā€ in your Options-section

Hi Thomas,
I have a card set up with show_empty:false, but it still shows up when there are no results.
The card is meant to show up when there are HACS updates due, but go away when there are none.
I have a template entity defined for this:

hacs_integrations_updates_due:
  value_template: "{% if states.sensor.hacs.attributes.repositories %} {{ states.sensor.hacs.attributes.repositories | map(attribute='name') | join('\n')  }} {% else %}{% endif %}"

And hereā€™s my auto-entities card config:

type: custom:auto-entities
card:
  type: entities
  title: auto_entities
show_empty: false
filter:
  include:
    - entity_id: sensor.hacs_integrations_updates_due

What have I missed? Do I need to put something like ā€œNULLā€ in between the Else and Endif in my template?

Thanks!

Hello everyone

Iā€™m trying to put together a small gaming dashboard with Steam shortcuts. This works quite well with auto entities mushroom and card mod. But what I canā€™t quite manage are the automatic background images for the mushroom cards. if I set them statically, it works, but not dynamically.

With the mushroom image it works with the variable, but not with the background:

type: custom:auto-entities
filter:
  include:
    - entity_id: '*game_*'
      device: TEST
      name: '*Favorites*'
      options:
        type: custom:mushroom-template-card
        primary: ''
        secondary: ''
        picture: >-
          https://cdn.cloudflare.steamstatic.com/steam/apps/{% set str =
          state_attr(entity, 'friendly_name') %}{% set sub = str.split('_')[2]
          %}{{sub}}/header.jpg
        tap_action:
          action: toggle
        layout: vertical
        card_mod:
          style: |
            ha-card {     
             
                background-image: url('https://cdn.cloudflare.steamstatic.com/steam/apps/{% set str = state_attr(entity, 'friendly_name') %}{% set sub = str.split('_')[2]%}{{sub}}/header.jpg')!important;
               
                }
sort:
  method: friendly_name
card:
  square: false
  type: grid
  columns: 7
  title: Favorites
card_param: cards
show_empty: true
view_layout:
  position: main

2024-03-01 22_47_26-Gaming ā€“ Home Assistant

How could I solve this?

Hello Community!

Iā€™m quite new on Home Assistent so apologies for my noob question!

Iā€™m trying to combine 2 cards / features and stuck on the fact, if its possible to use the result (entities) from the Auto-entities in a new card?

Example:

type: custom:auto-entities
filter:
  include:
    - name: '*Rollladen*'
      options: {}
  exclude:
    - entity_id: /sensor*
    - entity_id: /button*
    - name: Alle RolllƤden
      options: {}
show_empty: false
sort:
  reverse: false
  ignore_case: false
  ip: false
card:
  type: horizontal-stack
  cards:
    - type: custom:shutter-card
    - type: custom:shutter-card

Result:
image

The horizontal-stack is mandatory, otherwise the shutter will be shown vertically.

Iā€™m wondering if its possible to use this in any way / respectively to use the auto-entities to hand over the result to the shutter-card in a horizontal-stack type?

Source:https://github.com/Deejayfool/hass-shutter-card and https://www.home-assistant.io/dashboards/horizontal-stack/

Any ideas are welcome! Thank you in advance! :crossed_fingers:

try to use below:

          - type: custom:auto-entities
            card:
              square: false
              columns: 2
              type: grid
            card_param: cards
            filter:
              include:
                 - name: '*Rollladen*'
                   options:
                     type: custom:shutter-card
                     icon_color: '#87bf50'
                     etc.
                     etc.
                     etc. = configs your shutter-card support
1 Like

Thank you for the fast reply!
Unfortunately I get No type provided - config below:

- type: custom:auto-entities
  card:
    square: false
    columns: 2
    type: grid
  card_param: cards
  filter:
    include:
      - name: '*Rollladen*'
        options:
          type: custom:shutter-card
          icon_color: '#87bf50'
          buttons_position: right
          title_position: top

Thanks again!!