Simple Script with sensor value calculation

Hi,
I’m making a script which rewinds AppleTV’s current playing position by 20 seconds.
The corresponding attribute is called media_position but I can’t get the calculation to work. Any ideas?
Here’s what I have:

movie_rewind:
  alias: Movie Rewind
  sequence:
  - service: media_player.media_seek
    data:
      seek_position: {{ states('media_player.appletv', 'media_position') - 20 }}
    entity_id: media_player.appletv
  mode: single

states(‘entity_id’) returns the current state of “entity_id”, to access attributes you instead need to use state_attr(‘entity_id’, ‘attribute’)

So in your case the script should read:

  alias: Movie Rewind
  sequence:
  - service: media_player.media_seek
    data:
      seek_position: "{{ state_attr('media_player.appletv', 'media_position') - 20 }}"
    entity_id: media_player.appletv
  mode: single

Edited: To add the quotes around the single line template that I missed originally, as pointed out by @osdyonis in below post.

Thank you, kind stranger! In fact, I found out it actually has to be in quotes, like so:

seek_position: "{{ state_attr('media_player.appletv', 'media_position') - 20 }}"

@osdyonis good spot, sorry that I didn’t give you the full solution, I have edited my post above to include the quotes just incase somebody else stumbles across this thread, so that the solution is correct!