From e56a6f071cec9f7a3ce1bfbb95e0c4725bba178d Mon Sep 17 00:00:00 2001 From: Lennard Beers Date: Wed, 26 Jul 2023 04:11:58 +0200 Subject: [PATCH 1/2] chore: add missing template variables to example config --- examples/configuration.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/configuration.yaml b/examples/configuration.yaml index b59b65e..5718d39 100644 --- a/examples/configuration.yaml +++ b/examples/configuration.yaml @@ -70,7 +70,7 @@ media_player: volume_up: clear_playlist: join: - play_media: + play_media: # {{ media_id }} {{ media_type }} unjoin: sound_mode_scripts: - source_scripts: \ No newline at end of file + source_scripts: From 73d06a12660b76f98394a74fe6755edf717998ea Mon Sep 17 00:00:00 2001 From: Lennard Beers Date: Wed, 26 Jul 2023 04:16:32 +0200 Subject: [PATCH 2/2] chore: add real config example --- examples/real_configuration.yaml | 614 +++++++++++++++++++++++++++++++ 1 file changed, 614 insertions(+) create mode 100644 examples/real_configuration.yaml diff --git a/examples/real_configuration.yaml b/examples/real_configuration.yaml new file mode 100644 index 0000000..e66272a --- /dev/null +++ b/examples/real_configuration.yaml @@ -0,0 +1,614 @@ + + +media_player: + - platform: template_media_player + media_players: + fernseher: + unique_id: fernseher + friendly_name: Fernseher + device_class: tv + browse_media_entity_id: media_player.fernseher_plex + global_template: > + {% set spotify = "media_player.lennard_spotify" %} + {% set plex = "media_player.fernseher_plex" %} + {% set chromecast = "media_player.fernseher_chromecast" %} + {% set adb = "media_player.fernseher_adb" %} + {% set webos = "media_player.fernseher_webos" %} + {% set soundbar = "media_player.soundbar" %} + {% set spotify_playing_on_tv = state_attr(spotify, "source") in ["SHIELD", None] %} + {% set source = state_attr(adb, "source") %} + {% set chromecast_app = state_attr(chromecast, "app_name") %} + {% set is_spotify_app = source == "Spotify" or chromecast_app == "Spotify" %} + {% set is_spotify = spotify_playing_on_tv and is_spotify_app %} + {% set is_plex = states(plex) in ["playing", "paused", "buffering"] %} + {% set is_chromecast = states(chromecast) in ["playing", "paused", "buffering"] %} + {% set is_adb = states(adb) in ["playing", "paused", "buffering", "idle"] %} + {% set is_webos = states(webos) in ["playing", "paused", "buffering"] %} + {% set player = + spotify if is_spotify else + plex if is_plex else + chromecast if is_chromecast else + adb if is_adb else + webos %} + icon_template: "mdi:television" + state_template: > + {% if is_spotify or is_plex or is_chromecast %} + {% if is_spotify_app and not is_spotify %} + idle + {% else %} + {{ states(chromecast) }} + {% endif %} + {% elif is_adb %} + {{ states(adb) }} + {% else %} + {{ states(webos) }} + {% endif %} + attribute_templates: + app_id: > + {{ state_attr(player, attribute) }} + app_name: > + {{ state_attr(player, attribute) }} + entity_picture: > + {{ state_attr(player, attribute) }} + entity_picture_local: > + {{ state_attr(player, attribute) }} + media_album_artist: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ state_attr(adb, attribute) }} + {% endif %} + media_album_name: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ state_attr(adb, attribute) }} + {% endif %} + media_artist: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ state_attr(adb, attribute) }} + {% endif %} + media_channel: > + {{ state_attr(player, attribute) }} + media_content_id: > + {{ state_attr(player, attribute) }} + media_content_rating: > + {{ state_attr(player, attribute) }} + media_content_type: > + {{ state_attr(player, attribute) }} + media_duration: > + {% if is_spotify or is_plex or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% elif is_adb %} + {{ state_attr(adb, attribute) }} + {% else %} + {{ state_attr(webos, attribute) }} + {% endif %} + media_episode: > + {{ state_attr(player, attribute) }} + media_image_hash: > + {{ state_attr(player, attribute) }} + media_image_url: > + {{ state_attr(player, attribute) }} + media_library_title: > + {{ state_attr(player, attribute) }} + media_playlist: > + {{ state_attr(player, attribute) }} + media_position: > + {% if is_spotify or is_plex or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% elif is_adb %} + {{ state_attr(adb, attribute) }} + {% else %} + {{ state_attr(webos, attribute) }} + {% endif %} + media_position_updated_at: > + {% if is_spotify or is_plex or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% elif is_adb %} + {{ state_attr(adb, attribute) }} + {% else %} + {{ state_attr(webos, attribute) }} + {% endif %} + media_season: > + {{ state_attr(player, attribute) }} + media_series_title: > + {{ state_attr(player, attribute) }} + media_summary: > + {{ state_attr(player, attribute) }} + media_title: > + {% if is_plex %} + {{ state_attr(plex, attribute) }} + {% elif is_spotify %} + {{ state_attr(spotify, attribute) }} + {% elif is_chromecast and not is_spotify_app %} + {{ state_attr(chromecast, attribute) }} + {% elif is_adb %} + {{ state_attr(adb, attribute) }} + {% else %} + {{ state_attr(webos, attribute) }} + {% endif %} + media_track: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ state_attr(adb, attribute) }} + {% endif %} + player_source: > + {{ state_attr(player, attribute) }} + repeat: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ None }} + {% endif %} + seek_position: > + {% if is_spotify or is_plex or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% elif is_adb %} + {{ state_attr(adb, attribute) }} + {% else %} + {{ state_attr(webos, attribute) }} + {% endif %} + shuffle: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ None }} + {% endif %} + sound_mode: > + {{ state_attr(soundbar, attribute) }} + source: > + {% if is_adb %} + {% set source = state_attr(adb, attribute) %} + {% else %} + {% set source = state_attr(webos, attribute) %} + {% endif %} + {% if source == "" or source == None %} + Aus + {% else %} + {{ source }} + {% endif %} + username: > + {{ state_attr(player, attribute) }} + volume_level: > + {{ state_attr(soundbar, attribute) }} + is_volume_muted: > + {{ state_attr(soundbar, attribute) }} + service_scripts: + media_next_track: + service: media_player.media_next_track + data_template: + entity_id: media_player.fernseher_android_tv + media_pause: + service: media_player.media_pause + data_template: + entity_id: media_player.fernseher_android_tv + media_play: + service: media_player.media_play + data_template: + entity_id: media_player.fernseher_android_tv + media_play_pause: + service: media_player.media_play_pause + data_template: + entity_id: media_player.fernseher_android_tv + media_previous_track: + service: media_player.media_previous_track + data_template: + entity_id: media_player.fernseher_android_tv + media_seek: + service: media_player.media_seek + data_template: + entity_id: media_player.fernseher_chromecast + seek_position: > + {{ position }} + media_stop: + service: media_player.media_stop + data_template: + entity_id: media_player.fernseher_android_tv + repeat_set: + service: media_player.repeat_set + data_template: + entity_id: media_player.lennard_spotify + repeat: > + {{ repeat }} + shuffle_set: + service: media_player.shuffle_set + data_template: + entity_id: media_player.lennard_spotify + shuffle: > + {{ shuffle }} + toggle: + service: media_player.toggle + data_template: + entity_id: media_player.fernseher_android_tv + turn_on: + service: media_player.turn_on + data_template: + entity_id: media_player.fernseher_android_tv + turn_off: + service: media_player.turn_off + data_template: + entity_id: media_player.fernseher_android_tv + volume_down: + service: media_player.volume_down + data_template: + entity_id: media_player.fernseher_android_tv + volume_mute: + service: media_player.volume_mute + data_template: + entity_id: media_player.soundbar + is_volume_muted: "{{ mute }}" + volume_set: + service: media_player.volume_set + data_template: + entity_id: media_player.soundbar + volume_level: "{{ volume }}" + volume_up: + service: media_player.volume_up + data_template: + entity_id: media_player.fernseher_android_tv + play_media: + - service: media_player.select_source + data: + entity_id: media_player.fernseher + source: Plex + - service: media_player.play_media + data_template: + entity_id: media_player.fernseher_plex + media_content_id: > + {{ media_id }} + media_content_type: > + {{ media_type }} + + sound_mode_scripts: + AI Sound Pro: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar + sound_mode: AI Sound Pro + Bass Blast: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar + sound_mode: Bass Blast + Dolby Atmos: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar + sound_mode: Dolby Atmos + Movie: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar + sound_mode: Movie + Music: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar + sound_mode: Music + Standard: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar + sound_mode: Standard + User: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar + sound_mode: User + + source_scripts: + Aus: + - service: media_player.turn_off + data_template: + entity_id: media_player.fernseher + Home: + - service: remote.send_command + data: + num_repeats: 1 + delay_secs: 0.2 + hold_secs: 0 + command: HOME + entity_id: remote.fernseher_android_tv + Plex: + - service: script.select_source + data: + tv_entity: media_player.fernseher_webos + tv_source: LG SOUND BAR + state_entity: media_player.fernseher + turn_on_entity: media_player.fernseher + stop_entity: media_player.fernseher + source_entity: media_player.fernseher_adb + source: Plex + Spotify: + - service: script.select_source + data: + tv_entity: media_player.fernseher_webos + tv_source: LG SOUND BAR + state_entity: media_player.fernseher + turn_on_entity: media_player.fernseher + stop_entity: media_player.fernseher + source_entity: media_player.fernseher_adb + source: Spotify + YouTube: + - service: script.select_source + data: + tv_entity: media_player.fernseher_webos + tv_source: LG SOUND BAR + state_entity: media_player.fernseher + turn_on_entity: media_player.fernseher + stop_entity: media_player.fernseher + source_entity: media_player.fernseher_adb + source: YouTube + ZDF: + - service: script.select_source + data: + tv_entity: media_player.fernseher_webos + tv_source: LG SOUND BAR + state_entity: media_player.fernseher + turn_on_entity: media_player.fernseher + stop_entity: media_player.fernseher + source_entity: media_player.fernseher_adb + source: ZDF + Nintendo Switch: + - service: script.select_source + data: + state_entity: media_player.fernseher + turn_on_entity: media_player.fernseher + stop_entity: media_player.fernseher + source_entity: media_player.fernseher_webos + source: Nintendo Switch + Wii U: + - service: script.select_source + data: + state_entity: media_player.fernseher + turn_on_entity: media_player.fernseher + stop_entity: media_player.fernseher + source_entity: media_player.fernseher_webos + source: Nintendo Switch + + soundbar: + unique_id: soundbar + friendly_name: Soundbar + device_class: speaker + global_template: > + {% set spotify = "media_player.lennard_spotify" %} + {% set chromecast = "media_player.soundbar_chromecast" %} + {% set lg = "media_player.soundbar_lg" %} + {% set is_spotify = state_attr(spotify, "source") in ["Soundbar", "Überall", "Wohnzimmer", "Untergeschoss"] %} + {% set is_chromecast = states(chromecast) in ["playing", "paused", "buffering"] %} + {% set player = + spotify if is_spotify + else chromecast if is_chromecast + else lg %} + icon_template: "mdi:soundbar" + state_template: > + {% if states(chromecast) != "off" %} + {{ states(chromecast) }} + {% elif states(lg) == "on" %} + idle + {% else %} + states(lg) + {% endif %} + attribute_templates: + app_id: > + {{ state_attr(player, attribute) }} + app_name: > + {{ state_attr(player, attribute) }} + entity_picture: > + {{ state_attr(player, attribute) }} + entity_picture_local: > + {{ state_attr(player, attribute) }} + media_album_artist: > + {{ state_attr(player, attribute) }} + media_album_name: > + {{ state_attr(player, attribute) }} + media_artist: > + {{ state_attr(player, attribute) }} + media_content_id: > + {{ state_attr(player, attribute) }} + media_content_type: > + {{ state_attr(player, attribute) }} + media_duration: > + {% if is_spotify or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% else %} + {{ state_attr(lg, attribute) }} + {% endif %} + media_image_hash: > + {{ state_attr(player, attribute) }} + media_image_url: > + {{ state_attr(player, attribute) }} + media_playlist: > + {{ state_attr(player, attribute) }} + media_position: > + {% if is_spotify or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% else %} + {{ state_attr(lg, attribute) }} + {% endif %} + media_position_updated_at: > + {% if is_spotify or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% else %} + {{ state_attr(lg, attribute) }} + {% endif %} + media_title: > + {{ state_attr(player, attribute) }} + media_track: > + {{ state_attr(player, attribute) }} + repeat: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ None }} + {% endif %} + seek_position: > + {% if is_spotify or is_chromecast %} + {{ state_attr(chromecast, attribute) }} + {% else %} + {{ state_attr(lg, attribute) }} + {% endif %} + shuffle: > + {% if is_spotify %} + {{ state_attr(spotify, attribute) }} + {% else %} + {{ None }} + {% endif %} + sound_mode: > + {{ state_attr(lg, attribute) }} + source: > + {{ state_attr(lg, attribute) }} + volume_level: > + {{ state_attr(lg, attribute) }} + is_volume_muted: > + {{ state_attr(lg, attribute) }} + + service_scripts: + media_next_track: + service: media_player.media_next_track + data_template: + entity_id: media_player.soundbar_chromecast + media_pause: + service: media_player.media_pause + data_template: + entity_id: media_player.soundbar_chromecast + media_play: + service: media_player.media_play + data_template: + entity_id: media_player.soundbar_chromecast + media_play_pause: + service: media_player.media_play_pause + data_template: + entity_id: media_player.soundbar_chromecast + media_previous_track: + service: media_player.media_previous_track + data_template: + entity_id: media_player.soundbar_chromecast + media_seek: + service: media_player.media_seek + data_template: + entity_id: media_player.fernseher_chromecast + seek_position: > + {{ position }} + media_stop: + service: media_player.media_stop + data_template: + entity_id: media_player.soundbar_chromecast + repeat_set: + service: media_player.repeat_set + data_template: + entity_id: media_player.lennard_spotify + repeat: > + {{ repeat }} + shuffle_set: + service: media_player.shuffle_set + data_template: + entity_id: media_player.lennard_spotify + shuffle: > + {{ shuffle }} + toggle: + service: media_player.toggle + data_template: + entity_id: media_player.soundbar_chromecast + turn_on: + service: media_player.turn_on + data_template: + entity_id: media_player.soundbar_chromecast + volume_down: + service: media_player.volume_down + data_template: + entity_id: media_player.soundbar_lg + volume_mute: + service: media_player.volume_mute + data_template: + entity_id: media_player.soundbar_lg + is_volume_muted: "{{ mute }}" + volume_set: + service: media_player.volume_set + data_template: + entity_id: media_player.soundbar_lg + volume_level: "{{ volume }}" + volume_up: + service: media_player.volume_up + data_template: + entity_id: media_player.soundbar_lg + + sound_mode_scripts: + AI Sound Pro: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar_lg + sound_mode: AI Sound Pro + Bass Blast: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar_lg + sound_mode: Bass Blast + Dolby Atmos: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar_lg + sound_mode: Dolby Atmos + Movie: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar_lg + sound_mode: Movie + Music: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar_lg + sound_mode: Music + Standard: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar_lg + sound_mode: Standard + User: + service: media_player.select_sound_mode + data_template: + entity_id: media_player.soundbar_lg + sound_mode: User + + source_scripts: + Bluetooth: + - service: script.select_source + data: + state_entity: media_player.soundbar_lg + turn_on_entity: media_player.soundbar_lg + source_entity: media_player.soundbar_lg + source: Bluetooth + HDMI: + - service: script.select_source + data: + state_entity: media_player.soundbar_lg + turn_on_entity: media_player.soundbar_lg + source_entity: media_player.soundbar_lg + source: HDMI + Optical/HDMI ARC: + - service: script.select_source + data: + state_entity: media_player.soundbar_lg + turn_on_entity: media_player.soundbar_lg + source_entity: media_player.soundbar_lg + source: Optical/HDMI ARC + USB2: + - service: script.select_source + data: + state_entity: media_player.soundbar_lg + turn_on_entity: media_player.soundbar_lg + source_entity: media_player.soundbar_lg + source: USB2 + Wi-Fi: + - service: script.select_source + data: + state_entity: media_player.soundbar_lg + turn_on_entity: media_player.soundbar_lg + source_entity: media_player.soundbar_lg + source: Wi-Fi + +