Tap to turn on/play/pause media player

Hi all,

I am looking for a way to, as a tap_action in lovelace:

If the media player is off, turn it on
if the media player is paused, toggle it to play
if the media player is playing, pause it.

Is this possible? I am totally lost.

The tap action should call a script. The script contains this sequence of actions:

  sequence:
    - service: media_player.turn_on # Turn on if off. If it is already on this won't do anything.
      entity_id: media_player.your_media_player_here
    - condition: template # only do the next bit if playing or paused, i.e. not if idle
      value_template: "{{ states('media_player.your_media_player_here') in ['paused', 'playing'] }}"
    - service: media_player.media_play_pause # If playing will pause, if paused will play. 
      entity_id: media_player.your_media_player_here
4 Likes