-
Notifications
You must be signed in to change notification settings - Fork 183
/
media_player.yaml
142 lines (136 loc) · 4.73 KB
/
media_player.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
#-
# _ _ _
# _ __ ___ ___ __| (_) __ _ _ __ | | __ _ _ _ ___ _ __
# | '_ ` _ \ / _ \/ _` | |/ _` | | '_ \| |/ _` | | | |/ _ \ '__|
# | | | | | | __/ (_| | | (_| | | |_) | | (_| | |_| | __/ |
# |_| |_| |_|\___|\__,_|_|\__,_|____| .__/|_|\__,_|\__, |\___|_|
# |_____|_| |___/
#
#- from github.com/basnijholt/home-assistant-config
- alias: "Media player: turn on Opt when TV is on and Spotify is not playing and not Usb"
description: |
The speaker is connected via an optical cable to the TV. Whenever the speakers
aren't playing Spotify (via WiFi) directly, switch the source of the speakers
to "Opt".
trigger:
- platform: state
entity_id: media_player.tv
- platform: state
entity_id: media_player.spotify
to: paused
condition:
- condition: state
entity_id: media_player.tv
state: "on"
- condition: state
entity_id: media_player.kef_ls50
state: "on"
- "{{ not is_state_attr('media_player.kef_ls50', 'source', 'Opt') }}"
- "{{ not is_state_attr('media_player.tv', 'source', 'GALLERY') }}"
- >
{{ not (is_state_attr('media_player.kef_ls50', 'source', 'Usb')
and is_state_attr('media_player.tv', 'source', 'HDMI 3')) }}
- >
{{ not (is_state_attr('media_player.spotify', 'source', 'LS50 Wireless')
and is_state('media_player.spotify', 'playing')) }}
action:
service: media_player.select_source
entity_id: media_player.kef_ls50
data:
source: Opt
- alias: "Media player: turn off speakers when turning off TV"
trigger:
platform: state
entity_id: media_player.tv
to: "off"
condition:
condition: state
entity_id: media_player.kef_ls50
state: "on"
action:
- service: homeassistant.update_entity
entity_id: media_player.kef_ls50
- condition: template
value_template: >
{{ is_state_attr("media_player.kef_ls50", "source", "Opt") }}
- service: media_player.turn_off
entity_id: media_player.kef_ls50
- alias: "Media player: if speakers off and TV on, turn on the speaker on TV state change"
trigger:
platform: state
entity_id: media_player.tv
condition: # Happens e.g., when speakers auto-shutdown and the TV is on but idle
- condition: state
entity_id: media_player.kef_ls50
state: "off"
- condition: state
entity_id: media_player.tv
state: "on"
# only consider meaningful changes to the state
- >
{{ trigger.from_state.state != trigger.to_state.state
or trigger.from_state.attributes["volume_level"] != trigger.to_state.attributes["volume_level"]
or trigger.from_state.attributes["source"] != trigger.to_state.attributes["source"] }}
action:
- service: media_player.turn_on
entity_id: media_player.kef_ls50
- service: media_player.select_source
entity_id: media_player.kef_ls50
data:
source: Opt
- alias: "Media player: update Spotify entity when TV is on every 5 seconds"
trigger:
platform: time_pattern
seconds: "/5"
condition:
- condition: state
entity_id: media_player.spotify
state: playing
- condition: state
entity_id: media_player.tv
state: "on"
action:
service: homeassistant.update_entity
entity_id: media_player.spotify
- alias: "Media player: sync KEF LS50 and TV volume"
mode: single
max_exceeded: silent
trigger:
- platform: state
entity_id: media_player.kef_ls50
attribute: volume_level
- platform: state
entity_id: media_player.tv
attribute: volume_level
condition:
- "{{ trigger.to_state.state != 'off' }}"
- "{{ state_attr('media_player.kef_ls50', 'source') in ('Opt', 'Usb') }}"
action:
repeat:
sequence:
- service: media_player.volume_set
data:
entity_id: >
media_player.{{ "tv" if (trigger.entity_id == "media_player.kef_ls50") else "kef_ls50" }}
volume_level: >
{{ state_attr(trigger.entity_id, "volume_level") }}
- delay:
milliseconds: 200
until:
- >
{{ state_attr("media_player.tv", "volume_level") == state_attr("media_player.kef_ls50", "volume_level")
or not (is_state("media_player.tv", "on") and is_state("media_player.kef_ls50", "on")) }}
- alias: "Media player: automatically turn off TV and speakers after two hours of inactivity"
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_living_room_klok
to: "off"
for: "02:00:00"
action:
- service: media_player.turn_off
data:
entity_id: media_player.kef_ls50
- service: media_player.turn_off
data:
entity_id: media_player.tv