Using media length as the track seek value in a service?

I am trying to make a next track service for my plex, as it seems the next track is unsupported - seeking to a value works, but I would like to use the length of the current track as the seek position

I have tried various configurations of the following as I have managed to find all the info in attr info and tested the seek function with a plain text number.

service: media_player.media_seek
data:
  seek_position: {% state_attr("media_player.floor_guy","media_duration") %}
target:
  entity_id: media_player.floor_guy

Replace the % with { or }.
Templates should be {{ }}

I tried it with: seek_position: {{ state_attr(“media_player.floor_guy”,“media_duration”) }} and it came up with the error: Failed to call service media_player.media_seek. Error rendering data template: Result is not a Dictionary

Hello. Does anyone know how to write this?

Thanks - thought it would be something simple like this.

Is something like this possible too? Using the value of an input as part of the entity name. I have tried the following, but it does not seem to be writing the contents of the variable the way I wanted it to.

{{ state_attr("media_player.{{ states('input_select.player') }}","media_duration") }}

If I put {{ states('input_select.player') }} in a template by itself it writes the part of the media player name that is used in the original question.

I have now figured out how to format this correctly :slightly_smiling_face:

{{ state_attr("media_player."+states('input_select.player'),"friendly_name") }}

Hi, would like to do the same but I thought seek was not possible with Plex. Did you get it to work? Or did you find some workaround?

Nevermind, tested myself and it seems to be working as expected. Thanks for the hint!

My complete scripts to go next or previous track for selected media player input_select.media_player, detecting if special seek is required when Plex is playing.

alias: Cast next media player selection
sequence:
  - service: media_player.media_next_track
    data_template:
      entity_id: media_player.{{ states('input_select.media_player') }}
    enabled: false
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{state_attr('media_player.' ~
              states('input_select.media_player'), 'app_name') == 'Plex'}}
        sequence:
          - service: media_player.media_seek
            target:
              entity_id: media_player.{{ states('input_select.media_player') }}
            data:
              seek_position: >-
                {{ state_attr("media_player." ~  states('input_select.media_player'),"media_duration") }}
    default:
      - service: media_player.media_next_track
        data_template:
          entity_id: media_player.{{ states('input_select.media_player') }}
mode: single
icon: mdi:skip-forward
alias: Cast previous media player selection
sequence:
  - service: media_player.media_previous_track
    data_template:
      entity_id: media_player.{{ states('input_select.media_player') }}
    enabled: false
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{state_attr('media_player.' ~
              states('input_select.media_player'), 'app_name') == 'Plex'}}
        sequence:
          - service: media_player.media_seek
            target:
              entity_id: media_player.{{ states('input_select.media_player') }}
            data:
              seek_position: 0
    default:
      - service: media_player.media_previous_track
        data_template:
          entity_id: media_player.{{ states('input_select.media_player') }}
mode: single
icon: mdi:skip-backward