Sennevds / media_player.template

Template media_player for Home Assistant
MIT License
126 stars 23 forks source link

actions do not match Media_player actions #32

Closed kryptonitecb3 closed 2 years ago

kryptonitecb3 commented 3 years ago

I came across your custom component and wanted to first say thank you. I'm trying to do exactly what you did, start with an Esphome IR blaster, and make a media player from it.

I've been running in to issues with the terminology you have listed and the ones in the Home Assistant documentation. When I try to use certain definitions from media_player I get errors when I run configuration validation (https://www.home-assistant.io/integrations/media_player/).

You have the list in the readme but I get errors when I try to use media_play, media_pause, media_next_track, media_previous_track.

From trial and error I have figured out media_play=play, media_pause=pause. However I can't get media_previous_track, or media_next_track to work.

Working config:

  - platform: media_player_template
    media_players:
      living_room_tv:
        friendly_name: Living Room TV
        device_class: tv
        value_template: >
          {% if is_state("binary_sensor.living_room_samsung_tv_status", "on") -%}
            on
          {%- else -%}
            off
          {%- endif %}
        turn_on:
          service: switch.turn_on
          target:
            entity_id: switch.lr_samsung_tv_power
        turn_off:
          service: switch.turn_on
          target:
            entity_id: switch.lr_samsung_tv_power
        volume_up:
          service: switch.turn_on
          target:
            entity_id: switch.lr_samsung_tv_volume_up
        volume_down:
          service: switch.turn_on
          target:
            entity_id: switch.lr_samsung_tv_volume_down
        mute:
          service: switch.turn_on
          target:
            entity_id: switch.lr_samsung_tv_mute
        play:
          service: switch.turn_on
          target:
            entity_id: switch.lr_samsung_tv_play
        pause:
          service: switch.turn_on
          target:
            entity_id: switch.lr_samsung_tv_pause
#        media_previous_track:
#          service: switch.turn_on
#          target:
#            entity_id: switch.lr_samsung_tv_rewind
#        media_next_track:
#          service: switch.turn_on
#          target:
#            entity_id: switch.lr_samsung_tv_forward
        inputs:
          source 1:
            service: switch.toggle
            target:
              entity_id: switch.lr_samsung_tv_hdmi_1
          source 2:
            service: switch.toggle
            target:
              entity_id: switch.lr_samsung_tv_hdmi_2

Configuration validation error: Invalid config for [media_player.media_player_template]: [media_previous_track] is an invalid option for [media_player.media_player_template]. Check: media_player.media_player_template->media_players->living_room_tv->media_previous_track. (See ?, line ?).

Working universal media player config:

media_player:
  - platform: universal
    device_class: tv
    name: Living Room Samsung TV
    state_template: "{{is_state('binary_sensor.living_room_samsung_tv_status', 'on')}}"
    commands:
      turn_on:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_power
      turn_off:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_power
      volume_up:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_volume_up
      volume_down:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_volume_down
      volume_mute:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_mute
      media_play:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_play
      media_pause:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_pause
      media_previous_track:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_rewind
      media_next_track:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_forward
      select_source:
        service: switch.turn_on
        target:
          entity_id: switch.lr_samsung_tv_source
    attributes:
      state: binary_sensor.living_room_samsung_tv_status
Tonguc-Endem commented 3 years ago

I have the same problem. I can not even get the next and previous buttons to appear.

media_player:
  - platform: media_player_template
    media_players:
      receiver:
        friendly_name: "Audio-Video Receiver"
        device_class: receiver
        current_source_template: "{{ states('sensor.avr_source') }}"
        value_template: >
          {% if is_state("switch.avr_power", "on") -%}
            on
          {%- else -%}
            off
          {%- endif %}
        turn_on:
          service: switch.turn_on
          data_template:
            entity_id: switch.avr_on
        turn_off:
          service: switch.turn_on
          data_template:
            entity_id: switch.avr_off
        volume_up:
          service: switch.turn_on
          data_template:
            entity_id: switch.avr_volume_up
        volume_down:
          service: switch.turn_on
          data_template:
            entity_id: switch.avr_volume_down

        play:
          service: media_player.media_play
          data_template:
            entity_id: media_player.str_dn1080_2
        pause:
          service: media_player.media_pause
          data_template:
            entity_id: media_player.str_dn1080_2
        stop:
          service: media_player.media_stop
          service_data:
            entity_id: media_player.str_dn1080_2            
        next:
          service: media_player.media_next_track
          data_template:
            entity_id: media_player.str_dn1080_2
        previous:
          service: media_player.media_previous_track
          data_template:
            entity_id: media_player.str_dn1080_2

        sound_modes:
          Direct:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_soundfield_direct
          Multi Channel Stereo:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_soundfield_multi_channel_stereo
          2 Channel Stereo:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_soundfield_2_channel_stereo
          Front Surround:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_soundfield_front_surround
          Neural:X:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_soundfield_neural_x
          Dolby Surround:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_soundfield_dolby_surround
          A.F.D.:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_soundfield_a_f_d

        inputs:
          Turntable:   # SA-CD/CD
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_sa_cd_cd
          Computer:     # VIDEO 1
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_video_1
          Apple TV:  # VIDEO 2
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_video_2
          Cable TV:  # SAT/CATV
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_sat_catv
          TV:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_tv
          DVD:   # BD/DVD
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_bd_dvd
          GAME:   # GAME
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_game
          FM Tuner:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_fm_tuner
          USB:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_usb
          Bluetooth:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_bluetooth
          Home Network:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_home_network
          Music Service List:
            service: switch.turn_on
            data_template:
              entity_id: switch.avr_source_music_service_list
#------------------------------------------------       
        set_volume:
          service: number.set_value
          data:
            entity_id: number.avr_volume
            #value: "{{((volume*74)|round|string|replace('.0', ''))|int}}"
            value: "{% set vol = ((volume*100)|round|string|replace('.0', ''))|int  -%}{% if vol > 74 %}74{% else %}{{vol}}{% endif %}"
        #current_volume_template: "{{ states('number.avr_volume')|int/74 }}"
        current_volume_template: "{{ states('number.avr_volume')|int/100 }}"    
        mute:
          service: switch.toggle
          data:
            entity_id: switch.avr_mute
        current_is_muted_template: >
          {% if is_state("switch.avr_mute", "on") -%}
            True
          {%- else -%}
            False
          {%- endif %}
        title_template: "{{ states.media_player.str_dn1080_2.attributes.media_title }}"
        media_content_type_template: "{{ states.media_player.str_dn1080_2.attributes.media_content_type }}"
        media_image_url_template: "{{ states.media_player.str_dn1080_2.attributes.entity_picture }}"
        media_duration_template: "{{ states.media_player.str_dn1080_2.attributes.media_duration }}"
        current_position_template: "{{ states.media_player.str_dn1080_2.attributes.media_position }}"
        artist_template: "{{ states.media_player.str_dn1080_2.attributes.media_artist }}"
        album_template: "{{ states.media_player.str_dn1080_2.attributes.media_album_name }}"
        current_sound_mode_template: "{{ states('sensor.avr_sound_field') }}"
Sennevds commented 3 years ago

@kryptonitecb3 it's 'previous' and 'next' If you want to see the buttons the value_template of the media player can't be just 'on' it should be 'playing', 'paused'