-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOwntracks Child MQTT.groovy
99 lines (95 loc) · 3 KB
/
Owntracks Child MQTT.groovy
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
metadata {
definition (name: "Owntracks Child MQTT Traking", namespace: "jorge.martinez", author: "Jorge Martinez") {
capability "Initialize"
capability "Sensor"
capability "Battery"
capability "Beacon"
capability "EstimatedTimeOfArrival"
capability "PresenceSensor"
attribute "topic", "String"
attribute "latitude", "float"
attribute "longitude", "float"
attribute "battery", "float"
attribute "speed", "integrer"
attribute "lastUpdated", "Date"
attribute "DevicelastUpdated", "String"
attribute "inregions", "String"
attribute "configuartion", "String"
attribute "stepsToday", "number"
attribute "stepsWeek", "number"
attribute "stepsYear", "number"
attribute "stepsLiveTime", "number"
attribute "epoch", "long"
attribute "communicado", "boolean"
//command "SetLogLat", ["float" , "float"]
//command "setBattery",["number","boolean"]
command "RequestLocation"
command "addWaysPoint", ["string", "number", "string", "string"]
command "GetConfiguration"
command "convertDateUnix", ["long"]
}
preferences {
section("settings"){
input "logEnable", "bool", title: "Enable Debug Logging?"
}
}
}
def SetIncommunicado (){
state.communicado = false
}
String convertDateUnix (edate){
def newdate = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (edate*1000));
log.debug newdate
return newdate
}
def updateepoch (Nepoch){
state.epoch = Nepoch
log.debug convertDateUnix (Nepoch)
state.DevicelastUpdated = convertDateUnix (Nepoch)
}
def updateconfiguartion(confg){
log.debug confg
state.configuartion = conf
}
def GetConfiguration(){
parent.publishMsg ("${state.topic}/cmd",'{"_type":"cmd","action":"dump"}')
}
def RequestLocation (){
parent.publishMsg ("${state.topic}/cmd",'{"_type": "cmd","action": "reportLocation"}')
}
def Updatetopic (top){
// sendEvent(name: "topic", value: top)
state.topic = top
}
def Updatelatitude (lat){
sendEvent(name: "latitude", value: lat)
state.latitude = lat
}
def Updatelongitude (lon){
sendEvent(name: "longitude", value: lat)
state.latitude = lat
}
def Updatebattery (bat){
sendEvent(name: "battery", value: bat)
}
def Updatespeed (spe){
sendEvent(name: "speed", value: spe)
}
def Updateinregions (region){
sendEvent(name: "inregions", value: region)
state.inregions = region
}
def lastUpdated(){
def nowDay = new Date().format("MMM dd", location.timeZone)
def nowTime = new Date().format("h:mm a", location.timeZone)
state.lastUpdated = nowDay + " at " + nowTime
sendEvent(name: "lastUpdated", value: nowDay + " at " + nowTime, displayed: false)
}
def Updatepresence (pre){sendEvent(name: "presence", value: pre)}
def UpdateData (lat, lon) {
if (!communicado) state.communicado = true
sendEvent(name: "latitude", value: lat)
state.latitude = lat
sendEvent(name: "longitude", value: lon)
state.longitude = lon
}