Casting random Youtube video to device

Hello,

I’m very new to HA (so apologies if this question isn’t in the right place) but eager to learn.

I’ve set up an automation that, at a time in the morning, will cast a YouTube video to my Google HUB for a bit of ambience. It works great:

action:
  - data:
      media_content_type: cast
      media_content_id: " { \"app_name\": \"youtube\", \"media_id\": \"GyK6w4RVePg\" }"
      enqueue: play
    service: media_player.play_media
    target:
      device_id: 323a99912ae05ec9a79471e420b87103

What I’d like to do though is have it play a random video from a set of possible ones. How would I go about doing that? Would it be a case of stipulating all the possible videos in the automation YAML somehow, or is there a way to pick randomly from a list / DB of some kind?

Thank you.

It you want an reason to learn Node-RED this would be a good example to practice on. You could store the video content params in a JSON structure and then pick one using a random number function. You’ll need some JavaScript in a Function node and then a Call service node to do the casting. I have no clue how this might be achieved using YAML.

I’ve managed to accomplish this with the following YAML:

service: media_player.play_media
data:
  media_content_type: cast
  media_content_id:  '
  { 
  "app_name": "youtube", 
  "media_id": "{{ ["4u0i7UgrUuk", "kD8oLJoCxPk", "TKKfQUkEa7M"] | random }}" 
  }'
target:
  device_id: 323a99912ae05ec9a79471e420b87103