Help with data_template using dynamic entity names question

The correct method to get a state out of an entity is states(), however you’re trying to get an attribute, which is state_attr().

Also, you need to wrap the entity_id in quotes as well as the attribute.

Thats the thing Petro, I have done all that and still nothing, check this out:

I’ve correctly templated this data into a sensor entity called sensor.sonos_media. And I can see its taking the url:

 sonos_media:
        friendly_name: "sonos_media"
        value_template: "{{ (state_attr('media_player.living_room', 'entity_picture')) }}"

I’ve also passed it the way I’ve stated and the way you have stated (the correct way), I’ve ALSO tried to pass the sensor “sensor.sonos_media” that has the url

like this

image: {{ states('sensor.sonos_media') }}

I get

                image:
                  '[object Object]': null

but it can’t be null because im seeing its value right nou in developer tools!

Screen Shot 2021-01-25 at 9.59.53 AM

This is the card:

Screen Shot 2021-01-25 at 10.01.08 AM

And when I get long press to go to the more info pop up, the image I want is there!!! OMG and can’t get it out!!!

Screen Shot 2021-01-25 at 10.01.13 AM

/api/media_player_proxy/… is not the full path and that’s most likely your issue.

When I hard code the value of the attribute or the templated sensor (see link) the picture works

/api/media_player_proxy/media_player.living_room?token=1124256fa1cae8e1be0c476c2ce881aaf523ff4cfeaba2b1866759033a944f8b&cache=d05f973fec3e2c7b

See picture when I hard code url

Screen Shot 2021-01-25 at 10.09.48 AM

put the template in double quotes or use the multiline indicator > and move the template to the next line.

This
Screen Shot 2021-01-25 at 10.22.37 AM

turns into this after I save

Screen Shot 2021-01-25 at 10.23.20 AM

still no image

Please reread this

I don’t mean to be dense but even tho I didn’t provide a picture I also used the multilane indicator and got the same result.

when you say put the template on double quotes, did I do that right?
what would be the notation when I use the multiline indicator?

Thanks a lot for the help

No this is what a template wrapped in double quotes would look like:

image: "{{ states('sensor.sonos_media') }}"

I provided it already

image: >
  {{ states('sensor.sonos_media') }}

Double quotes result in this

Screen Shot 2021-01-25 at 10.32.03 AM

Doesn’t work

(edit) Multiline turns into something else (sorry had an indentation issue before):

Screen Shot 2021-01-25 at 10.41.24 AM

What doesn’t work about the first image?

In the multiline indicator, the template needs to be indented by 2 spaces from image, like my example.

Result for both is no image

Screen Shot 2021-01-25 at 10.42.26 AM

instead of using that template to grab the state, just use the state_attr template in it instead, see if that works.

Ok I don’t know if this plays a role in the behavior im seeing, but all of this is wrapped in a fullscreen card add-on called home kit that makes rows and columns so I can organize mi view like so:

The code I use to prepare this Lovelace view is:

  - title: Tiles
    background: center / cover no-repeat fixed url("/local/bg2.jpg")
    path: Tiles
    panel: true
    icon: 'hass:tablet'
    style:
      opacity: 50
    badges: null
    cards:
      - type: 'custom:homekit-card'
        title: tablet
        style: |
          :host {
            font-family: -apple-system, BlinkMacSystemFont, sans-serif;
            }
        useBrightness: false
        useTemperature: false
        tileHoldAnimation: true
        titleColor: '#FFF'
        enableColumns: true
        statePositionTop: true
        rows:
          - row: 1
            columns:
              - column: 1
                tileOnRow: 3
                entities:

I have no idea, I don’t use that card. Does that card support images?

Does that card support templates for any field?

Yes, in that little circle it has an option called image that receives a url as string and displays it there

What im beginning to think is it doesn’t play well with gettin a variable instead of the string.

I would assume that the custom mini card doesn’t support templates as most lovelace does not support templates.

FYI, searched the Mini Media Player thread for “image:” and couldn’t find an example that employed a template. That thread contains over 2000 posts so there ought to be at least one if the option supported a template. I think the conclusion here is that it doesn’t.

1 Like

Yeah, I just tried to do the attribute directly with

              - type: 'custom:mini-media-player'
                entity: media_player.living_room
                name: Music
                image: {{ state_attr('media_player.living_room', 'entity_picture') }}
                speaker_group:
                  sync_volume: true
                  platform: sonos
                  show_group_count: true
                  expanded: false
                  entities:
                    - entity_id: media_player.Living_Room
                      name: Sonos Play
                    - entity_id: media_player.Living_Room_2
                      name: Sonos SL

and it doesn’t let me save, as if there is an issue with the code,

if I do multiline it doesn’t work either, it just quotes it out . so I guess it doesn’t do templates

Thanks for all the help, I hope this helps anyone that is pulling their hair out looking for the same solution