Skip to content

Commit

Permalink
replace adb source detection with androidtv remote
Browse files Browse the repository at this point in the history
- Add Android TV source sensors as select lists
  - Disable old sensors
- Update universal media players with new source sensors/selectors
- Add Android app id to name translations in `variables.jinja`
- Update media_icon macro in `util.jinja`
- Update automations to use new source sensors
- Update UI to use source names and not app ids
  • Loading branch information
zanix committed Oct 8, 2023
1 parent f6d0988 commit 8c79473
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 82 deletions.
24 changes: 16 additions & 8 deletions automations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@
description: Changes the reciever sound mode based on Source
trigger:
- platform: state
entity_id: media_player.family_room_shield
entity_id: media_player.family_room_universal
attribute: source
- platform: state
entity_id: media_player.denon_avr_s760h
Expand All @@ -2244,6 +2244,10 @@
- condition: state
entity_id: media_player.denon_avr_s760h
state: 'off'
- condition: state
entity_id: media_player.family_room_universal
attribute: source
state: nl.rogro82.pipup
- condition: template
value_template: '{{ sound_mode != state_attr("media_player.denon_avr_s760h", "sound_mode")
}}'
Expand All @@ -2255,23 +2259,27 @@
sound_mode: '{{ sound_mode }}'
variables:
sound_mode: "{%- if trigger.to_state.attributes.source == 'Spotify' -%}\n MCH
STEREO\n{%- elif trigger.to_state.attributes.source in ['SmartTube', 'Youtube',
'YouTube Kids', 'DisneyNow', 'PBS Kids', 'Hulu'] -%}\n DOLBY DIGITAL\n{%- else
-%}\n DIRECT\n{%- endif -%}"
STEREO\n{%- elif trigger.to_state.attributes.source in ['SmartTube', 'YouTube',
'YouTube Kids', 'DisneyNow', 'PBS Kids'] -%}\n DOLBY DIGITAL\n{%- else -%}\n
\ DIRECT\n{%- endif -%}"
mode: single
- id: '1665696345535'
alias: ⏯ Living Room Sound Mode
description: Changes the reciever sound mode based on Source
trigger:
- platform: state
entity_id: media_player.living_room_shield
entity_id: media_player.living_room_universal
attribute: source
condition:
- condition: not
conditions:
- condition: state
entity_id: media_player.yamaha_rx_v679
state: 'off'
- condition: state
entity_id: media_player.living_room_universal
attribute: source
state: nl.rogro82.pipup
- condition: template
value_template: '{{ sound_mode != state_attr("media_player.yamaha_rx_v679", "sound_mode")
}}'
Expand All @@ -2283,9 +2291,9 @@
sound_mode: '{{ sound_mode }}'
variables:
sound_mode: "{%- if trigger.to_state.attributes.source == 'Spotify' -%}\n 7ch_stereo\n{%-
elif trigger.to_state.attributes.source in ['SmartTube', 'Youtube', 'YouTube
Kids', 'DisneyNow', 'PBS Kids', 'Hulu'] -%}\n surr_decoder\n{%- else -%}\n
\ straight\n{%- endif -%}"
elif trigger.to_state.attributes.source in ['SmartTube', 'YouTube', 'YouTube
Kids', 'DisneyNow', 'PBS Kids'] -%}\n surr_decoder\n{%- else -%}\n straight\n{%-
endif -%}"
mode: single
- id: '1665696446379'
alias: ⚙️ Event Sniffer [Actionable Event]
Expand Down
24 changes: 12 additions & 12 deletions custom_templates/util.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@
{%- macro media_icon(entity) -%}
{%- set app = state_attr(entity, "source") -%}
{%- set app_list = {
"com.amazon.amazonvideo.livingroom": "fab:amazon",
"com.crunchyroll.crunchyroid": "fapro:crunchyroll",
"com.disney.datg.videoplatforms.android.watchdc": "fapro:disney_now",
"com.teamsmart.videomanager.tv": "mdi:youtube",
"com.google.android.youtube.tv": "mdi:youtube",
"com.google.android.youtube.tvkids": "fapro:youtube_kids",
"com.hulu.livingroomplus": "mdi:hulu",
"com.netflix.ninja": "mdi:netflix",
"com.plexapp.android": "mdi:plex",
"com.spotify.tv.android": "mdi:spotify",
"org.pbskids.video": "fapro:pbs_kids",
"tv.twitch.android.viewer": "mdi:twitch",
"Amazon": "fab:amazon",
"Crunchyroll": "fapro:crunchyroll",
"DisneyNow": "fapro:disney_now",
"Hulu": "mdi:hulu",
"Netflix": "mdi:netflix",
"PBS Kids": "fapro:pbs_kids",
"Plex": "mdi:plex",
"SmartTube": "mdi:youtube",
"Spotify": "mdi:spotify",
"YouTube": "mdi:youtube",
"YouTube Kids": "fapro:youtube_kids",
"Twitch": "mdi:twitch",
} -%}
{%- set media_type = state_attr(entity, "media_content_type") -%}
{%- set media_type_list = {
Expand Down
23 changes: 23 additions & 0 deletions custom_templates/variables.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
{# VARIABLES MACROS #}

{#
Android TV Source
The result of this needs to be converted using from_json.
#}
{% macro androidtv() %}
{{ {
"com.spocky.projengmenu": "Home",
"com.google.android.backdrop": "Screensaver",
"com.amazon.amazonvideo.livingroom": "Amazon",
"com.crunchyroll.crunchyroid": "Crunchyroll",
"com.disney.datg.videoplatforms.android.watchdc": "DisneyNow",
"com.hulu.livingroomplus": "Hulu",
"com.netflix.ninja": "Netflix",
"org.pbskids.video": "PBS Kids",
"com.plexapp.android": "Plex",
"com.teamsmart.videomanager.tv": "SmartTube",
"com.spotify.tv.android": "Spotify",
"com.google.android.youtube.tvkids": "YouTube Kids",
"com.google.android.youtube.tv": "YouTube",
"tv.twitch.android.viewer": "Twitch"
} | to_json }}
{% endmacro %}

{#
Denon Sound Modes
The result of this needs to be converted using from_json.
Expand Down
31 changes: 20 additions & 11 deletions entities/media_player/family_room_universal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ children:
- media_player.playstation_4
- media_player.cast_family_room
- media_player.family_room_shield
active_child_template: >-
{%- if not states('media_player.playstation_4') in ['standby', 'off', 'unknown', 'unavailable'] -%}
media_player.playstation_4
{%- elif not states('media_player.plex_family_room') in ['standby', 'off', 'unknown', 'unavailable'] -%}
media_player.plex_family_room
{%- else -%}
media_player.family_room_shield
{%- endif -%}
state_template: >-
{% if not states('media_player.playstation_4') in ['standby', 'off', 'unknown', 'unavailable'] %}
{{ states("media_player.playstation_4") }}
{% elif not states('media_player.plex_family_room') in ['standby', 'off', 'unknown', 'unavailable'] %}
{{ states("media_player.plex_family_room") }}
{% else %}
{%- if not states('media_player.playstation_4') in ['standby', 'off', 'unknown', 'unavailable'] -%}
{{ states('media_player.playstation_4') }}
{%- elif not states('media_player.plex_family_room') in ['standby', 'off', 'unknown', 'unavailable'] -%}
{{ states('media_player.plex_family_room') }}
{%- else -%}
{{ states('media_player.family_room_shield') }}
{% endif %}
{%- endif -%}
browse_media_entity: media_player.family_room_shield
attributes:
source_list: media_player.family_room_shield|source_list
source: media_player.family_room_shield|app_id
sound_mode_list: select.denon_sound_mode|options
source: select.family_room_source
source_list: select.family_room_source|options
sound_mode: select.denon_sound_mode
sound_mode_list: select.denon_sound_mode|options
volume_level: media_player.denon_avr_s760h|volume_level
is_volume_muted: media_player.denon_avr_s760h|is_volume_muted
commands:
Expand Down Expand Up @@ -81,9 +90,9 @@ commands:
data:
volume_level: '{{ volume_level }}'
select_source:
service: media_player.select_source
service: select.select_option
target:
entity_id: media_player.family_room_shield
entity_id: select.family_room_source
data:
source: '{{ source }}'
select_sound_mode:
Expand Down
19 changes: 10 additions & 9 deletions entities/media_player/living_room_universal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ children:
- media_player.cast_living_room
- media_player.living_room_shield
state_template: >-
{% if not states('media_player.plex_living_room') in ['standby', 'off', 'unknown', 'unavailable'] %}
{{ states("media_player.plex_living_room") }}
{% else %}
{%- if not states('media_player.plex_living_room') in ['standby', 'off', 'unknown', 'unavailable'] -%}
{{ states('media_player.plex_living_room') }}
{%- else -%}
{{ states('media_player.living_room_shield') }}
{% endif %}
{%- endif -%}
browse_media_entity: media_player.living_room_shield
attributes:
source_list: media_player.living_room_shield|source_list
source: media_player.living_room_shield|app_id
sound_mode_list: select.yamaha_sound_mode|options
source: select.living_room_source
source_list: select.living_room_source|options
sound_mode: select.yamaha_sound_mode
sound_mode_list: select.yamaha_sound_mode|options
volume_level: media_player.yamaha_rx_v679|volume_level
is_volume_muted: media_player.yamaha_rx_v679|is_volume_muted
commands:
Expand Down Expand Up @@ -76,9 +77,9 @@ commands:
data:
volume_level: '{{ volume_level }}'
select_source:
service: media_player.select_source
service: select.select_option
target:
entity_id: media_player.living_room_shield
entity_id: select.living_room_source
data:
source: '{{ source }}'
select_sound_mode:
Expand Down
13 changes: 7 additions & 6 deletions entities/media_player/master_bedroom_universal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ children:
- media_player.master_bedroom_shield
state_template: >-
{% if not states('media_player.plex_master_bedroom') in ['standby', 'off', 'unknown', 'unavailable'] %}
{{ states("media_player.plex_master_bedroom") }}
{{ states('media_player.plex_master_bedroom') }}
{% else %}
{{ states('media_player.master_bedroom_shield') }}
{{ states("media_player.master_bedroom_shield") }}
{% endif %}
browse_media_entity: media_player.master_bedroom_shield
attributes:
source_list: media_player.master_bedroom_shield|source_list
source: media_player.master_bedroom_shield|app_id
source: select.master_bedroom_source
source_list: select.master_bedroom_source|options
commands:
turn_on:
service: remote.turn_on
Expand Down Expand Up @@ -75,8 +76,8 @@ commands:
device: "Vizio Amp"
command: Mute
select_source:
service: media_player.select_source
service: select.select_option
target:
entity_id: media_player.master_bedroom_shield
entity_id: select.master_bedroom_source
data:
source: '{{ source }}'
28 changes: 28 additions & 0 deletions entities/template/select/family_room_source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# The template integration allows creating entities which derive their values
# from other data. This is done by specifying templates for properties of an
# entity, like the name or the state.
#
# https://www.home-assistant.io/integrations/template/
#
select:
- name: "Family Room Source"
availability: '{{ has_value("media_player.family_room_shield") and has_value("media_player.family_room_androidtv") }}'
state: |-
{%- from "variables.jinja" import androidtv %}
{%- set source = state_attr('media_player.family_room_androidtv', 'app_id') | default('off', true) -%}
{%- set sources = androidtv() | from_json -%}
{{ iif(source in sources, sources[source], source) }}
options: |-
{%- from "variables.jinja" import androidtv %}
{{ (androidtv() | from_json).values() | list }}
select_option:
- service: media_player.select_source
target:
entity_id: media_player.family_room_shield
data:
source: |-
{%- from "util.jinja" import dict_flip %}
{%- from "variables.jinja" import androidtv %}
{%- set sources = dict_flip(androidtv() | from_json) | from_json -%}
{{ iif(option in sources, sources[option], option) }}
28 changes: 28 additions & 0 deletions entities/template/select/living_room_source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# The template integration allows creating entities which derive their values
# from other data. This is done by specifying templates for properties of an
# entity, like the name or the state.
#
# https://www.home-assistant.io/integrations/template/
#
select:
- name: "Living Room Source"
availability: '{{ has_value("media_player.living_room_shield") and has_value("media_player.living_room_androidtv") }}'
state: |-
{%- from "variables.jinja" import androidtv %}
{%- set source = state_attr('media_player.living_room_androidtv', 'app_id') | default('off', true) -%}
{%- set sources = androidtv() | from_json -%}
{{ iif(source in sources, sources[source], source) }}
options: |-
{%- from "variables.jinja" import androidtv %}
{{ (androidtv() | from_json).values() | list }}
select_option:
- service: media_player.select_source
target:
entity_id: media_player.living_room_shield
data:
source: |-
{%- from "util.jinja" import dict_flip %}
{%- from "variables.jinja" import androidtv %}
{%- set sources = dict_flip(androidtv() | from_json) | from_json -%}
{{ iif(option in sources, sources[option], option) }}
28 changes: 28 additions & 0 deletions entities/template/select/master_bedroom_source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# The template integration allows creating entities which derive their values
# from other data. This is done by specifying templates for properties of an
# entity, like the name or the state.
#
# https://www.home-assistant.io/integrations/template/
#
select:
- name: "Master Bedroom Source"
availability: '{{ has_value("media_player.master_bedroom_shield") and has_value("media_player.master_bedroom_androidtv") }}'
state: |-
{%- from "variables.jinja" import androidtv %}
{%- set source = state_attr('media_player.master_bedroom_androidtv', 'app_id') | default('off', true) -%}
{%- set sources = androidtv() | from_json -%}
{{ iif(source in sources, sources[source], source) }}
options: |-
{%- from "variables.jinja" import androidtv %}
{{ (androidtv() | from_json).values() | list }}
select_option:
- service: media_player.select_source
target:
entity_id: media_player.master_bedroom_shield
data:
source: |-
{%- from "util.jinja" import dict_flip %}
{%- from "variables.jinja" import androidtv %}
{%- set sources = dict_flip(androidtv() | from_json) | from_json -%}
{{ iif(option in sources, sources[option], option) }}
24 changes: 12 additions & 12 deletions entities/template/sensor/media/media_player_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
# https://www.home-assistant.io/integrations/template/
#
sensor:
- name: Family Room Shield Source
availability: "{{ has_value('media_player.family_room_shield') }}"
state: "{{ state_attr('media_player.family_room_shield', 'source') | default('off', true) }}"
icon: mdi:import
# - name: Family Room Shield Source
# availability: "{{ has_value('media_player.family_room_shield') }}"
# state: "{{ state_attr('media_player.family_room_shield', 'source') | default('off', true) }}"
# icon: mdi:import

- name: Living Room Shield Source
availability: "{{ has_value('media_player.living_room_shield') }}"
state: "{{ state_attr('media_player.living_room_shield', 'source') | default('off', true) }}"
icon: mdi:import
# - name: Living Room Shield Source
# availability: "{{ has_value('media_player.living_room_shield') }}"
# state: "{{ state_attr('media_player.living_room_shield', 'source') | default('off', true) }}"
# icon: mdi:import

- name: Master Bedroom Shield Source
availability: "{{ has_value('media_player.master_bedroom_shield') }}"
state: "{{ state_attr('media_player.master_bedroom_shield', 'source') | default('off', true) }}"
icon: mdi:import
# - name: Master Bedroom Shield Source
# availability: "{{ has_value('media_player.master_bedroom_shield') }}"
# state: "{{ state_attr('media_player.master_bedroom_shield', 'source') | default('off', true) }}"
# icon: mdi:import

- name: Family Room Denon Source
availability: "{{ has_value('media_player.denon_avr_s760h') }}"
Expand Down
Loading

0 comments on commit 8c79473

Please sign in to comment.