Universal media player
A universal media player can combine multiple existing entities in Home Assistant into a single media player entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more]. This is used to create a single media player entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] that can control an entire media center.
Multiple media player entities may be controlled from a universal media player. Additionally, the universal media player can enable volume and power commands to be directed to other Home Assistant entities. This enables the media player power and volume commands to control devices like a television, amplifier or audio receiver, for example.
To use a universal media player add it to your configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file.
After changing the configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes.
Configuration Variables
A template that will allow to select (override) active child. Must return the entity_id
of the child selected as active, or None
to use the default behavior.
A template can be specified to render the state of the media player. In this way, the state may depend on entities that are not themselves media players, like switches or input booleans.
Media player commands to be overridden. Almost all media player action commands may be overridden. Example entries are turn_on
, turn_off
, select_source
, volume_set
, volume_up
, volume_down
, volume_mute
, media_play
, media_pause
, media_stop
, media_previous_track
, media_next_track
and play_media
(refer to the media_player
documentation to see the full list).
Attributes that can be overridden. Most, if not all, media player attributes can be overridden. Example entries are is_volume_muted
, state
, source
, source_list
and volume_level
. The values should be an entity ID and state attribute separated by a pipe character (|). If the entity ID’s state should be used, then only the entity id needs to be provided.
Allows override the browse media entity to desired media player.
The device class that this entity represents. Can be tv
, speaker
, or receiver
.
The universal media player will primarily imitate one of its children
. The universal media player will control the first child on the list that is active (not idle/off). The universal media player will also inherit its state from the first active child if a state_template
is not provided. Entities in the children:
list must be media players, but the state template can contain any entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more].
Using active_child_template
will allow you to specify an active entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] if the default behavior is unsuitable for your task. The template must return the entity_id
of the child that will be selected as active or None
to return the default behavior.
It is recommended that the command turn_on
, the command turn_off
, and the attribute state
all be provided together. The state
attribute indicates if the media player is on or off. If state
indicates the media player is off, this status will take precedence over the states of the children. If all the children are idle/off and state
is on, the Universal Media Player’s state will be on. If not provided, the toggle
command will delegate to turn_on
or turn_off
based on the state
.
It is also recommended that the command volume_up
, the command volume_down
, the command volume_mute
, and the attribute is_volume_muted
all be provided together. The attribute is_volume_muted
should return either True or the on state when the volume is muted. The volume_mute
actionActions are used in several places in Home Assistant. As part of a script or automation, actions define what is going to happen once a trigger is activated. In scripts, an action is called sequence. [Learn more] should toggle the mute setting.
When providing select_source
as a command, it is recommended to also provide the attributes source
, and source_list
. The source
attribute is the currently select source, while the source_list
attribute is a list of all available sources.
When using state_template
, if you use a template that depends on the current time it is recommended to use now()
. Using now()
will cause templates to be refreshed at the start of every new minute. For more information see the time section in the template documentation.
The browse_media_entity
parameter allows you to specify which media player will be used in media browser.
Usage examples
Chromecast & Kodi control with switches
In this example, a switch is available to control the power to the television. Switches are also available to turn the volume up, turn the volume down, and mute the audio. These could be command line switches or any other entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] in Home Assistant. The turn_on
and turn_off
commands will be redirected to the television, and the volume commands will be redirected to an audio receiver. The select_source
command will be passed directly to an A/V receiver.
The children are a Chromecast and a Kodi player. If the Chromecast is playing, the Universal Media Player will reflect its status. If the Chromecast is idle and Kodi is playing, the universal media player will change to reflect its status.
Kodi CEC-TV control
In this example, a Kodi Media Player runs in a CEC capable device (OSMC/OpenElec running in a Raspberry Pi 24/7, for example), and, with the JSON-CEC Kodi add-on installed, it can turn on and off the attached TV.
We store the state of the attached TV in an input boolean, so we can differentiate the TV being on or off, while Kodi is always ‘idle’, and use the universal media player to render its state with a template. We now can differentiate between the ‘idle’ and the ‘off’ state (being the second when it is idle and the TV is off).
Because the input boolean used to store the TV state is only changing when using the Home Assistant turn_on
and turn_off
actions, and Kodi could be controlled by so many ways, we also define some automations to update this Input Boolean when needed.
The complete configuration is:
Harmony remote example
The complete configuration is:
Denon AVR & HEOS
This media player combines the media players provided by the Denon AVR and HEOS integrations.
Features:
- Volume control via Denon entity (might be more fine-granular than HEOS volume control)
- ON/OFF button via Denon entity (not provided by HEOS media player)
- Sound mode selector via Denon entity (not provided by HEOS media player)
- Album art & Metadata via HEOS entity (not provided by Denon media player)
The complete configuration is:
Override active children
This example shows how you can use active_child_template
: