-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathroku_tv.groovy
More file actions
183 lines (147 loc) · 4.55 KB
/
roku_tv.groovy
File metadata and controls
183 lines (147 loc) · 4.55 KB
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
preferences {
input("deviceIp", "text", title: "Device IP")
input("deviceMac", "text", title: "Device MAC Address")
}
metadata {
definition (name: "Roku TV", namespace: "ericboehs", author: "Eric Boehs") {
capability "Switch"
capability "Polling"
capability "Refresh"
command "volume_up"
command "volume_down"
command "volume_mute"
command "nickjr"
command "disneyjr"
command "hdmi1"
command "hdmi2"
command "hdmi3"
command "hdmi4"
}
simulator {
}
tiles {
standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: 'Off', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "on"
state "on", label: 'On', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState: "off"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("volume_up", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"Vol +", action:"volume_up", icon:"st.custom.sonos.unmuted"
}
standardTile("volume_down", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"Vol -", action:"volume_down", icon:"st.custom.sonos.unmuted"
}
standardTile("volume_mute", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"Mute", action:"volume_mute", icon:"st.custom.sonos.muted"
}
standardTile("nickjr", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"Nick Jr.", action:"nickjr", icon:"st.Electronics.electronics12"
}
standardTile("disneyjr", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"Disney Jr.", action:"disneyjr", icon:"st.Electronics.electronics12"
}
standardTile("hdmi1", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"HDMI 1", action:"hdmi1", icon:"st.Electronics.electronics12"
}
standardTile("hdmi2", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"HDMI 2", action:"hdmi2", icon:"st.Electronics.electronics12"
}
standardTile("hdmi3", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"HDMI 3", action:"hdmi3", icon:"st.Electronics.electronics12"
}
standardTile("hdmi4", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"HDMI 4", action:"hdmi4", icon:"st.Electronics.electronics12"
}
main "button"
details(["button", "refresh", "volume_mute", "volume_down", "volume_up", "hdmi1", "hdmi2", "hdmi3", "hdmi4", "nickjr", "disneyjr"])
}
}
def installed() {
updated()
}
def updated() {
log.debug "updated"
poll()
runEvery1Minute(poll)
}
def parse(String description) {
def msg = parseLanMessage(description)
if (msg.body && msg.body.contains("PowerOn")) {
sendEvent(name: "switch", value: "on")
}
}
def on() {
sendEvent(name: "switch", value: "on")
sendHubCommand(new physicalgraph.device.HubAction (
"wake on lan ${deviceMac}",
physicalgraph.device.Protocol.LAN,
null,
[:]
))
keypress('Power')
}
def off() {
sendEvent(name: "switch", value: "off")
keypress('PowerOff')
}
def volume_up() {
keypress('VolumeUp')
}
def volume_down() {
keypress('VolumeDown')
}
def volume_mute() {
keypress('VolumeMute')
}
def nickjr() {
launchApp('66595')
}
def disneyjr() {
launchApp('34278')
}
def hdmi1() {
keypress('InputHDMI1')
}
def hdmi2() {
keypress('InputHDMI2')
}
def hdmi3() {
keypress('InputHDMI3')
}
def hdmi4() {
keypress('InputHDMI4')
}
def poll() {
log.debug "Executing 'poll'"
refresh()
}
def refresh() {
log.debug "Executing 'refresh'"
queryDeviceState()
}
def queryDeviceState() {
sendEvent(name: "switch", value: "off")
sendHubCommand(new physicalgraph.device.HubAction(
method: "GET",
path: "/query/device-info",
headers: [ HOST: "${deviceIp}:8060" ]
))
}
def keypress(key) {
log.debug "Executing '${key}'"
def result = new physicalgraph.device.HubAction(
method: "POST",
path: "/keypress/${key}",
headers: [ HOST: "${deviceIp}:8060" ],
)
}
def launchApp(appId) {
log.debug "Executing 'launchApp ${appId}'"
def result = new physicalgraph.device.HubAction(
method: "POST",
path: "/launch/${appId}",
headers: [ HOST: "${deviceIp}:8060" ],
)
}