How to get plex to play a random epsiode of a tv show?

Hello,

I have this script and I am trying to get it to play a random episode of a particular tv show. Can anyone advise me? Thanks!

alias: "Plex: Bluey Watch Random"
sequence:
  - service: remote.send_command
    data:
      command: wakeup
    target:
      entity_id:
        - remote.appletv
  - service: media_player.select_source
    data:
      source: Plex
    target:
      entity_id:
        - media_player.appletv
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: button.press
    data: {}
    target:
      entity_id:
        - button.scan_clients_htpc
  - wait_template: >-
      {{ not is_state('media_player.plex_plex_for_apple_tv_mb_apple_tv',
      'unavailable')   }}
    timeout: "45"
  - service: media_player.play_media
    data:
      media_content_type: EPISODE
      media_content_id: "{ \"library_name\" : \"TV Shows\", \"show_name\": \"Bluey\", \"maxresults\": 1 }"
      enqueue: replace
    target:
      entity_id:
        - media_player.plex_plex_for_apple_tv_apple_tv
mode: single

For anyone trying the same thing, this is the notation that finally worked. Don’t ask me why…

alias: "Plex: Bluey Watch Random"
sequence:
  - service: remote.send_command
    data:
      command: wakeup
    target:
      entity_id:
        - remote.appletv
  - service: media_player.select_source
    data:
      source: Plex
    target:
      entity_id:
        - media_player.appletv
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: button.press
    data: {}
    target:
      entity_id:
        - button.scan_clients_htpc
  - wait_template: >-
      {{ not is_state('media_player.plex_plex_for_apple_tv_mb_apple_tv',
      'unavailable')   }}
    timeout: "45"
  - service: media_player.play_media
    data:
      media_content_type: EPISODE
      media_content_id: >-
        { "library_name" : "TV Shows", "show_name": "Bluey (2018)", "shuffle":
        "1", "maxresults": 1 }
      enqueue: replace
    target:
      entity_id:
        - media_player.plex_plex_for_apple_tv_apple_tv
mode: single
1 Like

Mine works like this:

alias: "Plex: Bluey Watch Random"
sequence:
  - service: remote.turn_on
    data:
      activity: plex://
    target:
      entity_id: remote.sony_kd_65xd7505
  - service: media_player.play_media
    data:
      media_content_type: EPISODE
      media_content_id: >-
        { "library_name" : "Animated series", "show_name": "Bluey (2018)",
        "shuffle": "1", "maxresults": 1 }
      enqueue: replace
    target:
      entity_id: media_player.plex_plex_for_android_tv_bravia_4k_gb
mode: single

Thank you! Was hoping I’d find an easy way to do this, and I don’t even need to change the title of the show!

What the heck!? That’s exactly what I’m here for too. “Bluey” wasn’t part of my search term.

I guess us parents are sick of pushing too many buttons for a 10 min episode.

What kind of psyop is bluey running? I’ve been working on this automation for a while myself!

Mine may be a different reason… Our two Porkies (half-pom/half-yorkie) bark at every tiny noise during the day while I’m working UNLESS Bluey is on, if Bluey is on the television in the living room they are quiet as church mice.

This will save me some sanity.

can you get this to work like this but with a roku device?

I don’t think so. I’ve got it working with Plex following this doc: Plex Media Server - Home Assistant which is Plex specific.

The analogous doc for Roku is Roku - Home Assistant and I don’t see anything about randomization. But I also don’t know Roku so maybe you can make sense of channels, and/or searching.

I hope you get it to work, my kid can just click any of these buttons for random episodes and it’s been an incredible time saver. I even wrote a Powershell script that HA calls when a library count changes (meaning I added a new show or removed a show) and then it interrogates Plex via its API to build a new Lovelace yaml that updates this screen dynamically. “Dad can you download Bill Nye?” I just queue it up in Sonarr and then it shows up on this screen with art all by itself 10 min later.