-
Notifications
You must be signed in to change notification settings - Fork 0
/
Battery Tile
50 lines (39 loc) · 972 Bytes
/
Battery Tile
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
/*
Virtual Device with `battery` value to pass details to Actiontiles object.
*/
metadata {
definition(name: "Battery Tile", namespace: "s.tavener", author: "Stavener" ) {
capability "Battery"
capability "Sensor"
capability "Actuator"
command "setbattery"
command "getbattery"
attribute "battery", "number"
}
tiles {
valueTile("battery", "device.battery", width: 3, height: 1) {
state "default", label:'${currentValue} number}'
}
}
}
def initialize() {
state.value = 0.0
state.unit = "%"
log.debug("init")
}
def installed() {
log.debug "Installed"
initialize()
}
def updated() {
log.debug "Updated"
initialize()
}
def setbattery(new_value) {
log.debug "setbattery called battery=$new_value"
sendEvent(name:"battery", value: new_value, unit:"%")
}
private getbattery() {
value = device.currentState("battery")
return value
}