Problem with auto resuming Plex movie

Hi,
I’m trying to make an script to resume a movie that I started watchig. I’ve tried 2 ways, one with an input text that saves the title of the last movie I’ve watched, then I call the service media.player to start the movie and resuming, but I’ve got a problem, the title that gets the input, the one in the plex sensor, saves the name and the year in the name, " title (2010) " the title is not in the original title, and that makes that the media.player to not find the movie.
The other option is saving the media_content_id, and that worked but I haven’t the option to resume the movie where I left it.

First option code:

alias: Poner última pelicula plex
sequence:
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.sony_bravia_tv
  - delay:
      hours: 0
      minutes: 0
      seconds: 8
      milliseconds: 0
    enabled: true
  - service: media_player.select_source
    data:
      source: Plex
    target:
      device_id: 8eded30c3e91d60317611f17956b8c99
  - delay:
      hours: 0
      minutes: 0
      seconds: 8
      milliseconds: 0
    enabled: true
  - service: media_player.play_media
    target:
      entity_id: media_player.plex_plex_for_android_tv_bravia_4k_ur3
    data:
      media_content_id: >-
        { "library_name": "Movies", "title":
        "{{states(''input_text.ultima_pelicula_vista_plex'')}}", "resume": 1 }
      media_content_type: movie
mode: single
icon: mdi:movie-play

Second option code:

alias: Poner última pelicula plex
sequence:
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.sony_bravia_tv
  - delay:
      hours: 0
      minutes: 0
      seconds: 8
      milliseconds: 0
    enabled: true
  - service: media_player.select_source
    data:
      source: Plex
    target:
      device_id: 8eded30c3e91d60317611f17956b8c99
  - delay:
      hours: 0
      minutes: 0
      seconds: 8
      milliseconds: 0
    enabled: true
  - service: media_player.play_media
    target:
      entity_id: media_player.plex_plex_for_android_tv_bravia_4k_ur3
    data:
      media_content_id: '{{ states(''input_text.ultima_pelicula_vista_plex'') }}'
mode: single
icon: mdi:movie-play

Could anyone help me with this?

Thank you!!

I think with this query:

{ "library_name": "Movies", "inProgress": true, "sort": "lastViewedAt:desc",  "resume": 1, "maxresults": 1 }

I get what I want, I’ll test it later, and share the result.

Working!

Full script:

alias: Poner última pelicula plex
sequence:
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.sony_bravia_tv
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    enabled: true
  - service: media_player.select_source
    data:
      source: Plex
    target:
      device_id: 8eded30c3e91d60317611f17956b8c99
  - service: media_player.play_media
    target:
      entity_id: media_player.plex_plex_for_android_tv_bravia_4k_ur3
    data:
      media_content_id: >-
        { "library_name": "Movies", "inProgress": true, "sort":
        "lastViewedAt:desc",  "resume": 1, "maxresults": 1 }
      media_content_type: movie
mode: single
icon: mdi:movie-play

EDIT: correct query

My movies always resume from where they left off by default? How do I make it start at the begining every time? Resume = 0?

Yes, with "resume": 0 or deleting resume

I’ve tried both options and my movies alwasy resume from whre they left off. Ican’t figure out why or find anyone else having this issue

I have the exact opposite problem, the movie always starts from the beginning despite:

          media_content_id: >-
            { "library_name": "Film", "inProgress": true, "sort":
            "lastViewedAt:desc",  "resume": 1, "maxresults": 1, "title": "{{ film }}" }