Media_content_id from sensor state

n00b here.

So I have to crawl a coupe of urls on an API to fetch a URL to play on my chromecast. I couldn’t find a nice way to do this other than creating a sensor which runs a bash-script. Seems to work fine and the sensor state is containing the url I want. However my Chromecast cannot play this, like if the url is not passed correctly. Is this even possible?

automation:
- alias: Play Brandmand Sam

  trigger:
    platform: state
    entity_id: input_select.1salcast
    to: "Brandmand Sam"

  action:
    - service: media_player.play_media
      data:
        entity_id: media_player.1_sal
        media_content_id: sensor.brandmand_sam_url
        media_content_type: movie

I have also tried these:
media_content_id: {{ sensor.brandmand_sam_url }}
media_content_id: {{ state.sensor.brandmand_sam_url }}
with no luck.

Hi,

If the address is correct then you can get the value of the sensor with ‘{{states.sensor.brandmand_sam_url.state}}’

1 Like

Hi.
It is still not doing it. When I look at the attributes for the mediaplayer, it says:
media_content_id: {{ states.sensor.brandmand_sam_url.state }}
…So like it is not resolved to a url.
If I write in the url manuallay, it works fine. So the url is good.

Use “data_template:” instead of “data:”

Then go to Templates and check if there’s any error

Awesome! Now it works :slight_smile:

My bad, didn’t read the full script in the first instance.

Anyway, whenever you need to use custom values for any field you need to template.

Roger that.
And thank you very much for your help!

You’re welcome

Hovsa der vidst en dansker her