Issue with Intent Script formatting for plex media playback

So I have the following intent script working right now for media playback for my plex server:

  plexstreamtv:
    speech:
      text: Starting the playback in a moment.
    action:
      - service: media_player.play_media
        continue_on_error: true
        target:
          entity_id: "{{ media_player }}"
        data: 
          media_content_type: tvshow
          media_content_id: 'plex://{"library_name": "TV", "show.title": "{{ shows }}", "episode.unwatched": true, "allow_multiple": 1 }'
      - wait_template: "{{ is_state('sensor.deathbot64_state', 'playing') }}"
        timeout: "00:00:12"
      - if: 
          - "{{ not wait.completed }}"
        then:
          - service: media_player.play_media
            target:
              entity_id: "{{ media_player }}"
            data: 
              media_content_type: tvshow
              media_content_id: 'plex://{"library_name": "TV", "show.title": "{{ shows }}", "allow_multiple": 1 }'
        else:
          - stop: ""

I use a wait template that checks my tautulli sensor to see if my plex account is playing anything, as a fail safe just incase a tv show I pick doesn’t have any unwatched episodes, if the playback starts in the 12 seconds (some devices are slower than others for updating the plex account state) than the script stops, otherwise it will start the show right from the start of the series.

I want to switch the wait template to check the {{ media_player }} itself but I cant get it format to work correctly so the wait_template always fails back to playing it from the start when i try to switch the code to something like:


  plexstreamtv:
    speech:
      text: Starting the playback in a moment.
    action:
      - service: media_player.play_media
        continue_on_error: true
        target:
          entity_id: "{{ media_player }}"
        data: 
          media_content_type: tvshow
          media_content_id: 'plex://{"library_name": "TV", "show.title": "{{ shows }}", "episode.unwatched": true, "allow_multiple": 1 }'
      - wait_template: "{{ is_state('{{ media_player }}', 'playing') }}"
        timeout: "00:00:12"
      - if: 
          - "{{ not wait.completed }}"
        then:
          - service: media_player.play_media
            target:
              entity_id: "{{ media_player }}"
            data: 
              media_content_type: tvshow
              media_content_id: 'plex://{"library_name": "TV", "show.title": "{{ shows }}", "allow_multiple": 1 }'
        else:
          - stop: ""

How would I format this to work the way I want to?

Hi, I’m sorry i do NOT have the answer to what you asked, hopefully you found it by now…BUt I wonder if you could help me

My coding is setup up pretty similar to yours, and the allow_mulitiple: 1 in your coding was a huge help that I couldn’t get answers on. I kept getting errors if movie such as HArry Potter shared the same title. But now it seems to just play the first one

Getting to my point. Whenever I launch a movie, it alwasy picks up where it left off. Is there coding I can add to content_ID where it will alwasy start from the beginning?

My second question is, I have to alwasy start a move with my remote first before home assitant text field will actually work

THe whole scan plex thing when you first go to the app doesnt seem to work for me

I ended up switch to a sentence automation to get play working. And I added a Plex client scan in the automation steps. I just make an automation per device to eliminate variables needed.

alias: Play Tv Show on the Bedroom TV
description: ""
trigger:
  - platform: conversation
    command:
      - Play the show {shows} on the bedroom
      - Play the show {shows} on the bedroom tv
      - Play the tv show {shows} on the bedroom
      - Play the tv show {shows} on the bedroom tv
      - Play the series {shows} on the bedroom
      - Play the series {shows} on the bedroom tv
condition: []
action:
  - service: plex.scan_for_clients
    data: {}
  - service: media_player.play_media
    continue_on_error: true
    data:
      media_content_type: tvshow
      media_content_id: >-
        plex://{"library_name": "TV", "show.title": "{{ trigger.slots.shows }}",
        "episode.unwatched": true, "allow_multiple": 1 }
    target:
      entity_id: media_player.bedroom_tv
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - if:
      - condition: state
        entity_id: media_player.bedroom_tv
        state: playing
    then:
      - stop: ""
    else:
      - service: media_player.play_media
        data:
          media_content_type: tvshow
          media_content_id: >-
            plex://{"library_name": "TV", "show.title": "{{ trigger.slots.shows
            }}", "allow_multiple": 1 }
        target:
          entity_id: media_player.bedroom_tv
mode: single

Hmm ok cool, that scan client has a work for me in the past, but I’ll try mirroring your code and see what happens.

What about the movie playing from the beginning? No matter what. I do using an offset using resume = 0. It always continues from where it left off when I play any Plex movie

alias: Play Movie on the bedroom tv
description: ""
trigger:
  - platform: conversation
    command:
      - (start|play) [the] Movie {movie} (on|in) [the] bedroom tv
      - (start|play) [the] Movie {movie} (on|in) [the] bedroom
condition: []
action:
  - service: plex.scan_for_clients
    data: {}
  - service: media_player.play_media
    data:
      media_content_type: tvshow
      media_content_id: "plex://{\"library_name\": \"Movies\", \"title\": \"{{ trigger.slots.movie }}\" }"
    target:
      entity_id: media_player.bedroom_tv
mode: single

I think the movies start from the start with this script but I’m not 100% sure