Template in script parameters

Hey All,

just a short background: I have multiple Chromecast Audio devices connected to speakers around the house and I have a di.fm subscription plus some radio stations that I would like to listen to. I’m looking for a convenient way to select what to play and where to play.

The plan is/was to create two input_selects and a single script that reads the entity_id and the media source from the two input selects and pushes those into a media_player.play_media service call.

This looks like the following in yaml:

the input_selects:

media_source: 
  name: Music Styles
  initial: http://prem2.di.fm:80/chillout?
  options: 
  - http://prem2.di.fm:80/chillout?
  - http://prem2.di.fm:80/lounge?
  - http://prem2.di.fm:80/chillntropicalhouse?
  - http://prem2.di.fm:80/club?
  - http://prem2.di.fm:80/deepnudisco?
  - http://prem2.di.fm:80/liquidtrap?
  - http://prem2.di.fm:80/undergroundtechno?
  - http://79.172.212.151/chfm_en.mp3
  - http://stream.musicfm.hu:8000/musicfm.mp3
  - http://stream4.radio1.hu:8000/high.mp3
  icon: mdi:headphones

media_players: 
  name: Speakers
  initial: media_player.living_room_speaker
  options:
  - media_player.bedroom_speaker
  - media_player.kitchen_speaker
  - media_player.lg_tv_remote
  - media_player.living_room_speaker
  - media_player.office_speaker
  - media_player.whole_flat
  icon: mdi:speaker

The script:

'1536007986550':
  alias: Play Music of Your Choice
  sequence:
  - data:
      entity_id: '{{ states("input_select.media_players") }}'
      media_content_id: '{{ states("input_select.media_source") }}'
      media_content_type: mp3
    service: media_player.play_media

and it looks really tidy in Lovelace as well :slight_smile:

Sounds good so far isn’t it?

Well the only problem is that every time I run the script it logs an error:

Invalid service data for media_player.play_media: Entity ID {{ states("input_select.media_players") }} is an invalid entity id for dictionary value @ data['entity_id']. Got '{{ states("input_select.media_players") }}'

This can mean two things:

  1. the templates in the script parameters are not supported
  2. I’m making a mistake somewhere

Have you ever tried templates in scripts? is it supported?
Could you please check my yaml snippets to see what could be the problem?

Thanks in advance!
B

You need to use data_template instead of data when you are using templates :slight_smile:
data_template is not supported by the GUI editor so you would have to add that in the yaml file.

and it works!
Thanks!

BTW: what is the point of having data and data_template as two separate options?
I don’t really see a reason to ever use data again (other than it is supported by the GUI and it is just so fast that way)

I actually have no idea :smiley:

It’s a little off topic but do you ever see your chromecasts randomly generating different MAC addresses and connecting to the router with that different MAC?

Mine does it constantly. I’d say it does it 5-10 times every day. I had a hard time trying to figure out why my known_devices.yaml got filled up with all of these unknown MAC addresses. Then I finally unplugged my chromecat audio and it completely stopped for a few days. then when I plugged it back in it started happening again so I know that’s the culprit.

Hey!
Never saw that… I have checked the known devices and it had nothing weird.
B

Thanks for checking.

I must have a screwy one. I tried to contact Google customer service about it but they basically said “it can’t be happening so…sorry there’s nothing we can do for you” :roll_eyes:

I hate it when I know more than the “experts”…

Are you sure that it is not someone trying to use your network hiding as a Chromecast??

I’ve seen this before on some devices.

I’m pretty sure it’s not.

Unless they can somehow also know when I unplugged it to see if that was the thing doing it…:worried::fearful::scream:

:smile: