Giter VIP home page Giter VIP logo

media_player.template's Introduction

media_player.template

media_player template for Home Assistant

GitHub Release hacs_badge License

Project Maintenance GitHub Activity

Community Forum

Current implemented features:

  • on_action
  • off_action
  • play_action
  • play_pause_action
  • stop_action
  • pause_action
  • next_action
  • previous_action
  • volume_up_action
  • volume_down_action
  • mute_action
  • source list
  • current source
  • title
  • artist
  • album
  • current volume
  • set_volume action
  • play_media action (not tested)
  • media_content_type_template
  • media_image_url_template
  • media_episode_template
  • media_season_template
  • media_series_title_template
  • media_album_artist_template
  • current_is_muted_template
  • device_class

media_content_type_template can be one of the following values:

  • tv_show
  • music
  • movie
  • video

based on this value other parameters are shown ex artist is only shown when type is music

Variables used:

set_volume:

  • {volume}

mute:

  • {is_muted}

play_media:

  • {media_type}
  • {media_id}

Preview config:

media_player:
  - platform: media_player_template
    media_players:
      receiver:
        friendly_name: Receiver
        device_class: receiver
        current_source_template: "{{ states('input_text.selected_source') }}"
        value_template: >
          {% if is_state("input_boolean.receiver_on", "on") -%}
            on
          {%- else -%}
            off
          {%- endif %}
        turn_on:
          service: switch.turn_on
          data_template:
            entity_id: switch.receiver_on
        turn_off:
          service: switch.turn_on
          data_template:
            entity_id: switch.receiver_off
        volume_up:
          service: switch.turn_on
          data_template:
            entity_id: switch.volume_up
        volume_down:
          service: switch.turn_on
          data_template:
            entity_id: switch.vol
        inputs:
          source 1:
            service: input_boolean.turn_on
            data_template:
              entity_id: input_boolean.source_1
          source 2:
            service: input_boolean.turn_on
            data_template:
              entity_id: input_boolean.source_2
        set_volume:
          service: input_text.set_value
          data:
            entity_id: input_text.selected_volume
            value: "{{volume}}"
        mute:
          service: input_number.set_value
          data:
            entity_id: input_number.selected_is_muted
            value: "{{is_muted}}"
        current_is_muted_template: >
          {{ states('input_boolean.is_muted') }}
        album_art_template: "{{ states('input_text.album_art') }}"
        title_template: "{{ states('input_text.title') }}"
        album_template: "{{ states('input_text.album') }}"
        artist_template: "{{ states('input_text.artist') }}"

media_player.template's People

Contributors

antoni-czaplicki avatar chbartsch avatar colinrobbins avatar dvv avatar ehendrix23 avatar golles avatar ktibow avatar maxi1134 avatar pschmitt avatar sennevds avatar seperis avatar wrt54g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

media_player.template's Issues

album_art doesn't exist-is it actually entity_picture_tempate ?

I had some time and was checking all your templates. album_art is the only one (I think) that I can't make work. I went to HA's media_player component and the template component and looked also at the sonos integration and a couple of others; album_art doesn't show as a possibility anywhere, but entity_picture_template does. I'm going to guess they're synonymous; when I check my sonos, it looks like the album art appears under entity_picture in attributes.

You have both in the media_player_template under Schema, but entity_picture_template doesn't appear just above it in the list of your templates starting on line 66. I didn't want to change it without your permission, since I could be wrong or I'm making a mistake in trying to get it display.

ETA: or is album art equal to media_image_url? Sonos seemed to be using entity when music plays, but that doesn't mean it's universal.

media_series missing _title in code

media_series_title isn't working due to this bit of code:

Problem:
Line 437: "_media_series", self._media_series_title_template

Correction:
"_media_series" to "_media_series_title"

Tested in my copy in HA and that fixed the problem. Otherwise is working fantastically.

feature request: "Browse_Media"

Hi
first of thanks for this awesome integration.

it would be great if the "browse_media" function could be implemented

clicking this on the native media_player integration opens HomeAssistant's media section (c.f. screenshot below -- not my screenshot). Would be great to have this in media_player.template as well
Screenshot 2024-01-21 163820
thanks again

Does not work in HA core-2022.2.0b6

Hi,

This integration failes to load in HA core-2022.2.0b6.
This was previousl working in 2021.11.1
My log file is below.

Logger: homeassistant.components.media_player
Source: custom_components/media_player_template/media_player.py:298
Integration: Media Player (documentation, issues)
First occurred: 15:46:08 (1 occurrences)
Last logged: 15:46:08

Error while setting up media_player_template platform for media_player
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/media_player_template/media_player.py", line 157, in async_setup_platform
    async_add_entities(await _async_create_entities(hass, config))
  File "/home/homeassistant/.homeassistant/custom_components/media_player_template/media_player.py", line 205, in _async_create_entities
    MediaPlayerTemplate(
  File "/home/homeassistant/.homeassistant/custom_components/media_player_template/media_player.py", line 298, in __init__
    super().__init__(
TypeError: __init__() missing 1 required positional argument: 'hass'

Naming consistency - media_album_artist_template

This is super minor and basically a matter of naming consistency

To keep consistency, you might change "media_album_artist_template" to "album_artist_template" for consistency in your template. Both 'artist' and "album" don't have 'media_' in front, which I assume is because they're music; "media_album_artist_template" also is music-exclusive so as a visual reference to what content-type this template is associated with. I noticed--and appreciate--that tv-related uses the prefix 'media_' (season, episode, series name). It's not a big deal, and I verified changing the name doesn't make any real difference other than when I'm reading the code. I can make the change and do the pull if you want, but like I said, it's really just a code consistency thing.

This template is working gangbusters for my Combined Media Player, so thank you. This has been bar none the most useful and fun single custom_component I've played with.

Shuffle and repeat

First of, looks lika you built a great and flexible integration that solves multiple issues with the Universal media player integration. I'm trying to merge spotify players with cast players and the universal media player don't allow all attributes to overwritten in a nice way with templates like your integration. What's missing in both tho is to be able to configure shuffle and repeat mode. Would love to see that in this integration!

How to set current volume

How can I set the current volume for my template media_player?

I tried current_volume_template but that is not allowed.
I don't see it in the example config.

Publish to HACS (or HA)

Wow this is awesome! This seems like it may be viable candidate for HACS if not merging upstream into HA itself?

Choosing ZONE

I have DENON Receaver with HEOS
so there are two ZONEs main and secondary
How can I add zone-choosing?

No module named 'homeassistant.components.template.media_player

I'm using HA 0.111.4 with this custom_component.

I've put the files correctly within the custom_components folder:

imagem

And I'm using this yaml configuration:

media_player:
  - platform: template
    media_players:
      hisense_tv:
        friendly_name: 'Hisense H43B7320'
        current_source_template: "{{ states('sensor.tv_source') }}"
        value_template: >
          {% if is_state('device_tracker.hisense_tv', 'home') %}
            {{ 'on' }}
          {% else %}
            {{ 'off' }}
          {% endif %}
        turn_on:
          service: switch.turn_on
          entity_id: switch.hisense_tv
        turn_off:
          service: switch.turn_off
          entity_id: switch.hisense_tv
        volume_up:
          service: script.executa_hisense_volume_up
        volume_down:
          service: script.executa_hisense_volume_down
        input_templates:
          TV:
            service: script.executa_hisense_input_tv
          HDMI 1:
            service: script.executa_hisense_input_hdmi_1
          HDMI 2:
            service: script.executa_hisense_input_hdmi_2
          HDMI 3:
            service: script.executa_hisense_input_hdmi_3
          Netflix:
            service: script.executa_hisense_netflix
          Home:
            service: script.executa_hisense_home

But I get this error message when checking the configuration:

Platform error media_player.template - No module named 'homeassistant.components.template.media_player'

Update component to use event.async_track_template_result instead of template.extract_entities

Apparently a lot has changed for the template integrations in Hass. template.extract_entities is now deprecated and we have to use event.async_track_template_result. They also added a TemplateEntity to the template domain.

This needs a lot of changes in my code. At this moment the component still works(0.115) but probably will break in upcoming versions.
If anybody can help to change the code to these changes that would be really helpfull!

[Feature] Add device_class

First off, thank you very much. Been waiting for something like this quite a long time. :-)

This feature request is to add a configuration item for device_class. A media player currently can have a device class of tv, speaker, or receiver.
There are other integrations that use this to determine what the capabilities are. For example, the HomeKit integration creates a "MediaPlayer" in HomeKit for media player, but when the device class for the HASS media player is set to tv then it creates a "TelevisionMediaPlayer" instead.

Thx.

icon_template not working?

Hey, icon_template is not documented but present in the source code. I can't seem to get it working, it is being ignored. Any way around this?

Volume control

Hi! I am looking to use this integration to replace an input_number for centralized volume control. Is it possible to make an device/entity with only a value for volume? (0.0 - 1.0). I am new to this so not great at yaml/configs..

[FEATURE REQUEST] Ability to add multiple entity ids to services.

First of all, I wanna say thanks for this card! It has been wonderful.

I am now trying to create a template media_player that would basically control the media_players in the room in which I am.

I tried using the following with no success: [see code]

Would it be possible to try and implement this possibility? It would be much appreciated!

  template_following_media_player:
    friendly_name: Template Following Media Player
    device_class: speaker
    value_template: >
            {% set ns = namespace( cast_entity = "media_player.livingroom_chromecast", template_entity = "" ) %}
            {% set ns.final_entity = ns.cast_entity %}   {# Declare Variables#}                
            {% for media_player in states.media_player %} 
              {% if "plex" in media_player.entity_id and media_player.state != "unavailable" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                  {% if state_attr( ns.final_entity, 'media_title') %}
                    {% if  state_attr( ns.cast_entity, 'media_title') in ( media_title | string )%}
                    {% set ns.template_entity = entity %}
                    {% endif %}
                  {% elif state_attr( ns.final_entity, 'media_series_title') %}
                    {% if  state_attr( ns.cast_entity, 'media_series_title') in ( media_series_title | string )%}
                    {% set ns.template_entity = entity %}
                    {% endif %}
                  {% endif %}                      
              {% endif %}                  
            {% endfor %}                
            {% if ns.template_entity == "" %}
                {% set ns.template_entity = ns.cast_entity %}
            {% endif %}
            {% if ns.template_entity != ns.cast_entity %}                  
              {{states(ns.template_entity)}}
            {% elif state_attr( ns.cast_entity, 'media_title')  %} 
              {{states(ns.cast_entity)}}
            {% else %}
              off
            {% endif %}
    next:
      service: media_player.media_seek
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
        seek_position: 56000
    turn_on:
      service: media_player.turn_on
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
    stop:
      service: media_player.media_stop
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
    turn_off:
      service: media_player.turn_off
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
    volume_up:
      service: media_player.volume_up
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
    volume_down:
      service: media_player.volume_down
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
    mute:
      service: media_player.volume_mute
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
    set_volume:
      service: media_player.volume_set
      data_template:
        entity_id: >
            {% set location = states('sensor.maxi_location_v3') %}  
            {% set ns = namespace( entities = [], final_entities = []  )%}
            
            {% for media_player in states.media_player %} 
              {% if location in media_player.entity_id  and  "template" not in media_player.entity_id and "plex" not in media_player.entity_id and media_player.state != "unavailable" and media_player.state != "off" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                {% set ns.entities = ns.entities + [entity] %}
              {% endif %}                  
            {% endfor %}  
            
            {% for entity in ns.entities %}  
            {% set is_muted = state_attr(entity, "is_volume_muted") %}
              {% if is_muted == false %}
                 {% if "speaker" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% if ns.final_entities | length == 0 %}
                 {% if "chromecast" in entity %}
                   {% set ns.final_entities = ns.final_entities + [entity] %}
                {% endif %}
                {% endif %}
              {% endif %}
            {% endfor %}
            {% for entity in ns.final_entities %}
            - {{entity}}{% endfor %}
        volume_level: "{{ volume }}"
    current_is_muted_template: "{{state_attr( 'media_player.livingroom_chromecast', 'is_volume_muted') }}"
    media_image_url_template: >
            {% set ns = namespace( cast_entity = "media_player.livingroom_chromecast", template_entity = "" ) %}
            {% set ns.final_entity = ns.cast_entity %}   {# Declare Variables#}                
            {% for media_player in states.media_player %} 
              {% if "plex" in media_player.entity_id and media_player.state != "unavailable" %}
                {% set entity = media_player.entity_id %}
                {% set media_title = state_attr( entity, 'media_title') %}
                {% set media_series_title = state_attr( entity, 'media_series_title') %}
                {% set media_series_episode = state_attr( entity, 'media_espisode') %}
                {% set media_series_season = state_attr( entity, 'media_season') %}
                  {% if state_attr( ns.final_entity, 'media_title') %}
                    {% if  state_attr( ns.cast_entity, 'media_title') in ( media_title | string )%}
                    {% set ns.template_entity = entity %}
                    {% endif %}
                  {% elif state_attr( ns.final_entity, 'media_series_title') %}
                    {% if  state_attr( ns.cast_entity, 'media_series_title') in ( media_series_title | string )%}
                    {% set ns.template_entity = entity %}
                    {% endif %}
                  {% endif %}                      
              {% endif %}                  
            {% endfor %}                
            {% if ns.template_entity == "" %}
                {% set ns.template_entity = ns.cast_entity %}
            {% endif %}
            {% if ns.template_entity != ns.cast_entity %}                  
              {{state_attr(ns.template_entity, 'entity_picture')}}
            {% elif state_attr( ns.cast_entity, 'media_title')  %} 
              {{state_attr(ns.cast_entity, 'entity_picture')}} 
            {% else %}
              off
            {% endif %}
    media_series_title_template: "{{state_attr( 'media_player.livingroom_chromecast', 'media_series_title') }}"
    title_template: "{{state_attr( 'media_player.livingroom_chromecast', 'media_title') }}"
    media_episode_template: "{{state_attr( 'media_player.livingroom_chromecast', 'media_episode') }}"
    media_season_template: "{{state_attr( 'media_player.livingroom_chromecast', 'media_season') }}"
    unique_id: template_following_media_player

Deprecated supported features values - HA Core 2024.01.0b2 and above

Startup of HA Core 2024.01.0b2 and above presents a deprecation message in the logs:

Entity media_player.xxxx (<class 'custom_components.media_player_template.media_player.MediaPlayerTemplate'>) is using deprecated supported features values which will be removed in HA Core 2025.1. Instead it should use <MediaPlayerEntityFeature.PAUSE|VOLUME_MUTE|PREVIOUS_TRACK|NEXT_TRACK|TURN_ON|TURN_OFF|VOLUME_STEP|SELECT_SOURCE|STOP|PLAY|SELECT_SOUND_MODE: 89529>, please create a bug report at https://github.com/Sennevds/media_player.template/issues and reference https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation

Seems there's quite a long time to address this though, and the created media players continue to function as normal:

Add Version key in json

Hi,

I found a warning message in logs. I'm quite sure that you already know it but if don't please have a look at it:

No 'version' key in the manifest file for custom integration 'media_player_template'. As of Home Assistant 2021.6, this integration will no longer be loaded. Please report this to the maintainer of 'media_player_template'

Media Position and Duration?

Is there any way to set the media position and duration attributes for controlling position of currently playing media? Kinda like how the media player card lets you control kodi content

Consider adding all (most?) of the default Media Player services

I just wanna say first, great job on this component! I'm not sure if you realized but you're close to finishing this request

https://community.home-assistant.io/t/media-player-as-mqtt/204396

I installed your component and set it up with my MQTT enabled media player and the basic functionality works great! I can play/pause, skip, go back etc.

You should consider adding the other remaining services that Media Player provides. Mainly these are the major ones for a media player:

  • volume_set
  • media_play_pause
  • play_media (so you can show media_content_type stuff such as song name, album etc.)

Anyways, this is just a suggestion I had for this otherwise great component! Hope to see you publish it one day ๐Ÿ˜„

Cannot get pause/seek/current_position_template/media_duration_template working

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?

value_template doesn't seem to be working

The state of my media player is always off, even though my value_template is returning "on".

platform: template
media_players:
upstairs:
friendly_name: Upstairs
value_template: >
{% if is_state("input_boolean.upstairs_music_power", "on") -%}
on
{%- else -%}
off
{%- endif %}
turn_on:
service: input_boolean.turn_on
data_template:
entity_id: input_boolean.upstairs_music_power
turn_off:
service: input_boolean.turn_off
data_template:
entity_id: input_boolean.upstairs_music_power
volume_up:
service: input_number.increment
data_template:
entity_id: input_number.upstairs_music_volume
volume_down:
service: input_number.decrement
data_template:
entity_id: input_number.upstairs_music_volume

Receiving message in HA log that media_player.template is using depreciating features that will be unavailable in 2025

The message in my log file is:

(MainThread) [homeassistant.helpers.entity] Entity media_player.now_playing (<class 'custom_components.media_player_template.media_player.MediaPlayerTemplate'>) is using deprecated supported features values which will be removed in HA Core 2025.1. Instead it should use <MediaPlayerEntityFeature.TURN_ON|TURN_OFF|VOLUME_STEP|SELECT_SOURCE|SELECT_SOUND_MODE: 68992>, please create a bug report at https://github.com/Sennevds/media_player.template/issues and reference https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation

I love this template and is making my life so much easier. Is this on anyone's radar to be fixed?

About sound mode template

Hi
Is there possible adding a "sound mode template" feature?
And how about adding a switch for "one button control source" (IR remoted, can not be specified)?

actions do not match Media_player actions

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.