sennevds / media_player.template Goto Github PK
View Code? Open in Web Editor NEWTemplate media_player for Home Assistant
License: MIT License
Template media_player for Home Assistant
License: MIT License
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?
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..
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'
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?
Hi,
is there a way to set a dynamic source list, e.g. all values from an input_select?
regards,
justr
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
the seek bar does not move while the media is playing, as soon as i pause, it'll catch up to what it should be.
After updating media_player.template does not start. This is due #42601
Hello,
I set the volume by "entity_id: number.volume".
I'm trying with this code but the volume doesn't work:
media_player:
platform: media_player_template
media_players:
2bagno:
value_template: >
{% if is_state("switch.omnilink_zone_2", "on") -%}
on
{%- else -%}
off
{%- endif %}
turn_on:
service: switch.turn_on
data_template:
entity_id: switch.omnilink_zone_2
turn_off:
service: switch.turn_off
data_template:
entity_id: switch.omnilink_zone_2
set_volume:
service: number.set_value
data:
entity_id: number.volume
value: "{{volume}}"
only input_text entity are admitted?
Are you aware of https://www.home-assistant.io/integrations/universal/ ?
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
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
Testing this using an input_number. The slider on the media player goes from 0-100, but only sets a value of 0-1
Maybe I'm just stupid, but what can you do with this integration? I cannot derive that from the description.
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'
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!
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.
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.
I can not understand why it works And I so need it
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.
When those options are added to configuration.yaml it throws an error saying that those options are incorrect for this component. Without them and with other defaults (from README.md) it passes no problem.
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?
If you want, I can contribute some advanced CI to your repository in a PR. Let me know if you want that.
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:
Anyways, this is just a suggestion I had for this otherwise great component! Hope to see you publish it one day ๐
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.
I'm using HA 0.111.4 with this custom_component.
I've put the files correctly within the custom_components folder:
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'
I have DENON Receaver with HEOS
so there are two ZONEs main and secondary
How can I add zone-choosing?
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!
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
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)?
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.
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
thanks again
Wow this is awesome! This seems like it may be viable candidate for HACS if not merging upstream into HA itself?
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:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.