You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// If value is an integer, it must have a trailing "i"
@@ -297,9 +303,9 @@ def handleEvent(evt) {
297
303
def unit = escapeStringForInfluxDB(evt.unit)
298
304
def value = escapeStringForInfluxDB(evt.value)
299
305
def valueBinary =''
300
-
306
+
301
307
def data ="${measurement},deviceId=${deviceId},deviceName=${deviceName},groupId=${groupId},groupName=${groupName},hubId=${hubId},hubName=${hubName},locationId=${locationId},locationName=${locationName}"
302
-
308
+
303
309
// Unit tag and fields depend on the event type:
304
310
// Most string-valued attributes can be translated to a binary value too.
305
311
if ('acceleration'== evt.name) { // acceleration: Calculate a binary value (active = 1, inactive = 0)
@@ -419,7 +425,7 @@ def handleEvent(evt) {
419
425
elseif ('thermostatOperatingState'== evt.name) { // thermostatOperatingState: Calculate a binary value (heating = 1, <any other value> = 0)
420
426
unit ='thermostatOperatingState'
421
427
value ='"'+ value +'"'
422
-
valueBinary = ('idle'== evt.value) ?'0i':'1i'
428
+
valueBinary = ('idle'== evt.value) ?'0i':'1i'
423
429
data +=",unit=${unit} value=${value},valueBinary=${valueBinary}"
424
430
}
425
431
elseif ('thermostatSetpointMode'== evt.name) { // thermostatSetpointMode: Calculate a binary value (followSchedule = 0, <any other value> = 1)
@@ -474,18 +480,15 @@ def handleEvent(evt) {
474
480
}
475
481
// Catch any other event with a string value that hasn't been handled:
476
482
elseif (evt.value ==~/.*[^0-9\.,-].*/) { // match if any characters are not digits, period, comma, or hyphen.
477
-
logger("handleEvent(): Found a string value that's not explicitly handled: Device Name: ${deviceName}, Event Name: ${evt.name}, Value:${evt.value}","warn")
483
+
logger("parseEvent(): Found a string value that's not explicitly handled: Device Name: ${deviceName}, Event Name: ${evt.name}, Value:${evt.value}","warn")
478
484
value ='"'+ value +'"'
479
485
data +=",unit=${unit} value=${value}"
480
486
}
481
487
// Catch any other general numerical event (carbonDioxide, power, energy, humidity, level, temperature, ultravioletIndex, voltage, etc).
482
488
else {
483
489
data +=",unit=${unit} value=${value}"
484
490
}
485
-
486
-
// Post data to InfluxDB:
487
-
postToInfluxDB(data)
488
-
491
+
return data
489
492
}
490
493
491
494
@@ -497,41 +500,43 @@ def handleEvent(evt) {
497
500
* softPoll()
498
501
*
499
502
* Executed by schedule.
500
-
*
503
+
*
501
504
* Forces data to be posted to InfluxDB (even if an event has not been triggered).
502
505
* Doesn't poll devices, just builds a fake event to pass to handleEvent().
503
506
*
504
507
* Also calls LogSystemProperties().
505
508
**/
506
509
defsoftPoll() {
507
510
logger("softPoll()","trace")
508
-
511
+
509
512
logSystemProperties()
510
-
513
+
511
514
// Iterate over each attribute for each device, in each device collection in deviceAttributes:
512
515
def devs // temp variable to hold device collection.
516
+
def eventsData = []
513
517
state.deviceAttributes.each { da->
514
518
devs = settings."${da.devices}"
515
519
if (devs && (da.attributes)) {
516
520
devs.each { d->
517
521
da.attributes.each { attr->
518
522
if (d.hasAttribute(attr) && d.latestState(attr)?.value !=null) {
519
523
logger("softPoll(): Softpolling device ${d} for attribute: ${attr}","info")
520
-
//Send fake event to handleEvent():
521
-
handleEvent([
522
-
name: attr,
524
+
//Event list to sent to InfluxDB
525
+
eventsData.add(parseEvent([
526
+
name: attr,
523
527
value: d.latestState(attr)?.value,
524
528
unit: d.latestState(attr)?.unit,
525
529
device: d,
526
530
deviceId: d.id,
527
531
displayName: d.displayName
528
-
])
532
+
]))
529
533
}
530
534
}
531
535
}
532
536
}
533
537
}
534
-
538
+
// InfluxDB needs to be a newline delimited string
0 commit comments