🔹 Auto-entities - Automatically fill cards with entities

Yes, your code work, but it doesn’t limit to one specific light, which is what I’m looking for.

I tried using templates, but getting identation errors I cannot seem to solve. Here is what I tried:

type: 'custom:auto-entities'
card:
  type: entities
  entities:
    - type: section
      label: Scenes for Kontor
    {% set scenes = state_attr('light.kontor_hr', 'hue_scenes') %}
    {% for scene in scenes -%}
      - type: button
        tap_action:
          action: call-service
          service: hue.hue_activate_scene
          service_data:
            entity_id: light.kontor_hr
            scene_name: "{{ scene }}"
        name: "{{ scene }}"
    {% endfor %}
  show_empty: false
  filter:
    include:
      - entity_id: light.kontor_hr

But this gives me the error:

Configuration errors detected:

    bad indentation of a mapping entry (7:5)

     4 |   entities:
     5 |     - type: section
     6 |       label: Scenes for Kontor
     7 |     {% set scenes = state_attr('ligh ...

And no matter where I move the indentations, I can never get it working.
Can anyone help me?

Thanks.

As far as i understand things right. The card parameter is to select the container, a card that is able to display many entities like the entty card ord the grid card or a vertical stack card. And with the options entry you define the card inside the container.

So if you select grid in card you could use button inside options.

Example

type: custom:auto-entities
filter:
  include:
    - entity_id: sensor.net_gas_station_*
      options:
          type: custom:mushroom-template-card
          entity: this.entity_id
          primary: '{{state_attr(entity, ''brand'')}} - {{state_attr(entity, ''city'')}}'
          secondary: '{{states(entity)}} €'
          picture: /local/gas_station/{{state_attr(entity, 'brand')}}.png
card:
  square: false
  columns: 2
  type: grid
show_empty: false
card_param: cards
sort:
  method: state
  numeric: true

This gives me a grif of fuel station sorted by price.

Maybe that helps with your scenes

I think you are talking about the hue scenes that are created with the Hue App and are made visible in Home Assistant by the Hue integration. I don’t think you can filter by lamp/entity in the scene as my hue scenes only show the data below in the developer tools.

group_name: Woonkamer
group_type: room
name: Smaragden eiland
speed: 0.6031746031746031
brightness: 85.04
is_dynamic: true
friendly_name: Woonkamer Smaragden eiland

Since Hue scenes are associated with rooms or zones I use the code below to list all hue scenes in an area in an entities card. Home Assistant seems to automatically assign Hue Scenes to areas in Home Assistant if they have the same name as the room/zone in Philips Hue app so the list stays up to date when I change things in the Philips Hue app…

Maybe that also works for you?
Then you could expand it to make it look more like you want.

card:
  type: entities
  title: Scenes
filter:
  include:
    - area: Woonkamer
      domain: scene
      integration: hue
type: custom:auto-entities
sort:
  method: friendly_name

I really like how you were able to get a different picture for each entity.
I want this for my hue scenes, but I’m not there yet.
Will post a longer post below of what I have achieved so far.

Yes, you are right.
I concluded with the same; the scene entity_id are not listed when doing it like this.

Based on help from the community, this is what I got so far:

It still needs some tweaking, and I need to figure out how to use different pictures for the different buttons, but:

type: custom:auto-entities
card:
  square: false
  type: grid
  columns: 2
card_param: cards
filter:
  include:
    - entity_id: scene.kontor*
      options:
        type: custom:button-card
        show_entity_picture: true
        entity_picture: /local/hue-icons/hue-icon_lyst.png
        show_name: false
        name: nothing_yeet
        tap_action:
          action: call-service
          service: hue.activate_scene
          service_data:
            entity_id: this.entity_id
        double_tap_action:
          action: call-service
          service: light.turn_off
          service_data:
            entity_id: light.kontor_hr

Gives this output:
image

3 working buttons :slight_smile:

I’m not sure if this is a Auto-Entities discussion anymore, or if it should be moved to custom: button-card, but…

We still need to figure out how to use different pictures for different scenes somehow.

I have created pictures for different scenes and name them the same as the scene name

Maybe it is possible to strip the scene entity name so only the scene name remains.
Example: strip scene.kontor_hr_golden_pond so only golden_pond remains

That way we could create something like this:
entity_picture: /local/hue-icons/hue-icon_{{stripped_entity_name]]_lyst.png

I also think it would be wise to remove the text from the picture and use a stripped show_name instead.
That way the icons could be used by others than me

Thanks again for helping out, I really appreciate it

for an alternative, see my earlier post here on how to auto-populate those

Thank you for answering.
I have seen your post now, and I must say your work is most impressive! Hats off to you.
What card you use to set up this?
But your scripts seems to populate an input select box that lists ALL lights that has Hue Scenes connected to them.
But how do I alter the template to list the scenes ONE light only?
This is because I have one card per room and therefor need scenes for that one room.
If I understand this correctly, it needs to be done in 2 rounds:
First use the light entity_id to find all hue scenes connected to that light and create a list.
And then use that list to find the scene entity_id’s for those scene into another list. And that list can be used to populate the auto-entities card?

Sorry for the stupid AF questions

You might not even need a template if I read your requirements.

Just add an area and if you want, the integration on domain scene. I do that in my rooms and works perfectly.

These are embedded the custom slider

I might have forgotten to mention I did customize all scenes to have their respective entity_picture

A bit off topic, but how did you get the images for all the Hue Scenes?
The actual image files I mean.

I made them :wink:

I’ve also posted that in the linked topic. every time the Hue app has new scenes, I make a png for those and set them in customize

I’m struggling with calling a rest_command as a tap_action for an auto-entities entity.

While the template works fine for the display part (“primary:”), the rest_command leads to the following error logged:

Template variable warning: ‘id’ is undefined when rendering 'ID={{ id }}'

The problem seems to be the line:

id: '{{ state_attr(entity, ''index'') }}' 

For test purposes I used a constant (id: “17”) and this worked as expected.

Any suggestions?

This is the complete card:

type: custom:auto-entities
card:
  square: false
  columns: 1
  type: grid
show_empty: false
card_param: cards
filter:
  include:
    - entity_id: input_text.xenia_script_*
      options:
        type: custom:mushroom-template-card
        entity: this.entity_id
        primary: '{{ state_attr(entity, ''name'') }} [{{ state_attr(entity, 'index') }}]'
        tap_action:
          action: call-service
          service: rest_command.execute_xenia_script
          service-data:
            id: '{{ state_attr(entity, ''index'') }}'
sort:
  method: entity_id

Are you sure that an input_text entity has an indes attribute?

although I am not familiar with the mushroom-template-card, I suspect your issue has to do with the quoting, which looks painful to my eyes…

you’d help yourself a lot if you’d use multiline notation, and be done with all of these double single quotes.

As you state the primary works ( it uses 'index' ) , so single single quotes, you’d probably need to use that in the secondary too (now using double single quotes ''index'' )

this would probably make it work:

    - entity_id: input_text.xenia_script_*
      options:
        type: custom:mushroom-template-card
        entity: this.entity_id
        primary: >
          {{ state_attr(entity, 'name') }} [{{ state_attr(entity, index) }}]
        tap_action:
          action: call-service
          service: rest_command.execute_xenia_script
          service-data:
            id: >
              {{ state_attr(entity, index) }}

if index is in fact a variable name. If it is an attribute, the question dibbler raises, you’d need to single quote them. that would be surprising though, given: Input Text - Home Assistant, and would have to been set via customize or some other option. Unless that would be some hidden option in either of the cards/integrations…

Absolutely. They are generated in a sep, Python script. Two attributes are in existence:

  • name
  • index

1 Like

Sorry, you’re right regarding the quoting. This somehow was messed up while copying over to here.

It’s currently in like this:

id: '{{ state_attr(entity, 'index') }}'

index is an attribute and currently already correctly interpreted for “primary” in displaying the attribute value.

image

Repeating the currently used quoting in HA:

type: custom:auto-entities
card:
  square: false
  columns: 1
  type: grid
show_empty: false
card_param: cards
filter:
  include:
    - entity_id: input_text.xenia_script_*
      options:
        type: custom:mushroom-template-card
        entity: this.entity_id
        primary: '{{ state_attr(entity, 'name') }} [{{ state_attr(entity, 'index') }}]'
        tap_action:
          action: call-service
          service: rest_command.execute_xenia_script
          service-data:
            id: '{{ state_attr(entity, 'index') }}'
sort:
  method: entity_id

but now you are having issues with the yaml, as the interpreter can not separate the correct strings. as is clearly displayed in the coloring

if you insist on using single lines, than use double outer quotes and single inner quotes.

its like that with all yaml, everywhere.

Chaging it to multiline notation, but the rest_command has still the same error:

Template variable warning: ‘id’ is undefined when rendering ‘ID={{ id }}’

type: custom:mushroom-template-card
entity: this.entity_id
primary: |
  {{ state_attr(entity, 'name') }}  [{{  state_attr(entity, 'index') }}]
tap_action:
  action: call-service
  service: rest_command.execute_xenia_script
  service-data:
    id: |
      {{ state_attr(entity, 'index') }}

that would be the outcome if you pasted the template in dev tools template, and replace entity with an actual entity_id?

besides all of that, could it be the rest_command expects an entity_id, instead of an attribute only? this would make your challenge probably be rather Off topic for auto-entities.

DevTools - Templates –
This delivers the correct result:
{{ state_attr(‘input_text.xenia_script_17’, ‘index’) }} → 17
This provides “UndefinedError: ‘input_text’ is undefined”:
{{ state_attr(input_text.xenia_script_17, ‘index’) }}
BUT quoting entity in primary: leads to an error.

In the mean time I also experimented with:

    id: |
      {{ states.this.entity_id.attributes.index }}

But the error log still lists the same error.

This is the rest_command:

  execute_xenia_script:
    url: "http://xenia.local/execute_script"
    method: POST
    payload: "ID={{ id }}"
    content_type: "application/x-www-form-urlencoded"

this is all very odd. the second version is wrong ofc, you need to quote the entity_id.

can you screenshot the entity in dev tools state like this: