Files
home-assistant/packages/media/media.yaml

267 lines
10 KiB
YAML

# Media Player Package
# -----------------------------------------------------------------------------
# Media Player State Helpers
input_select:
ht_player_state:
name: Home Theater Player State
options:
- Idle
- Playing
- Paused
- Stopped
- System
- Offline
- Unknown
initial: Idle
# -----------------------------------------------------------------------------
# Media Player Configuration Switches
input_boolean:
ht_adjust_volume_hvac:
name: Home Theater Adjust Volume for HVAC
ht_volume_adjusted:
name: Home Theater Volume is Adjusted
# -----------------------------------------------------------------------------
# Media Player Scripts
script:
# Update the Player State when an input device changes state. The state of
# the overall player is taken from the state of the currently active input
# device to the receiver.
ht_player_state_update:
alias: Home Theater Player State Update
mode: restart
sequence:
- choose:
# Receiver Off
- conditions: "{{ is_state('media_player.living_room_receiver', 'off') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Idle
# Shield TV Input
#
# Very annoying since apps don't necessarily tell Android if they are playing
# (looking at you, Jellyfin) and we need two integrations to even get the full
# story for the Android TV base status.
#
# ATV (app ID) | Cast | JF | State
# ----------------------------|---------|---------|--------------------
# off (XX) | XX | XX | Idle (system off)
# on (com.spocky.projengmenu) | XX | XX | Idle (Projectivity Launcher)
# on (org.jellyfin.androidtv) | XX | idle | Stopped (Jellyfin Home)
# on (org.jellyfin.androidtv) | XX | playing | Playing (Jellyfin)
# on (org.jellyfin.androidtv) | XX | paused | Paused (Jellyfin)
# on (others) | idle | XX | Stopped (App Home)
# on (others) | playing | XX | Playing (App)
# on (others) | paused | XX | Paused (App)
#
- condition: "{{ state_attr('media_player.living_room_receiver', 'source') == 'SHIELD' }}"
sequence:
- choose:
- conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ is_state('media_player.shield_tv_living_room_atv', 'off') }}"
- condition: template
value_template: "{{ state_attr('media_player.shield_tv_living_room_atv', 'app_id') == 'com.spocky.projengmenu' }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Idle
- conditions: "{{ state_attr('media_player.shield_tv_living_room_atv', 'app_id') == 'org.jellyfin.androidtv' }}"
sequence:
- choose:
- conditions: "{{ is_state('media_player.shield_tv_living_room_jellyfin', 'playing') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Playing
- conditions: "{{ is_state('media_player.shield_tv_living_room_jellyfin', 'paused') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Paused
- conditions: "{{ is_state('media_player.shield_tv_living_room_jellyfin', 'idle') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Stopped
- conditions: "{{ is_state('media_player.shield_tv_living_room_cast', 'playing') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Playing
- conditions: "{{ is_state('media_player.shield_tv_living_room_cast', 'paused') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Paused
- conditions: "{{ is_state('media_player.shield_tv_living_room_cast', 'idle') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Stopped
# Roku Input
- conditions: "{{ state_attr('media_player.living_room_receiver', 'source') == 'Roku Ultra' }}"
sequence:
- choose:
- conditions: "{{ is_state('media_player.living_room_roku', 'playing') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Playing
- conditions: "{{ is_state('media_player.living_room_roku', 'paused') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Paused
- conditions: "{{ is_state('media_player.living_room_roku', 'on') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Stopped
- conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ is_state('media_player.living_room_roku', 'idle') }}"
- condition: template
value_template: "{{ is_state('media_player.living_room_roku', 'off') }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Idle
# Fallback to Unknown State
default:
- service: input_select.select_option
target:
entity_id: input_select.ht_player_state
data:
option: Unknown
# -----------------------------------------------------------------------------
# Media Player Automations
automation:
- alias: Home Theater Idle Timeout
trigger:
- platform: state
entity_id: input_select.ht_player_state
to: Stopped
for:
minutes: 10
action:
- service: input_select.select_option
target:
entity_id: "{{ trigger.entity_id }}"
data:
option: Idle
- alias: Home Theater Receiver State Update
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id: media_player.living_room_receiver
- platform: state
entity_id: media_player.living_room_roku
- platform: state
entity_id: media_player.shield_tv_living_room_atv
- platform: state
entity_id: media_player.shield_tv_living_room_cast
- platform: state
entity_id: media_player.shield_tv_living_room_jellyfin
action:
- service: script.ht_player_state_update
- alias: Turn Up Volume when HVAC Fan Starts
trigger:
- platform: state
entity_id: binary_sensor.hvac_fan_running
to: "on"
condition:
- "{{ is_state('input_boolean.ht_adjust_volume_hvac', 'on') }}"
- "{{ is_state('input_boolean.ht_volume_adjusted', 'off') }}"
- "{{ is_state('media_player.living_room_receiver', 'on') }}"
- "{{ is_state_attr('media_player.living_room_receiver', 'is_volume_muted', false) }}"
action:
- repeat:
count: 6
sequence:
- delay:
milliseconds: 250
- service: media_player.volume_up
target:
entity_id: media_player.living_room_receiver
- service: input_boolean.turn_on
target:
entity_id: input_boolean.ht_volume_adjusted
- alias: Turn Down Volume when HVAC Fan Stops
trigger:
- platform: state
entity_id: binary_sensor.hvac_fan_running
from: "on"
# The fan_state attribute turns off before the fan actually stops
for:
seconds: 45
condition:
- "{{ is_state('input_boolean.ht_adjust_volume_hvac', 'on') }}"
- "{{ is_state('input_boolean.ht_volume_adjusted', 'on') }}"
- "{{ is_state('media_player.living_room_receiver', 'on') }}"
- "{{ is_state_attr('media_player.living_room_receiver', 'is_volume_muted', false) }}"
action:
- repeat:
count: 6
sequence:
- delay:
milliseconds: 250
- service: media_player.volume_down
target:
entity_id: media_player.living_room_receiver
- service: input_boolean.turn_off
target:
entity_id: input_boolean.ht_volume_adjusted