Skip to content

Cannot get pause/seek/current_position_template/media_duration_template working #29

Description

@slyoldfox

I am trying to create a media player card for the spotify native interface on macOS.
All scripts locally are working (and also through the shell_command api in HA).

The sensors all seems to have decent values and are populated through the command line sensor https://www.home-assistant.io/integrations/sensor.command_line/)

My current config is:

  - platform: media_player_template
    media_players:
      receiver:
        friendly_name: Receiver
        device_class: receiver
        current_volume_template: "{{ states('sensor.current_spotify_volume') }}"
        current_position_template: "{{ states('sensor.current_spotify_song_position') }}"
        media_duration_template: "{{ states('sensor.current_spotify_song_duration') }}"
        title_template: "{{ states('sensor.current_spotify_song') }}"
        #availability_template: "{{ states('sensor.current_spotify_availability') }}"
        #album_template: "album template"
        #artist_template: "artist template"
        value_template: >
          {% if is_state("switch.local_spotify", "on") -%}
            on
          {%- else -%}
            off
          {%- endif %}
        next:
          service: shell_command.spotify_next
        previous:
          service: shell_command.spotify_previous
        play:
          service: shell_command.spotify_play
        pause:
          service: shell_command.spotify_pause
        seek:
          service: shell_command.spotify_set_position
          data_template:
            position: "{{position}}"
        set_volume:
          service: shell_command.spotify_volume
          data_template:
            volume: "{{volume}}"
        stop:
          service: switch.turn_off
          data_template:
            entity_id: switch.local_spotify
        turn_on:
          service: switch.turn_on
          data_template:
            entity_id: switch.local_spotify
        turn_off:
          service: switch.turn_off
          data_template:
            entity_id: switch.local_spotify
        mute:
          service: shell_command.spotify_volume
          data_template:
            volume: >-
              {%- if states.media_player.receiver.attributes.volume_level == 0 -%}
              0.5
              {%- else -%}
              0
              {%- endif -%}

Volume set works + mute works. On/Off works. Play works.

I don't get a pause button however and I don't get a seek bar where I see the position + duration.

I have added some extra logging and I think all of them are related to self._state always being on or off. I suppose it needs a paused or playing state for the pause button and seek bar to appear.

As far as I can tell this can happen in
https://github.com/Sennevds/media_player.template/blob/master/custom_components/media_player_template/media_player.py#L478
or
https://github.com/Sennevds/media_player.template/blob/master/custom_components/media_player_template/media_player.py#L770

_update_state never sets anything else than on or off.
I also added some async_update logging statements and this seems never to be called. Not sure when this should be called. I thought for a moment I had to provide the states in the availability_template, but it seems this only expects an on or off value.

Do you have any insights where I could debug further? Or am I missing some config values?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions