-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.tv_tune_channel.yaml
185 lines (183 loc) · 6.99 KB
/
script.tv_tune_channel.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
alias: "TV: Tune Channel"
sequence:
- alias: Set variables
variables:
channel_code: >
{% set code = state_attr("sensor.youtubetv_channel_lookup", "details") |
selectattr("name", "equalto", channel) | map(attribute='code') | list
%}
{% if (code | count()) == 0 %}
NOTFOUND
{% else %}
{{ code | first }}
{% endif %}
current_code: >
{% set cur_code = state_attr("sensor.youtubetv_channel_lookup",
"details") | selectattr("name", "equalto", states('sensor.' ~ device ~
'_channel')|upper) | map(attribute='code') | list %}
{% if (cur_code | count()) == 0 %}
NOTFOUND
{% else %}
{{ cur_code | first }}
{% endif %}
- condition: template
value_template: "{{ (device | upper) != 'NONE' }}"
- choose:
- conditions:
- condition: template
value_template: "{{ channel_code != \"NOTFOUND\" }}"
alias: If channel is valid
sequence:
- alias: Tune if Channel is different than the Current Channel
if:
- condition: template
value_template: "{{ current_code != channel_code }}"
alias: If channel is different than the current channel
then:
- choose:
- conditions:
- condition: template
value_template: "{{ device == \"den\" }}"
alias: Google TV Devices
sequence:
- alias: If Off, turn Device on and Wait
if:
- condition: template
value_template: >-
{{ is_state("media_player." + device + "_adb",
"off") }}
alias: If Device is Off
then:
- service: media_player.turn_on
metadata: {}
data: {}
target:
entity_id: media_player.{{ device }}_adb
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- service: androidtv.adb_command
data:
command: >-
am start -a android.intent.action.VIEW -d
https://tv.youtube.com/watch?v={{ channel_code }} -n
com.google.android.youtube.tvunplugged/com.google.android.apps.youtube.tvunplugged.activity.MainActivity
target:
entity_id: media_player.{{ device }}_adb
- conditions:
- condition: template
value_template: "{{ device == \"becca_tv\" }}"
alias: Fire TV Devices
sequence:
- alias: If Off, turn Device on and Wait
if:
- condition: template
value_template: >-
{{ is_state("media_player." + device + "_adb",
"off") }}
alias: If Device is Off
then:
- service: media_player.turn_on
metadata: {}
data: {}
target:
entity_id: media_player.{{ device }}_adb
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- service: androidtv.adb_command
data:
entity_id: media_player.{{ device }}_adb
command: >-
am start -a android.intent.action.VIEW -d
https://tv.youtube.com/watch?v={{ channel_code }} -n
com.amazon.firetv.youtube.tv/dev.cobalt.app.MainActivity
default:
- alias: If Off, turn Device on and Wait
if:
- alias: If Device is Off
condition: template
value_template: "{{ is_state(\"remote.\" + device, \"off\") }}"
then:
- service: remote.turn_on
metadata: {}
data: {}
target:
entity_id: remote.{{ device }}
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- service: remote.turn_on
data:
activity: https://tv.youtube.com
target:
entity_id: remote.{{ device }}
- delay:
hours: 0
minutes: 0
seconds: 4
milliseconds: 0
- service: remote.turn_on
data:
activity: https://tv.youtube.com/watch/{{ channel_code }}
target:
entity_id: remote.{{ device }}
alias: Regular YouTube TV Channels
- conditions:
- condition: template
value_template: "{{ \"PRIME\" in (channel | upper) }}"
alias: Channel Requested is PRIME
sequence:
- service: remote.turn_on
data:
activity: https://app.primevideo.com
target:
entity_id: remote.{{ device }}
alias: Amazon Prime
- conditions:
- condition: template
value_template: "{{ \"ESPN+\" in (channel | upper) }}"
enabled: true
alias: Channel Requested is ESPN+
sequence:
- service: remote.turn_on
data:
activity: sportscenter://x-callback-url
target:
entity_id: remote.{{ device }}
enabled: true
alias: ESPN+
default:
- service: notify.{{ device }}
data:
message: "{{ channel }}"
title: Invalid Channel!
data:
fontsize: max
position: center
duration: 15
color: red
alias: TV Notification of invalid channel
mode: queued
max: 10
fields:
device:
selector:
select:
options:
- living_room_tv
- bedroom_android_tv
- den
required: true
name: Device
channel:
selector:
text: null
name: Channel
required: true