Need help with appending entity_picture url attribute to ha url

Im trying to get the now playing artwork from my sonos to add to my dashboards. Under the attributes of the media_player I get:
entity_picture: /api/media_player_proxy/media_player.bedroom?token=averylongstringthatchanges

I can goto https://nobody.duckdns.org/api/media_player_proxy/media_player.bedroom? but it downloads the artwork rather than displaying.

Ive created a sensor that grabs that attribute, is there a way to create a script or template that will create a good url for me? So somehow say add that attribute or sensor to https://nobody.duckdns.org ?

Then I can just use that sensor for my dashboard?

Well now it seems even using the token it is downloading the image. Anyone know how to save that image somewhere and use it? It would need to overwrite the file and keep the same name…

I got it working, but I am running into that caching issue. Only on the dashboard though, if I force a reload on my browser it updates the pic every track.

Have you ever figured this part out @Rene ? I know you guys were messin with it few months back in that thread.

I tried the refresh option in the widget and without it. I also have that force_compile in:

AppDaemon:
logfile: STDOUT
errorfile: STDERR
threads: 10
disable_apps: 1
force_compile: 1

HASS:
ha_url: https://nobody.duckdns.org
ha_key: …

HADashboard:
dash_url: http://x.x.x.x:5050
dash_dir: /home/homeassistant/conf/dashboards

i only helped others with it, because i never used anything like that.
i know someone had a working situation, but dont know who anymore.
but i also think i remember i saw something about it being broken again.

the cashing is about the same url.
wasnt it that a counting nr at the end of the url did help there?

maybe create the same url twice for the pic, and let AD change between the 2?

Hey Rene. That’s an interesting idea. I’m guessing the iframe does a sort of round robin then with the urls and refresh set to 10 would switch urls every ten sec?

I found something that half works. I’m using the iPad kiosk pro app that aimc turned me on too when I was first getting my feet wet.

In the app settings there’s an option to clear all cache when returned to the homepage(first tab on my dashboard). Once I go back to that page and return the sonos page it’s refreshed. But I don’t like that. I have a lot of people over to play pool and I want to leave the sonos page open by the pool table to be able to look quickly and change quickly. With that solution I have to set a timeout value in the app that takes it back to the homepage. Setting the homepage as the sonos page is not a way I’d like to go. I’ll try out your suggestions and report back. Thanks again!

Alright!!! Got it finally!!! This so awesome!

I tried that multiple urls but didnt have any luck.

The solution was to use that camera component, camera widget, and a template for the url :slight_smile:

So in my configuration.yaml

camera:
  - platform: generic
    still_image_url: https://xxx.duckdns.org/api/media_player_proxy/media_player.bedroom?{{ states.media_player.bedroom.attributes.token }}'

Then take that url you get from that camera entity in HA and add &api_password=yourhapassword to the end of the url, then add it to your dash file:

bedroom_media_art:
    widget_type: camera
    entity_picture: https://_xxx_.duckdns.org/api/camera_proxy/camera.generic_camera?token=_reallylongstringofcharectors_&api_password=_yourhapassword_
    refresh: 10

Now without changing dashboards or any interaction at all with the dashboard when the song changes, the dashboard changes to the new artwork in a few seconds.

Perfect!!! Thanks for all the help @rene ! You left enough bread crumbs around this forum to piece it together :slight_smile:

1 Like

very nice solution!!
the first step, gettin back to the source, and take it from there, was the smart move.
thx for sharing, it will help me help others :wink:

1 Like

Thank you sir!

1 Like

OK, lets keep going :slight_smile:
When im watching TV and the sonos are not playing music, the image is just absent. Thats fine its transparant doesnt look like theres an error or anything like that. BUT…Id like to use an image for when nothing is playing, maybe a picture of me lol or a picture of my tv…something. Using widget style I see you have the option for some css stuff…
widget_style: "background: white;"
but could you set the background to an image? So if no artwork is available it would just display what is “behind” the artwork?

One thing about sonos is the control is sometimes a pain…but now this solves that, im loving it.

you could try something like:

widget_style: "background-image:url(anything)"

i think it should show when no pic is in front.

Unfortunately no go. It looks like the no image stays in front and never displays what’s behind it.

I wonder if I create some if statement to say if tv or if not playing display. I not sure I could do that with dashboard though…

Any ideas? I would like to do it in ha rather than appdaemon. I don’t understand appdaemon lol:frowning:

if it still shows the “no picture” you probably need conditional css.
so something in the css that says “if pic is empty then hide”
unfortunatly i dont know if and how that is possible without changing the javascript from the widgets.

Alright, I appreciate it. Gave me a place to start looking

1 Like

Not sure what I´m getting wrong here.
Put this i the configuration.yaml file:

camera:

… and this in the test.dash file:

media_player:
widget_type: camera
entity_picture: http://10.0.0.27/api/camera_proxy/camera.generic_camera?token=e972ad54463cb9b1463ad247111f599084351683da23ccb46034234609a659ed&api_password=MyPaAsS
refresh: 10

In the Homeassistant states page I get:
screenshot1

In the dashboard, the widget shows a broken image link.

Any advice?

If you take your camera url and paste it in a browser do you get the image?

If I put this part in, I get a 404 : Not found:

http://10.0.0.27:8123/api/media_player_proxy/media_player.spotify/

If I paste the url from the dash-file, I get a ERR_CONNECTION_REFUSED

http://10.0.0.27/api/camera_proxy/camera.generic_camera?token=e972ad54463cb9b1463ad247111f599084351683da23ccb46034234609a659ed&api_password=SECRETPASS

If I take the url form media_player.spotify and paste into the browser, the album art appers:

http://10.0.0.27:8123/api/media_player_proxy/media_player.spotify?token=8c76ca1e8bd2d2c68cb5c743eb687276f91cf35315b8422f549513db5864e4ee&cache=c0a97f062071cab9

… however not getting the artwork on the home assistant frontend or on the dashboard. Any ideas?

in HA you use

still_image_url: http://10.0.0.27:8123/api/media_player_proxy/media_player.spotify?{{ states.media_player.spotify.attributes.token }}’

and the state is probably only the token
so then it should be

still_image_url: http://10.0.0.27:8123/api/media_player_proxy/media_player.spotify?token={{ states.media_player.spotify.attributes.token }}’

in HA.

but i have no clue how to ket the changing token into the dashboard.

Same outcome I´m afraid, but thanks.

i think you should look in your home assistant logfiles why it isnt working.
and if there is nothing you should use debugging for home assistant. (setting loglevels different for cams.)
or search for spotify on the forum.