iobroker.device-watcher 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/admin/i18n/de/translations.json +2 -1
- package/admin/i18n/en/translations.json +2 -2
- package/admin/i18n/es/translations.json +2 -1
- package/admin/i18n/fr/translations.json +2 -1
- package/admin/i18n/it/translations.json +2 -1
- package/admin/i18n/nl/translations.json +2 -1
- package/admin/i18n/pl/translations.json +2 -1
- package/admin/i18n/pt/translations.json +2 -1
- package/admin/i18n/ru/translations.json +2 -1
- package/admin/i18n/zh-cn/translations.json +2 -1
- package/admin/jsonConfig.json +1 -1
- package/io-package.json +24 -11
- package/main.js +740 -693
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -44,9 +44,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
44
44
|
// arrays of supported adapters
|
|
45
45
|
this.arrApart = {
|
|
46
46
|
//**** This Datapoints are only for the dev ****//
|
|
47
|
-
test: {'Selektor':'0_userdata.*.UNREACH', 'adapter':'homematic', 'rssiState':'.RSSI_DEVICE', 'battery':'.OPERATING_VOLTAGE', 'reach':'.UNREACH'},
|
|
48
|
-
test2: {'Selektor':'0_userdata.*.alive', 'adapter':'
|
|
49
|
-
test3: {'Selektor':'0_userdata.*.link_quality', 'adapter':'
|
|
47
|
+
test: {'Selektor':'0_userdata.*.UNREACH', 'adapter':'homematic', 'rssiState':'.RSSI_DEVICE', 'battery':'.OPERATING_VOLTAGE', 'reach':'.UNREACH', 'isLowBat':'.LOW_BAT'},
|
|
48
|
+
test2: {'Selektor':'0_userdata.*.alive', 'adapter':'test2', 'rssiState': '.Wifi_RSSI', 'battery':'none', 'reach':'.alive', 'isLowBat':'none', 'id':'.name'},
|
|
49
|
+
test3: {'Selektor':'0_userdata.*.link_quality', 'adapter':'test3', 'battery':'.battery', 'reach':'available', 'isLowBat':'none'},
|
|
50
50
|
//**** End of Dev Datapoints ****//
|
|
51
51
|
alexa2: {
|
|
52
52
|
'Selektor':'alexa2.*.online',
|
|
@@ -145,7 +145,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
145
145
|
},
|
|
146
146
|
switchbotBle: {
|
|
147
147
|
'Selektor':'switchbot-ble.*.rssi',
|
|
148
|
-
'adapter':'
|
|
148
|
+
'adapter':'switchbotBle',
|
|
149
149
|
'battery':'.battery',
|
|
150
150
|
'reach':'none',
|
|
151
151
|
'isLowBat':'none',
|
|
@@ -187,7 +187,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
187
187
|
|
|
188
188
|
try {
|
|
189
189
|
await this.main();
|
|
190
|
-
await this.
|
|
190
|
+
if (this.config.checkSendOfflineMsg) await this.sendOfflineNotifications();
|
|
191
|
+
if (this.config.checkSendBatteryMsg) await this.sendBatteryNotifications();
|
|
191
192
|
await this.writeDatapoints();
|
|
192
193
|
this.log.debug('all done, exiting');
|
|
193
194
|
this.terminate ? this.terminate('Everything done. Going to terminate till next schedule', 11) : process.exit(0);
|
|
@@ -216,6 +217,49 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
216
217
|
if (stateVal) return stateVal.val;
|
|
217
218
|
}
|
|
218
219
|
|
|
220
|
+
//Notification services
|
|
221
|
+
async sendPushover(text) {
|
|
222
|
+
await this.sendToAsync(this.config.instancePushover, 'send', {
|
|
223
|
+
message: text,
|
|
224
|
+
title: this.config.titlePushover,
|
|
225
|
+
device: this.config.devicePushover,
|
|
226
|
+
priority: this.config.prioPushover
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async sendTelegram(text) {
|
|
231
|
+
await this.sendToAsync(this.config.instanceTelegram, 'send', {
|
|
232
|
+
text: text,
|
|
233
|
+
user: this.config.deviceTelegram,
|
|
234
|
+
chatId: this.config.chatIdTelegram
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async sendWhatsapp(text) {
|
|
239
|
+
await this.sendToAsync(this.config.instanceWhatsapp, 'send', {
|
|
240
|
+
text: text,
|
|
241
|
+
phone: this.config.phoneWhatsapp
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async sendEmail(text) {
|
|
246
|
+
await this.sendToAsync(this.config.instanceEmail, 'send', {
|
|
247
|
+
sendTo: this.config.sendToEmail,
|
|
248
|
+
text: text,
|
|
249
|
+
subject: this.config.subjectEmail
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async sendJarvis(text) {
|
|
254
|
+
await this.setForeignStateAsync(`${this.config.instanceJarvis}.addNotification`, text);
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async sendLovelace(text) {
|
|
259
|
+
await this.setForeignStateAsync(`${this.config.instanceLovelace}.notifications.add`, text);
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
|
|
219
263
|
//create datapoints for each adapter
|
|
220
264
|
async createDPsForEachAdapter(adptName) {
|
|
221
265
|
await this.setObjectNotExistsAsync(`${adptName}.offlineCount`, {
|
|
@@ -328,205 +372,142 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
328
372
|
});
|
|
329
373
|
}
|
|
330
374
|
|
|
331
|
-
async
|
|
332
|
-
this.
|
|
375
|
+
async createData(i) {
|
|
376
|
+
const devices = await this.getForeignStatesAsync(this.arrDev[i].Selektor);
|
|
377
|
+
const deviceAdapterName = await this.capitalize(this.arrDev[i].adapter);
|
|
378
|
+
const myBlacklist = this.config.tableBlacklist;
|
|
333
379
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
ble: this.config.bleDevices,
|
|
339
|
-
sonoff: this.config.sonoffDevices,
|
|
340
|
-
shelly: this.config.shellyDevices,
|
|
341
|
-
homematic: this.config.homematicDevices,
|
|
342
|
-
deconz: this.config.deconzDevices,
|
|
343
|
-
zwave: this.config.zwaveDevices,
|
|
344
|
-
dect: this.config.dectDevices,
|
|
345
|
-
hue: this.config.hueDevices,
|
|
346
|
-
hueExt: this.config.hueExtDevices,
|
|
347
|
-
nukiExt: this.config.nukiExtDevices,
|
|
348
|
-
ping: this.config.pingDevices,
|
|
349
|
-
switchbotBle: this.config.switchbotBleDevices,
|
|
350
|
-
sonos: this.config.sonosDevices,
|
|
351
|
-
mihome: this.config.mihomeDevices,
|
|
352
|
-
mihomeGW: this.config.mihomeDevices,
|
|
353
|
-
test: false, // Only for Developer
|
|
354
|
-
test2: false, // Only for Developer
|
|
355
|
-
test3: false // Only for Developer
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
for(const [id] of Object.entries(this.arrApart)) {
|
|
359
|
-
const idAdapter = this.supAdapter[id];
|
|
360
|
-
if (idAdapter) {
|
|
361
|
-
this.arrDev.push(this.arrApart[id]);
|
|
362
|
-
this.adapterSelected.push(await this.capitalize(id));
|
|
363
|
-
/*try {
|
|
364
|
-
await this.createDPsForEachAdapter(id);
|
|
365
|
-
this.log.debug(`Created datapoints for ${await this.capitalize(id)}`);
|
|
366
|
-
} catch (e) {
|
|
367
|
-
this.log.warn(`Error at creating datapoints for each adapter: ${e}`);
|
|
368
|
-
}*/
|
|
369
|
-
}
|
|
380
|
+
/*---------- Loop for blacklist ----------*/
|
|
381
|
+
for(const i in myBlacklist){
|
|
382
|
+
this.blacklistArr.push(myBlacklist[i].device);
|
|
383
|
+
this.log.debug(`Found items on the blacklist: ${this.blacklistArr}`);
|
|
370
384
|
}
|
|
371
385
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
} else {
|
|
376
|
-
this.log.warn(`No adapter selected. Please check the instance configuration!`);
|
|
377
|
-
}
|
|
386
|
+
/*---------- Start of second main loop ----------*/
|
|
387
|
+
for(const [id] of Object.entries(devices)) {
|
|
388
|
+
if (!this.blacklistArr.includes(id)) {
|
|
378
389
|
|
|
379
|
-
|
|
390
|
+
const currDeviceString = id.slice(0, (id.lastIndexOf('.') + 1) - 1);
|
|
391
|
+
const shortCurrDeviceString = currDeviceString.slice(0, (currDeviceString.lastIndexOf('.') + 1) - 1);
|
|
380
392
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const devices = await this.getForeignStatesAsync(this.arrDev[i].Selektor);
|
|
386
|
-
const deviceAdapterName = await this.capitalize(this.arrDev[i].adapter);
|
|
387
|
-
const myBlacklist = this.config.tableBlacklist;
|
|
388
|
-
|
|
389
|
-
/*---------- Loop for blacklist ----------*/
|
|
390
|
-
for(const i in myBlacklist){
|
|
391
|
-
this.blacklistArr.push(myBlacklist[i].device);
|
|
392
|
-
this.log.debug(`Found items on the blacklist: ${this.blacklistArr}`);
|
|
393
|
-
}
|
|
393
|
+
//Get device name
|
|
394
|
+
const deviceObject = await this.getForeignObjectAsync(currDeviceString);
|
|
395
|
+
const shortDeviceObject = await this.getForeignObjectAsync(shortCurrDeviceString);
|
|
396
|
+
let deviceName;
|
|
394
397
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
+
if (deviceObject && typeof deviceObject === 'object') {
|
|
399
|
+
deviceName = deviceObject.common.name;
|
|
400
|
+
}
|
|
398
401
|
|
|
399
|
-
|
|
400
|
-
|
|
402
|
+
if (shortDeviceObject && typeof shortDeviceObject === 'object') {
|
|
403
|
+
if (this.arrDev[i].adapter === 'hue extended') {
|
|
404
|
+
deviceName = shortDeviceObject.common.name;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
401
407
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
408
|
+
//Get ID for Switchbot and ESPHome Devices
|
|
409
|
+
switch (this.arrDev[i].adapter) {
|
|
410
|
+
case 'switchbot ble':
|
|
411
|
+
case 'esphome':
|
|
412
|
+
deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
406
415
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
416
|
+
// 1. Get link quality
|
|
417
|
+
let deviceQualityState;
|
|
418
|
+
let linkQuality;
|
|
419
|
+
|
|
420
|
+
switch (this.arrDev[i].adapter) {
|
|
421
|
+
case 'homematic':
|
|
422
|
+
case 'sonoff':
|
|
423
|
+
deviceQualityState = await this.getForeignStateAsync(currDeviceString + this.arrDev[i].rssiState);
|
|
424
|
+
break;
|
|
425
|
+
default:
|
|
426
|
+
deviceQualityState = await this.getForeignStateAsync(id);
|
|
427
|
+
}
|
|
410
428
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
429
|
+
if ((deviceQualityState) && (typeof deviceQualityState.val === 'number')){
|
|
430
|
+
if (this.config.trueState) {
|
|
431
|
+
linkQuality = deviceQualityState.val;
|
|
432
|
+
} else {
|
|
433
|
+
if (deviceQualityState.val < 0) {
|
|
434
|
+
linkQuality = Math.min(Math.max(2 * (deviceQualityState.val + 100), 0), 100) + '%';
|
|
435
|
+
} else if ((deviceQualityState.val) >= 0) {
|
|
436
|
+
linkQuality = parseFloat((100/255 * deviceQualityState.val).toFixed(0)) + '%';
|
|
414
437
|
}
|
|
415
438
|
}
|
|
439
|
+
this.linkQualityDevices.push(
|
|
440
|
+
{
|
|
441
|
+
Device: deviceName,
|
|
442
|
+
Adapter: deviceAdapterName,
|
|
443
|
+
Link_quality: linkQuality
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
} else {
|
|
447
|
+
// no linkQuality available for powered devices
|
|
448
|
+
linkQuality = ' - ';
|
|
449
|
+
}
|
|
416
450
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
case 'switchbot ble':
|
|
420
|
-
case 'esphome':
|
|
421
|
-
deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
451
|
+
// 1b. Count how many devices with link Quality
|
|
452
|
+
this.linkQualityCount = this.linkQualityDevices.length;
|
|
424
453
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
454
|
+
// 2. When was the last contact to the device?
|
|
455
|
+
let lastContactString;
|
|
456
|
+
|
|
457
|
+
const deviceMainSelector = await this.getForeignStateAsync(id);
|
|
458
|
+
let deviceState = 'Online';
|
|
459
|
+
if (deviceMainSelector) {
|
|
460
|
+
try {
|
|
461
|
+
const time = new Date();
|
|
462
|
+
const lastContact = Math.round((time.getTime() - deviceMainSelector.ts) / 1000 / 60);
|
|
463
|
+
const lastStateChange = Math.round((time.getTime() - deviceMainSelector.lc) / 1000 / 60);
|
|
464
|
+
const deviceUnreachState = await this.getInitValue(currDeviceString + this.arrDev[i].reach);
|
|
428
465
|
|
|
429
|
-
switch (this.arrDev[i].adapter) {
|
|
430
|
-
case 'homematic':
|
|
431
|
-
case 'sonoff':
|
|
432
|
-
deviceQualityState = await this.getForeignStateAsync(currDeviceString + this.arrDev[i].rssiState);
|
|
433
|
-
break;
|
|
434
|
-
default:
|
|
435
|
-
deviceQualityState = await this.getForeignStateAsync(id);
|
|
436
|
-
}
|
|
437
466
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (deviceQualityState.val < 0) {
|
|
443
|
-
linkQuality = Math.min(Math.max(2 * (deviceQualityState.val + 100), 0), 100) + '%';
|
|
444
|
-
} else if ((deviceQualityState.val) >= 0) {
|
|
445
|
-
linkQuality = parseFloat((100/255 * deviceQualityState.val).toFixed(0)) + '%';
|
|
467
|
+
const getLastContact = async () => {
|
|
468
|
+
lastContactString = this.formatDate(new Date((deviceMainSelector.ts)), 'hh:mm') + ' Uhr';
|
|
469
|
+
if (Math.round(lastContact) > 100) {
|
|
470
|
+
lastContactString = Math.round(lastContact/60) + ' Stunden';
|
|
446
471
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
{
|
|
450
|
-
Device: deviceName,
|
|
451
|
-
Adapter: deviceAdapterName,
|
|
452
|
-
Link_quality: linkQuality
|
|
472
|
+
if (Math.round(lastContact/60) > 48) {
|
|
473
|
+
lastContactString = Math.round(lastContact/60/24) + ' Tagen';
|
|
453
474
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
// no linkQuality available for powered devices
|
|
457
|
-
linkQuality = ' - ';
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// 1b. Count how many devices with link Quality
|
|
461
|
-
this.linkQualityCount = this.linkQualityDevices.length;
|
|
475
|
+
return lastContactString;
|
|
476
|
+
};
|
|
462
477
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const deviceUnreachState = await this.getInitValue(currDeviceString + this.arrDev[i].reach);
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const getLastContact = async () => {
|
|
477
|
-
lastContactString = this.formatDate(new Date((deviceMainSelector.ts)), 'hh:mm') + ' Uhr';
|
|
478
|
-
if (Math.round(lastContact) > 100) {
|
|
479
|
-
lastContactString = Math.round(lastContact/60) + ' Stunden';
|
|
480
|
-
}
|
|
481
|
-
if (Math.round(lastContact/60) > 48) {
|
|
482
|
-
lastContactString = Math.round(lastContact/60/24) + ' Tagen';
|
|
483
|
-
}
|
|
484
|
-
return lastContactString;
|
|
485
|
-
};
|
|
478
|
+
const getLastStateChange = async () => {
|
|
479
|
+
lastContactString = this.formatDate(new Date((deviceMainSelector.lc)), 'hh:mm') + ' Uhr';
|
|
480
|
+
if (Math.round(lastStateChange) > 100) {
|
|
481
|
+
lastContactString = Math.round(lastStateChange/60) + ' Stunden';
|
|
482
|
+
}
|
|
483
|
+
if (Math.round(lastStateChange/60) > 48) {
|
|
484
|
+
lastContactString = Math.round(lastStateChange/60/24) + ' Tagen';
|
|
485
|
+
}
|
|
486
|
+
return lastContactString;
|
|
487
|
+
};
|
|
486
488
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
489
|
+
// 2b. wenn seit X Minuten kein Kontakt mehr besteht, nimm Gerät in Liste auf
|
|
490
|
+
//Rechne auf Tage um, wenn mehr als 48 Stunden seit letztem Kontakt vergangen sind
|
|
491
|
+
//lastContactString = Math.round(lastContact) + ' Minuten';
|
|
492
|
+
switch (this.arrDev[i].adapter) {
|
|
493
|
+
case 'ping':
|
|
494
|
+
//State changed
|
|
495
|
+
if (!deviceUnreachState) {
|
|
496
|
+
await getLastStateChange();
|
|
497
|
+
} else {
|
|
498
|
+
await getLastContact();
|
|
494
499
|
}
|
|
495
|
-
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
// 2b. wenn seit X Minuten kein Kontakt mehr besteht, nimm Gerät in Liste auf
|
|
499
|
-
//Rechne auf Tage um, wenn mehr als 48 Stunden seit letztem Kontakt vergangen sind
|
|
500
|
-
//lastContactString = Math.round(lastContact) + ' Minuten';
|
|
501
|
-
switch (this.arrDev[i].adapter) {
|
|
502
|
-
case 'ping':
|
|
503
|
-
//State changed
|
|
504
|
-
if (!deviceUnreachState) {
|
|
505
|
-
await getLastStateChange();
|
|
506
|
-
} else {
|
|
507
|
-
await getLastContact();
|
|
508
|
-
}
|
|
509
|
-
break;
|
|
500
|
+
break;
|
|
510
501
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
502
|
+
default:
|
|
503
|
+
await getLastContact();
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
515
506
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
deviceState = 'Offline'; //set online state to offline
|
|
521
|
-
this.offlineDevices.push(
|
|
522
|
-
{
|
|
523
|
-
Device: deviceName,
|
|
524
|
-
Adapter: deviceAdapterName,
|
|
525
|
-
Last_contact: lastContactString
|
|
526
|
-
}
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
} else if (lastContact > this.config.alexa2MaxMinutes) {
|
|
507
|
+
switch (this.arrDev[i].adapter) {
|
|
508
|
+
case 'alexa2':
|
|
509
|
+
if (this.config.alexa2MaxMinutes === -1) {
|
|
510
|
+
if (!deviceUnreachState) {
|
|
530
511
|
deviceState = 'Offline'; //set online state to offline
|
|
531
512
|
this.offlineDevices.push(
|
|
532
513
|
{
|
|
@@ -536,20 +517,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
536
517
|
}
|
|
537
518
|
);
|
|
538
519
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
Device: deviceName,
|
|
547
|
-
Adapter: deviceAdapterName,
|
|
548
|
-
Last_contact: lastContactString
|
|
549
|
-
}
|
|
550
|
-
);
|
|
520
|
+
} else if (lastContact > this.config.alexa2MaxMinutes) {
|
|
521
|
+
deviceState = 'Offline'; //set online state to offline
|
|
522
|
+
this.offlineDevices.push(
|
|
523
|
+
{
|
|
524
|
+
Device: deviceName,
|
|
525
|
+
Adapter: deviceAdapterName,
|
|
526
|
+
Last_contact: lastContactString
|
|
551
527
|
}
|
|
552
|
-
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
break;
|
|
531
|
+
case 'ble':
|
|
532
|
+
if (this.config.bleMaxMinutes === -1) {
|
|
533
|
+
if (!deviceUnreachState) {
|
|
553
534
|
deviceState = 'Offline'; //set online state to offline
|
|
554
535
|
this.offlineDevices.push(
|
|
555
536
|
{
|
|
@@ -559,20 +540,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
559
540
|
}
|
|
560
541
|
);
|
|
561
542
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
Device: deviceName,
|
|
570
|
-
Adapter: deviceAdapterName,
|
|
571
|
-
Last_contact: lastContactString
|
|
572
|
-
}
|
|
573
|
-
);
|
|
543
|
+
} else if (lastContact > this.config.bleMaxMinutes) {
|
|
544
|
+
deviceState = 'Offline'; //set online state to offline
|
|
545
|
+
this.offlineDevices.push(
|
|
546
|
+
{
|
|
547
|
+
Device: deviceName,
|
|
548
|
+
Adapter: deviceAdapterName,
|
|
549
|
+
Last_contact: lastContactString
|
|
574
550
|
}
|
|
575
|
-
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
break;
|
|
554
|
+
case 'deconz':
|
|
555
|
+
if (this.config.deconzMaxMinutes === -1) {
|
|
556
|
+
if (!deviceUnreachState) {
|
|
576
557
|
deviceState = 'Offline'; //set online state to offline
|
|
577
558
|
this.offlineDevices.push(
|
|
578
559
|
{
|
|
@@ -582,20 +563,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
582
563
|
}
|
|
583
564
|
);
|
|
584
565
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
Device: deviceName,
|
|
593
|
-
Adapter: deviceAdapterName,
|
|
594
|
-
Last_contact: lastContactString
|
|
595
|
-
}
|
|
596
|
-
);
|
|
566
|
+
} else if (lastContact > this.config.deconzMaxMinutes) {
|
|
567
|
+
deviceState = 'Offline'; //set online state to offline
|
|
568
|
+
this.offlineDevices.push(
|
|
569
|
+
{
|
|
570
|
+
Device: deviceName,
|
|
571
|
+
Adapter: deviceAdapterName,
|
|
572
|
+
Last_contact: lastContactString
|
|
597
573
|
}
|
|
598
|
-
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
break;
|
|
577
|
+
case 'esphome':
|
|
578
|
+
if (this.config.esphomeMaxMinutes === -1) {
|
|
579
|
+
if (!deviceUnreachState) {
|
|
599
580
|
deviceState = 'Offline'; //set online state to offline
|
|
600
581
|
this.offlineDevices.push(
|
|
601
582
|
{
|
|
@@ -605,20 +586,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
605
586
|
}
|
|
606
587
|
);
|
|
607
588
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
Device: deviceName,
|
|
616
|
-
Adapter: deviceAdapterName,
|
|
617
|
-
Last_contact: lastContactString
|
|
618
|
-
}
|
|
619
|
-
);
|
|
589
|
+
} else if (lastContact > this.config.esphomeMaxMinutes) {
|
|
590
|
+
deviceState = 'Offline'; //set online state to offline
|
|
591
|
+
this.offlineDevices.push(
|
|
592
|
+
{
|
|
593
|
+
Device: deviceName,
|
|
594
|
+
Adapter: deviceAdapterName,
|
|
595
|
+
Last_contact: lastContactString
|
|
620
596
|
}
|
|
621
|
-
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
break;
|
|
600
|
+
case 'fritzDect':
|
|
601
|
+
if (this.config.fritzdectMaxMinutes === -1) {
|
|
602
|
+
if (!deviceUnreachState) {
|
|
622
603
|
deviceState = 'Offline'; //set online state to offline
|
|
623
604
|
this.offlineDevices.push(
|
|
624
605
|
{
|
|
@@ -628,20 +609,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
628
609
|
}
|
|
629
610
|
);
|
|
630
611
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
Device: deviceName,
|
|
639
|
-
Adapter: deviceAdapterName,
|
|
640
|
-
Last_contact: lastContactString
|
|
641
|
-
}
|
|
642
|
-
);
|
|
612
|
+
} else if (lastContact > this.config.fritzdectMaxMinutes) {
|
|
613
|
+
deviceState = 'Offline'; //set online state to offline
|
|
614
|
+
this.offlineDevices.push(
|
|
615
|
+
{
|
|
616
|
+
Device: deviceName,
|
|
617
|
+
Adapter: deviceAdapterName,
|
|
618
|
+
Last_contact: lastContactString
|
|
643
619
|
}
|
|
644
|
-
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
break;
|
|
623
|
+
case 'homematic':
|
|
624
|
+
if (this.config.homematicMaxMinutes === -1) {
|
|
625
|
+
if (deviceUnreachState) {
|
|
645
626
|
deviceState = 'Offline'; //set online state to offline
|
|
646
627
|
this.offlineDevices.push(
|
|
647
628
|
{
|
|
@@ -651,20 +632,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
651
632
|
}
|
|
652
633
|
);
|
|
653
634
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
Device: deviceName,
|
|
662
|
-
Adapter: deviceAdapterName,
|
|
663
|
-
Last_contact: lastContactString
|
|
664
|
-
}
|
|
665
|
-
);
|
|
635
|
+
} else if (lastContact > this.config.homematicMaxMinutes) {
|
|
636
|
+
deviceState = 'Offline'; //set online state to offline
|
|
637
|
+
this.offlineDevices.push(
|
|
638
|
+
{
|
|
639
|
+
Device: deviceName,
|
|
640
|
+
Adapter: deviceAdapterName,
|
|
641
|
+
Last_contact: lastContactString
|
|
666
642
|
}
|
|
667
|
-
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
break;
|
|
646
|
+
case 'hue':
|
|
647
|
+
if (this.config.hueMaxMinutes === -1) {
|
|
648
|
+
if (!deviceUnreachState) {
|
|
668
649
|
deviceState = 'Offline'; //set online state to offline
|
|
669
650
|
this.offlineDevices.push(
|
|
670
651
|
{
|
|
@@ -674,20 +655,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
674
655
|
}
|
|
675
656
|
);
|
|
676
657
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
Device: deviceName,
|
|
685
|
-
Adapter: deviceAdapterName,
|
|
686
|
-
Last_contact: lastContactString
|
|
687
|
-
}
|
|
688
|
-
);
|
|
658
|
+
} else if (lastContact > this.config.hueMaxMinutes) {
|
|
659
|
+
deviceState = 'Offline'; //set online state to offline
|
|
660
|
+
this.offlineDevices.push(
|
|
661
|
+
{
|
|
662
|
+
Device: deviceName,
|
|
663
|
+
Adapter: deviceAdapterName,
|
|
664
|
+
Last_contact: lastContactString
|
|
689
665
|
}
|
|
690
|
-
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
break;
|
|
669
|
+
case 'hue extended':
|
|
670
|
+
if (this.config.hueextMaxMinutes === -1) {
|
|
671
|
+
if (!deviceUnreachState) {
|
|
691
672
|
deviceState = 'Offline'; //set online state to offline
|
|
692
673
|
this.offlineDevices.push(
|
|
693
674
|
{
|
|
@@ -697,20 +678,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
697
678
|
}
|
|
698
679
|
);
|
|
699
680
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
Device: deviceName,
|
|
708
|
-
Adapter: deviceAdapterName,
|
|
709
|
-
Last_contact: lastContactString
|
|
710
|
-
}
|
|
711
|
-
);
|
|
681
|
+
} else if (lastContact > this.config.hueextMaxMinutes) {
|
|
682
|
+
deviceState = 'Offline'; //set online state to offline
|
|
683
|
+
this.offlineDevices.push(
|
|
684
|
+
{
|
|
685
|
+
Device: deviceName,
|
|
686
|
+
Adapter: deviceAdapterName,
|
|
687
|
+
Last_contact: lastContactString
|
|
712
688
|
}
|
|
713
|
-
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
break;
|
|
692
|
+
case 'miHome':
|
|
693
|
+
if (this.config.mihomeMaxMinutes === -1) {
|
|
694
|
+
if (!deviceUnreachState) {
|
|
714
695
|
deviceState = 'Offline'; //set online state to offline
|
|
715
696
|
this.offlineDevices.push(
|
|
716
697
|
{
|
|
@@ -720,20 +701,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
720
701
|
}
|
|
721
702
|
);
|
|
722
703
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
Device: deviceName,
|
|
731
|
-
Adapter: deviceAdapterName,
|
|
732
|
-
Last_contact: lastContactString
|
|
733
|
-
}
|
|
734
|
-
);
|
|
704
|
+
} else if (lastContact > this.config.mihomeMaxMinutes) {
|
|
705
|
+
deviceState = 'Offline'; //set online state to offline
|
|
706
|
+
this.offlineDevices.push(
|
|
707
|
+
{
|
|
708
|
+
Device: deviceName,
|
|
709
|
+
Adapter: deviceAdapterName,
|
|
710
|
+
Last_contact: lastContactString
|
|
735
711
|
}
|
|
736
|
-
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
break;
|
|
715
|
+
case 'nuki_extended':
|
|
716
|
+
if (this.config.nukiextendMaxMinutes === -1) {
|
|
717
|
+
if (!deviceUnreachState) {
|
|
737
718
|
deviceState = 'Offline'; //set online state to offline
|
|
738
719
|
this.offlineDevices.push(
|
|
739
720
|
{
|
|
@@ -743,20 +724,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
743
724
|
}
|
|
744
725
|
);
|
|
745
726
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
Device: deviceName,
|
|
754
|
-
Adapter: deviceAdapterName,
|
|
755
|
-
Last_contact: lastContactString
|
|
756
|
-
}
|
|
757
|
-
);
|
|
727
|
+
} else if (lastContact > this.config.nukiextendMaxMinutes) {
|
|
728
|
+
deviceState = 'Offline'; //set online state to offline
|
|
729
|
+
this.offlineDevices.push(
|
|
730
|
+
{
|
|
731
|
+
Device: deviceName,
|
|
732
|
+
Adapter: deviceAdapterName,
|
|
733
|
+
Last_contact: lastContactString
|
|
758
734
|
}
|
|
759
|
-
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
break;
|
|
738
|
+
case 'ping':
|
|
739
|
+
if (this.config.pingMaxMinutes === -1) {
|
|
740
|
+
if (!deviceUnreachState) {
|
|
760
741
|
deviceState = 'Offline'; //set online state to offline
|
|
761
742
|
this.offlineDevices.push(
|
|
762
743
|
{
|
|
@@ -766,20 +747,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
766
747
|
}
|
|
767
748
|
);
|
|
768
749
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
Device: deviceName,
|
|
777
|
-
Adapter: deviceAdapterName,
|
|
778
|
-
Last_contact: lastContactString
|
|
779
|
-
}
|
|
780
|
-
);
|
|
750
|
+
} else if ((lastStateChange > this.config.pingMaxMinutes) && (!deviceUnreachState)) {
|
|
751
|
+
deviceState = 'Offline'; //set online state to offline
|
|
752
|
+
this.offlineDevices.push(
|
|
753
|
+
{
|
|
754
|
+
Device: deviceName,
|
|
755
|
+
Adapter: deviceAdapterName,
|
|
756
|
+
Last_contact: lastContactString
|
|
781
757
|
}
|
|
782
|
-
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
break;
|
|
761
|
+
case 'shelly':
|
|
762
|
+
if (this.config.shellyMaxMinutes === -1) {
|
|
763
|
+
if (!deviceUnreachState) {
|
|
783
764
|
deviceState = 'Offline'; //set online state to offline
|
|
784
765
|
this.offlineDevices.push(
|
|
785
766
|
{
|
|
@@ -789,20 +770,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
789
770
|
}
|
|
790
771
|
);
|
|
791
772
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
Device: deviceName,
|
|
800
|
-
Adapter: deviceAdapterName,
|
|
801
|
-
Last_contact: lastContactString
|
|
802
|
-
}
|
|
803
|
-
);
|
|
773
|
+
} else if (lastContact > this.config.shellyMaxMinutes) {
|
|
774
|
+
deviceState = 'Offline'; //set online state to offline
|
|
775
|
+
this.offlineDevices.push(
|
|
776
|
+
{
|
|
777
|
+
Device: deviceName,
|
|
778
|
+
Adapter: deviceAdapterName,
|
|
779
|
+
Last_contact: lastContactString
|
|
804
780
|
}
|
|
805
|
-
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
break;
|
|
784
|
+
case 'sonoff':
|
|
785
|
+
if (this.config.sonoffMaxMinutes === -1) {
|
|
786
|
+
if (!deviceUnreachState) {
|
|
806
787
|
deviceState = 'Offline'; //set online state to offline
|
|
807
788
|
this.offlineDevices.push(
|
|
808
789
|
{
|
|
@@ -812,20 +793,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
812
793
|
}
|
|
813
794
|
);
|
|
814
795
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
Device: deviceName,
|
|
823
|
-
Adapter: deviceAdapterName,
|
|
824
|
-
Last_contact: lastContactString
|
|
825
|
-
}
|
|
826
|
-
);
|
|
796
|
+
} else if (lastContact > this.config.sonoffMaxMinutes) {
|
|
797
|
+
deviceState = 'Offline'; //set online state to offline
|
|
798
|
+
this.offlineDevices.push(
|
|
799
|
+
{
|
|
800
|
+
Device: deviceName,
|
|
801
|
+
Adapter: deviceAdapterName,
|
|
802
|
+
Last_contact: lastContactString
|
|
827
803
|
}
|
|
828
|
-
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
break;
|
|
807
|
+
case 'sonos':
|
|
808
|
+
if (this.config.sonosMaxMinutes === -1) {
|
|
809
|
+
if (!deviceUnreachState) {
|
|
829
810
|
deviceState = 'Offline'; //set online state to offline
|
|
830
811
|
this.offlineDevices.push(
|
|
831
812
|
{
|
|
@@ -835,20 +816,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
835
816
|
}
|
|
836
817
|
);
|
|
837
818
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
Device: deviceName,
|
|
846
|
-
Adapter: deviceAdapterName,
|
|
847
|
-
Last_contact: lastContactString
|
|
848
|
-
}
|
|
849
|
-
);
|
|
819
|
+
} else if (lastContact > this.config.sonosMaxMinutes) {
|
|
820
|
+
deviceState = 'Offline'; //set online state to offline
|
|
821
|
+
this.offlineDevices.push(
|
|
822
|
+
{
|
|
823
|
+
Device: deviceName,
|
|
824
|
+
Adapter: deviceAdapterName,
|
|
825
|
+
Last_contact: lastContactString
|
|
850
826
|
}
|
|
851
|
-
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
break;
|
|
830
|
+
case 'switchbot ble':
|
|
831
|
+
if (this.config.switchbotMaxMinutes === -1) {
|
|
832
|
+
if (!deviceUnreachState) {
|
|
852
833
|
deviceState = 'Offline'; //set online state to offline
|
|
853
834
|
this.offlineDevices.push(
|
|
854
835
|
{
|
|
@@ -858,20 +839,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
858
839
|
}
|
|
859
840
|
);
|
|
860
841
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
Device: deviceName,
|
|
869
|
-
Adapter: deviceAdapterName,
|
|
870
|
-
Last_contact: lastContactString
|
|
871
|
-
}
|
|
872
|
-
);
|
|
842
|
+
} else if (lastContact > this.config.switchbotMaxMinutes) {
|
|
843
|
+
deviceState = 'Offline'; //set online state to offline
|
|
844
|
+
this.offlineDevices.push(
|
|
845
|
+
{
|
|
846
|
+
Device: deviceName,
|
|
847
|
+
Adapter: deviceAdapterName,
|
|
848
|
+
Last_contact: lastContactString
|
|
873
849
|
}
|
|
874
|
-
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
break;
|
|
853
|
+
case 'zigbee':
|
|
854
|
+
if (this.config.zigbeeMaxMinutes === -1) {
|
|
855
|
+
if (!deviceUnreachState) {
|
|
875
856
|
deviceState = 'Offline'; //set online state to offline
|
|
876
857
|
this.offlineDevices.push(
|
|
877
858
|
{
|
|
@@ -881,20 +862,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
881
862
|
}
|
|
882
863
|
);
|
|
883
864
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
Device: deviceName,
|
|
892
|
-
Adapter: deviceAdapterName,
|
|
893
|
-
Last_contact: lastContactString
|
|
894
|
-
}
|
|
895
|
-
);
|
|
865
|
+
} else if (lastContact > this.config.zigbeeMaxMinutes) {
|
|
866
|
+
deviceState = 'Offline'; //set online state to offline
|
|
867
|
+
this.offlineDevices.push(
|
|
868
|
+
{
|
|
869
|
+
Device: deviceName,
|
|
870
|
+
Adapter: deviceAdapterName,
|
|
871
|
+
Last_contact: lastContactString
|
|
896
872
|
}
|
|
897
|
-
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
break;
|
|
876
|
+
case 'zwave':
|
|
877
|
+
if (this.config.zwaveMaxMinutes === -1) {
|
|
878
|
+
if (!deviceUnreachState) {
|
|
898
879
|
deviceState = 'Offline'; //set online state to offline
|
|
899
880
|
this.offlineDevices.push(
|
|
900
881
|
{
|
|
@@ -904,116 +885,114 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
904
885
|
}
|
|
905
886
|
);
|
|
906
887
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
this.log.error(`(03) Error while getting timestate ${e}`);
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
// 2c. Count how many devcies are offline
|
|
917
|
-
this.offlineDevicesCount = this.offlineDevices.length;
|
|
918
|
-
|
|
919
|
-
// 3. Get battery states
|
|
920
|
-
const deviceBatteryState = await this.getInitValue(currDeviceString + this.arrDev[i].battery);
|
|
921
|
-
const shortDeviceBatteryState = await this.getInitValue(shortCurrDeviceString + this.arrDev[i].battery);
|
|
922
|
-
let batteryHealth;
|
|
923
|
-
|
|
924
|
-
if ((!deviceBatteryState) && (!shortDeviceBatteryState)) {
|
|
925
|
-
batteryHealth = ' - ';
|
|
926
|
-
} else {
|
|
927
|
-
|
|
928
|
-
switch (this.arrDev[i].adapter) {
|
|
929
|
-
case 'homematic':
|
|
930
|
-
if (deviceBatteryState === 0) {
|
|
931
|
-
batteryHealth = ' - ';
|
|
932
|
-
} else {
|
|
933
|
-
batteryHealth = deviceBatteryState + 'V';
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
this.batteryPowered.push(
|
|
937
|
-
{
|
|
938
|
-
Device: deviceName,
|
|
939
|
-
Adapter: deviceAdapterName,
|
|
940
|
-
Battery: batteryHealth
|
|
941
|
-
}
|
|
942
|
-
);
|
|
943
|
-
break;
|
|
944
|
-
case 'hue extended':
|
|
945
|
-
if (shortDeviceBatteryState) {
|
|
946
|
-
batteryHealth = shortDeviceBatteryState + '%';
|
|
947
|
-
this.batteryPowered.push(
|
|
888
|
+
} else if (lastContact > this.config.zwaveMaxMinutes) {
|
|
889
|
+
deviceState = 'Offline'; //set online state to offline
|
|
890
|
+
this.offlineDevices.push(
|
|
948
891
|
{
|
|
949
892
|
Device: deviceName,
|
|
950
893
|
Adapter: deviceAdapterName,
|
|
951
|
-
|
|
894
|
+
Last_contact: lastContactString
|
|
952
895
|
}
|
|
953
896
|
);
|
|
954
897
|
}
|
|
955
898
|
break;
|
|
956
|
-
default:
|
|
957
|
-
batteryHealth = (deviceBatteryState) + '%';
|
|
958
|
-
this.batteryPowered.push(
|
|
959
|
-
{
|
|
960
|
-
Device: deviceName,
|
|
961
|
-
Adapter: deviceAdapterName,
|
|
962
|
-
Battery: batteryHealth
|
|
963
|
-
}
|
|
964
|
-
);
|
|
965
899
|
}
|
|
900
|
+
} catch (e) {
|
|
901
|
+
this.log.error(`(03) Error while getting timestate ${e}`);
|
|
966
902
|
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
|
|
967
906
|
|
|
968
|
-
|
|
969
|
-
|
|
907
|
+
// 2c. Count how many devcies are offline
|
|
908
|
+
this.offlineDevicesCount = this.offlineDevices.length;
|
|
970
909
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
910
|
+
// 3. Get battery states
|
|
911
|
+
const deviceBatteryState = await this.getInitValue(currDeviceString + this.arrDev[i].battery);
|
|
912
|
+
const shortDeviceBatteryState = await this.getInitValue(shortCurrDeviceString + this.arrDev[i].battery);
|
|
913
|
+
let batteryHealth;
|
|
975
914
|
|
|
915
|
+
if ((!deviceBatteryState) && (!shortDeviceBatteryState)) {
|
|
916
|
+
batteryHealth = ' - ';
|
|
917
|
+
} else {
|
|
918
|
+
|
|
919
|
+
switch (this.arrDev[i].adapter) {
|
|
920
|
+
case 'homematic':
|
|
921
|
+
if (deviceBatteryState === 0) {
|
|
922
|
+
batteryHealth = ' - ';
|
|
923
|
+
} else {
|
|
924
|
+
batteryHealth = deviceBatteryState + 'V';
|
|
925
|
+
}
|
|
976
926
|
|
|
977
|
-
|
|
978
|
-
if (deviceBatteryState && (deviceBatteryState < batteryWarningMin)) {
|
|
979
|
-
this.batteryLowPowered.push(
|
|
927
|
+
this.batteryPowered.push(
|
|
980
928
|
{
|
|
981
929
|
Device: deviceName,
|
|
982
930
|
Adapter: deviceAdapterName,
|
|
983
931
|
Battery: batteryHealth
|
|
984
932
|
}
|
|
985
933
|
);
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
934
|
+
break;
|
|
935
|
+
case 'hue extended':
|
|
936
|
+
if (shortDeviceBatteryState) {
|
|
937
|
+
batteryHealth = shortDeviceBatteryState + '%';
|
|
938
|
+
this.batteryPowered.push(
|
|
939
|
+
{
|
|
940
|
+
Device: deviceName,
|
|
941
|
+
Adapter: deviceAdapterName,
|
|
942
|
+
Battery: batteryHealth
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
break;
|
|
947
|
+
default:
|
|
948
|
+
batteryHealth = (deviceBatteryState) + '%';
|
|
949
|
+
this.batteryPowered.push(
|
|
990
950
|
{
|
|
991
951
|
Device: deviceName,
|
|
992
952
|
Adapter: deviceAdapterName,
|
|
993
953
|
Battery: batteryHealth
|
|
994
954
|
}
|
|
995
955
|
);
|
|
996
|
-
}
|
|
997
956
|
}
|
|
957
|
+
}
|
|
998
958
|
|
|
999
|
-
|
|
1000
|
-
|
|
959
|
+
// 3b. Count how many devices are with battery
|
|
960
|
+
this.batteryPoweredCount = this.batteryPowered.length;
|
|
1001
961
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
962
|
+
// 3c. Count how many devices are with low battery
|
|
963
|
+
const batteryWarningMin = this.config.minWarnBatterie;
|
|
964
|
+
const deviceLowBatState = await this.getInitValue(currDeviceString + this.arrDev[i].isLowBat);
|
|
965
|
+
const deviceLowBatStateHM = await this.getInitValue(currDeviceString + this.arrDev[i].isLowBat2);
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
if (this.arrDev[i].isLowBat === 'none') {
|
|
969
|
+
if (deviceBatteryState && (deviceBatteryState < batteryWarningMin)) {
|
|
970
|
+
this.batteryLowPowered.push(
|
|
971
|
+
{
|
|
972
|
+
Device: deviceName,
|
|
973
|
+
Adapter: deviceAdapterName,
|
|
974
|
+
Battery: batteryHealth
|
|
975
|
+
}
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
} else {
|
|
979
|
+
if (deviceLowBatState || deviceLowBatStateHM) {
|
|
980
|
+
this.batteryLowPowered.push(
|
|
981
|
+
{
|
|
982
|
+
Device: deviceName,
|
|
983
|
+
Adapter: deviceAdapterName,
|
|
984
|
+
Battery: batteryHealth
|
|
985
|
+
}
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// 3d. Count how many devices are with low battery
|
|
991
|
+
this.lowBatteryPoweredCount = this.batteryLowPowered.length;
|
|
992
|
+
|
|
993
|
+
// 4. Add all devices in the list
|
|
994
|
+
if (this.config.listOnlyBattery) {
|
|
995
|
+
if (deviceBatteryState !== null || shortDeviceBatteryState !== null) {
|
|
1017
996
|
this.listAllDevices.push(
|
|
1018
997
|
{
|
|
1019
998
|
Device: deviceName,
|
|
@@ -1025,55 +1004,228 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1025
1004
|
}
|
|
1026
1005
|
);
|
|
1027
1006
|
}
|
|
1007
|
+
} else if (!this.config.listOnlyBattery) {
|
|
1008
|
+
this.listAllDevices.push(
|
|
1009
|
+
{
|
|
1010
|
+
Device: deviceName,
|
|
1011
|
+
Adapter: deviceAdapterName,
|
|
1012
|
+
Battery: batteryHealth,
|
|
1013
|
+
Link_quality: linkQuality,
|
|
1014
|
+
Last_contact: lastContactString,
|
|
1015
|
+
Status: deviceState
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1028
1019
|
|
|
1029
1020
|
|
|
1030
|
-
|
|
1031
|
-
|
|
1021
|
+
// 4a. Count how many devices are exists
|
|
1022
|
+
this.deviceCounter = this.listAllDevices.length;
|
|
1023
|
+
}
|
|
1024
|
+
} //<--End of second loop
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
async createDataForEachAdpt(adptName) {
|
|
1028
|
+
this.log.debug(`Function started: ${this.createDataForEachAdpt.name}`);
|
|
1029
|
+
await this.resetVars();
|
|
1030
|
+
|
|
1031
|
+
for (let i = 0; i < this.arrDev.length; i++) {
|
|
1032
|
+
|
|
1033
|
+
if (this.arrDev[i].adapter.includes(adptName)) {
|
|
1034
|
+
await this.createData(i);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
}
|
|
1038
|
+
await this.writeDatapoints(adptName);
|
|
1039
|
+
|
|
1040
|
+
this.log.debug(`Function finished: ${this.createDataForEachAdpt.name}`);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
async createDataOfAll() {
|
|
1044
|
+
this.log.debug(`Function started: ${this.createDataOfAll.name}`);
|
|
1045
|
+
await this.resetVars();
|
|
1046
|
+
|
|
1047
|
+
for (let i = 0; i < this.arrDev.length; i++) {
|
|
1048
|
+
|
|
1049
|
+
await this.createData(i);
|
|
1050
|
+
|
|
1051
|
+
}
|
|
1052
|
+
await this.writeDatapoints();
|
|
1053
|
+
|
|
1054
|
+
this.log.debug(`Function finished: ${this.createDataOfAll.name}`);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
async resetVars() {
|
|
1058
|
+
// arrays
|
|
1059
|
+
this.offlineDevices = [],
|
|
1060
|
+
this.linkQualityDevices = [];
|
|
1061
|
+
this.batteryPowered = [];
|
|
1062
|
+
this.batteryLowPowered = [];
|
|
1063
|
+
this.listAllDevices = [];
|
|
1064
|
+
|
|
1065
|
+
// counts
|
|
1066
|
+
this.offlineDevicesCount = 0;
|
|
1067
|
+
this.deviceCounter = 0;
|
|
1068
|
+
this.linkQualityCount = 0;
|
|
1069
|
+
this.batteryPoweredCount = 0;
|
|
1070
|
+
this.lowBatteryPoweredCount = 0;
|
|
1071
|
+
|
|
1072
|
+
this.deviceReachable = '';
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
async main() {
|
|
1076
|
+
this.log.debug(`Function started: ${this.main.name}`);
|
|
1077
|
+
|
|
1078
|
+
this.supAdapter = {
|
|
1079
|
+
alexa2: this.config.alexa2Devices,
|
|
1080
|
+
esphome: this.config.esphomeDevices,
|
|
1081
|
+
zigbee: this.config.zigbeeDevices,
|
|
1082
|
+
ble: this.config.bleDevices,
|
|
1083
|
+
sonoff: this.config.sonoffDevices,
|
|
1084
|
+
shelly: this.config.shellyDevices,
|
|
1085
|
+
homematic: this.config.homematicDevices,
|
|
1086
|
+
deconz: this.config.deconzDevices,
|
|
1087
|
+
zwave: this.config.zwaveDevices,
|
|
1088
|
+
dect: this.config.dectDevices,
|
|
1089
|
+
hue: this.config.hueDevices,
|
|
1090
|
+
hueExt: this.config.hueExtDevices,
|
|
1091
|
+
nukiExt: this.config.nukiExtDevices,
|
|
1092
|
+
ping: this.config.pingDevices,
|
|
1093
|
+
switchbotBle: this.config.switchbotBleDevices,
|
|
1094
|
+
sonos: this.config.sonosDevices,
|
|
1095
|
+
mihome: this.config.mihomeDevices,
|
|
1096
|
+
mihomeGW: this.config.mihomeDevices,
|
|
1097
|
+
test: false, // Only for Developer
|
|
1098
|
+
test2: false, // Only for Developer
|
|
1099
|
+
test3: false // Only for Developer
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
for(const [id] of Object.entries(this.arrApart)) {
|
|
1103
|
+
if (this.supAdapter[id]) {
|
|
1104
|
+
this.arrDev.push(this.arrApart[id]);
|
|
1105
|
+
this.adapterSelected.push(await this.capitalize(id));
|
|
1106
|
+
this.log.debug(JSON.stringify(this.arrDev));
|
|
1107
|
+
|
|
1108
|
+
//create and fill datapoints for each adapter if selected
|
|
1109
|
+
if (this.config.createOwnFolder) {
|
|
1110
|
+
try {
|
|
1111
|
+
await this.createDPsForEachAdapter(id);
|
|
1112
|
+
this.log.debug(`Created datapoints for ${await this.capitalize(id)}`);
|
|
1113
|
+
await this.createDataForEachAdpt(id);
|
|
1114
|
+
this.log.debug(`Created and filled data for each adapter`);
|
|
1115
|
+
} catch (e) {
|
|
1116
|
+
this.log.warn(`Error at creating/filling datapoints for each adapter: ${e}`);
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1032
1119
|
}
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
//Check if an Adapter is selected.
|
|
1124
|
+
if (this.adapterSelected.length >= 1) {
|
|
1125
|
+
this.log.info(`Number of selected adapters: ${this.adapterSelected.length}. Loading data from: ${(this.adapterSelected).join(', ')} ...`);
|
|
1126
|
+
} else {
|
|
1127
|
+
this.log.warn(`No adapter selected. Please check the instance configuration!`);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/*=============================================
|
|
1132
|
+
= Start of main loop =
|
|
1133
|
+
=============================================*/
|
|
1134
|
+
try {
|
|
1135
|
+
await this.createDataOfAll();
|
|
1136
|
+
this.log.debug(`Created and filled data for all adapters`);
|
|
1137
|
+
} catch (e) {
|
|
1138
|
+
this.log.warn(`Error at creating/filling datapoints for all adapters: ${e}`);
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1035
1141
|
|
|
1036
1142
|
this.log.debug(`Function finished: ${this.main.name}`);
|
|
1037
1143
|
} //<--End of main function
|
|
1038
1144
|
|
|
1039
|
-
|
|
1145
|
+
|
|
1146
|
+
async sendOfflineNotifications() {
|
|
1040
1147
|
/*=============================================
|
|
1041
|
-
=
|
|
1148
|
+
= send offline notification =
|
|
1042
1149
|
=============================================*/
|
|
1043
|
-
this.log.debug(`Start the function: ${this.sendNotifications.name}`);
|
|
1044
1150
|
|
|
1045
|
-
|
|
1046
|
-
instance: this.config.instancePushover,
|
|
1047
|
-
title: this.config.titlePushover,
|
|
1048
|
-
device: this.config.devicePushover,
|
|
1049
|
-
prio: this.config.prioPushover
|
|
1151
|
+
this.log.debug(`Start the function: ${this.sendOfflineNotifications.name}`);
|
|
1050
1152
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
const email = {
|
|
1062
|
-
instance: this.config.instanceEmail,
|
|
1063
|
-
subject: this.config.subjectEmail,
|
|
1064
|
-
sendTo: this.config.sendToEmail
|
|
1153
|
+
try {
|
|
1154
|
+
let msg = '';
|
|
1155
|
+
const offlineDevicesCountOld = await this.getOwnInitValue('offlineCount');
|
|
1156
|
+
|
|
1157
|
+
if ((this.offlineDevicesCount != offlineDevicesCountOld)) {
|
|
1158
|
+
if (this.offlineDevicesCount == 1) { // make singular if it is only one device
|
|
1159
|
+
msg = 'Folgendes Gerät ist seit einiger Zeit nicht erreichbar: \n';
|
|
1160
|
+
} else if (this.offlineDevicesCount >= 2) { //make plural if it is more than one device
|
|
1161
|
+
msg = `Folgende ${this.offlineDevicesCount} Geräte sind seit einiger Zeit nicht erreichbar: \n`;
|
|
1162
|
+
}
|
|
1065
1163
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1164
|
+
for (const id of this.offlineDevices) {
|
|
1165
|
+
msg = `${msg} \n ${id['Device']} (${id['Last_contact']})`;
|
|
1166
|
+
}
|
|
1167
|
+
this.log.info(msg);
|
|
1168
|
+
await this.setStateAsync('lastNotification', msg, true);
|
|
1169
|
+
if (this.config.instancePushover) {
|
|
1170
|
+
try {
|
|
1171
|
+
await this.sendPushover(msg);
|
|
1172
|
+
} catch (e) {
|
|
1173
|
+
this.log.warn (`Getting error at sending pushover notification ${e}`);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
if (this.config.instanceTelegram) {
|
|
1177
|
+
try {
|
|
1178
|
+
await this.sendTelegram(msg);
|
|
1179
|
+
} catch (e) {
|
|
1180
|
+
this.log.warn (`Getting error at sending telegram notification ${e}`);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (this.config.instanceWhatsapp) {
|
|
1184
|
+
try {
|
|
1185
|
+
await this.sendWhatsapp(msg);
|
|
1186
|
+
} catch (e) {
|
|
1187
|
+
this.log.warn (`Getting error at sending whatsapp notification ${e}`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
if (this.config.instanceEmail) {
|
|
1191
|
+
try {
|
|
1192
|
+
await this.sendEmail(msg);
|
|
1193
|
+
} catch (e) {
|
|
1194
|
+
this.log.warn (`Getting error at sending email notification ${e}`);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
if (this.config.instanceJarvis) {
|
|
1198
|
+
try {
|
|
1199
|
+
await this.sendJarvis('{"title":"'+ this.config.titleJarvis +' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')","message":" ' + this.offlineDevicesCount + ' Geräte sind nicht erreichbar","display": "drawer"}');
|
|
1200
|
+
} catch (e) {
|
|
1201
|
+
this.log.warn (`Getting error at sending jarvis notification ${e}`);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
if (this.config.instanceLovelace) {
|
|
1205
|
+
try {
|
|
1206
|
+
await this.sendLovelace('{"message":" ' + this.offlineDevicesCount + ' Geräte sind nicht erreichbar", "title":"'+ this.config.titleLovelace +' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')"}');
|
|
1207
|
+
} catch (e) {
|
|
1208
|
+
this.log.warn (`Getting error at sending lovelace notification ${e}`);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
} catch (e) {
|
|
1213
|
+
this.log.debug(`Getting error at sending offline notification ${e}`);
|
|
1214
|
+
}
|
|
1215
|
+
this.log.debug(`Finished the function: ${this.sendOfflineNotifications.name}`);
|
|
1216
|
+
}//<--End of offline notification
|
|
1070
1217
|
|
|
1071
|
-
};
|
|
1072
|
-
const lovelace = {
|
|
1073
|
-
instance: this.config.instanceLovelace,
|
|
1074
|
-
title: this.config.titleLovelace
|
|
1075
1218
|
|
|
1076
|
-
|
|
1219
|
+
async sendBatteryNotifications() {
|
|
1220
|
+
/*=============================================
|
|
1221
|
+
= send low battery notification =
|
|
1222
|
+
=============================================*/
|
|
1223
|
+
|
|
1224
|
+
this.log.debug(`Start the function: ${this.sendBatteryNotifications.name}`);
|
|
1225
|
+
const now = new Date();
|
|
1226
|
+
const today = now.getDay();
|
|
1227
|
+
const checkDays = [];
|
|
1228
|
+
let checkToday;
|
|
1077
1229
|
|
|
1078
1230
|
const choosedDays = {
|
|
1079
1231
|
monday: this.config.checkMonday,
|
|
@@ -1085,262 +1237,157 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1085
1237
|
sunday: this.config.checkSunday,
|
|
1086
1238
|
};
|
|
1087
1239
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
};
|
|
1240
|
+
if (choosedDays.monday) checkDays.push(1);
|
|
1241
|
+
if (choosedDays.tuesday) checkDays.push(2);
|
|
1242
|
+
if (choosedDays.wednesday) checkDays.push(3);
|
|
1243
|
+
if (choosedDays.thursday) checkDays.push(4);
|
|
1244
|
+
if (choosedDays.friday) checkDays.push(5);
|
|
1245
|
+
if (choosedDays.saturday) checkDays.push(6);
|
|
1246
|
+
if (choosedDays.sunday) checkDays.push(0);
|
|
1096
1247
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
};
|
|
1248
|
+
//Check if the message should be send today
|
|
1249
|
+
checkDays.forEach(object => {
|
|
1250
|
+
if((object >= 0) && today == object){
|
|
1251
|
+
checkToday = true;
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1104
1254
|
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1255
|
+
//Check first if a day is selected
|
|
1256
|
+
if (checkDays.length >= 1) {
|
|
1257
|
+
this.log.debug(`Number of selected days: ${checkDays.length}. Send Message on: ${(checkDays).join(', ')} ...`);
|
|
1258
|
+
} else {
|
|
1259
|
+
this.log.warn(`No days selected. Please check the instance configuration!`);
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1111
1262
|
|
|
1112
|
-
|
|
1113
|
-
await this.sendToAsync(email.instance, 'send', {
|
|
1114
|
-
sendTo: email.sendTo,
|
|
1115
|
-
text: text,
|
|
1116
|
-
subject: email.subject
|
|
1117
|
-
});
|
|
1118
|
-
};
|
|
1263
|
+
try {
|
|
1119
1264
|
|
|
1120
|
-
|
|
1121
|
-
await this.
|
|
1122
|
-
};
|
|
1265
|
+
//Check if the message for low battery was already sent today
|
|
1266
|
+
const lastBatteryNotifyIndicator = await this.getOwnInitValue('info.lastBatteryNotification');
|
|
1123
1267
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1268
|
+
if (now.getHours() < 11) {await this.setStateAsync('info.lastBatteryNotification', false, true);} //set indicator for send message first to 'false' later after sending to 'true'
|
|
1269
|
+
if ((now.getHours() > 11) && (!lastBatteryNotifyIndicator) && (checkToday != undefined)){
|
|
1270
|
+
let infotext = '';
|
|
1127
1271
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
let msg = '';
|
|
1132
|
-
const offlineDevicesCountOld = await this.getOwnInitValue('offlineCount');
|
|
1133
|
-
|
|
1134
|
-
if ((this.offlineDevicesCount != offlineDevicesCountOld)) {
|
|
1135
|
-
if (this.offlineDevicesCount == 1) { // make singular if it is only one device
|
|
1136
|
-
msg = 'Folgendes Gerät ist seit einiger Zeit nicht erreichbar: \n';
|
|
1137
|
-
} else if (this.offlineDevicesCount >= 2) { //make plural if it is more than one device
|
|
1138
|
-
msg = `Folgende ${this.offlineDevicesCount} Geräte sind seit einiger Zeit nicht erreichbar: \n`;
|
|
1139
|
-
}
|
|
1272
|
+
for (const id of this.batteryLowPowered) {
|
|
1273
|
+
infotext = infotext + '\n' + id['Device'] + ' (' + id['Battery'] + ')'.split(', ');
|
|
1274
|
+
}
|
|
1140
1275
|
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
if (pushover.instance) {
|
|
1276
|
+
if (this.lowBatteryPoweredCount > 0) {
|
|
1277
|
+
this.log.info(`Niedrige Batteriezustände: ${infotext}`);
|
|
1278
|
+
await this.setStateAsync('lastNotification', infotext, true);
|
|
1279
|
+
|
|
1280
|
+
if (this.config.instancePushover) {
|
|
1147
1281
|
try {
|
|
1148
|
-
await sendPushover(
|
|
1282
|
+
await this.sendPushover(`Niedrige Batteriezustände: ${infotext}`);
|
|
1149
1283
|
} catch (e) {
|
|
1150
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1284
|
+
this.log.warn (`Getting error at sending pushover notification ${e}`);
|
|
1151
1285
|
}
|
|
1152
1286
|
}
|
|
1153
|
-
if (
|
|
1287
|
+
if (this.config.instanceTelegram) {
|
|
1154
1288
|
try {
|
|
1155
|
-
await sendTelegram(
|
|
1289
|
+
await this.sendTelegram(`Niedrige Batteriezustände: ${infotext}`);
|
|
1156
1290
|
} catch (e) {
|
|
1157
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1291
|
+
this.log.warn (`Getting error at sending telegram notification ${e}`);
|
|
1158
1292
|
}
|
|
1159
1293
|
}
|
|
1160
|
-
if (
|
|
1294
|
+
if (this.config.instanceWhatsapp) {
|
|
1161
1295
|
try {
|
|
1162
|
-
await sendWhatsapp(
|
|
1296
|
+
await this.sendWhatsapp(`Niedrige Batteriezustände: ${infotext}`);
|
|
1163
1297
|
} catch (e) {
|
|
1164
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1298
|
+
this.log.warn (`Getting error at sending whatsapp notification ${e}`);
|
|
1165
1299
|
}
|
|
1166
1300
|
}
|
|
1167
|
-
if (
|
|
1301
|
+
if (this.config.instanceEmail) {
|
|
1168
1302
|
try {
|
|
1169
|
-
await sendEmail(
|
|
1303
|
+
await this.sendEmail(`Niedrige Batteriezustände: ${infotext}`);
|
|
1170
1304
|
} catch (e) {
|
|
1171
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1305
|
+
this.log.warn (`Getting error at sending email notification ${e}`);
|
|
1172
1306
|
}
|
|
1173
1307
|
}
|
|
1174
|
-
if (
|
|
1308
|
+
if (this.config.instanceJarvis) {
|
|
1175
1309
|
try {
|
|
1176
|
-
await sendJarvis('{"title":"'+
|
|
1310
|
+
await this.sendJarvis('{"title":"'+ this.config.titleJarvis +' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')","message":" ' + this.lowBatteryPoweredCount + ' Geräte mit schwacher Batterie","display": "drawer"}');
|
|
1177
1311
|
} catch (e) {
|
|
1178
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1312
|
+
this.log.warn (`Getting error at sending jarvis notification ${e}`);
|
|
1179
1313
|
}
|
|
1180
1314
|
}
|
|
1181
|
-
if (
|
|
1315
|
+
if (this.config.instanceLovelace) {
|
|
1182
1316
|
try {
|
|
1183
|
-
await sendLovelace('{"message":" ' + this.
|
|
1317
|
+
await this.sendLovelace('{"message":" ' + this.lowBatteryPoweredCount + ' Geräte mit schwacher Batterie", "title":"'+ this.config.titleLovelace +' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')"}');
|
|
1184
1318
|
} catch (e) {
|
|
1185
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
} catch (e) {
|
|
1190
|
-
this.log.debug(`Getting error at sending offline notification ${e}`);
|
|
1191
|
-
}
|
|
1192
|
-
}//<--End of offline notification
|
|
1193
|
-
|
|
1194
|
-
/*---------- Low battery Notification ----------*/
|
|
1195
|
-
const now = new Date();
|
|
1196
|
-
const today = now.getDay();
|
|
1197
|
-
const checkDays = [];
|
|
1198
|
-
let checkToday;
|
|
1199
|
-
|
|
1200
|
-
if (choosedDays.monday) checkDays.push(1);
|
|
1201
|
-
if (choosedDays.tuesday) checkDays.push(2);
|
|
1202
|
-
if (choosedDays.wednesday) checkDays.push(3);
|
|
1203
|
-
if (choosedDays.thursday) checkDays.push(4);
|
|
1204
|
-
if (choosedDays.friday) checkDays.push(5);
|
|
1205
|
-
if (choosedDays.saturday) checkDays.push(6);
|
|
1206
|
-
if (choosedDays.sunday) checkDays.push(0);
|
|
1207
|
-
|
|
1208
|
-
if (this.config.checkSendBatteryMsg) this.log.debug(JSON.stringify(checkDays));
|
|
1209
|
-
|
|
1210
|
-
checkDays.forEach(object => {
|
|
1211
|
-
if((object >= 0) && today == object){
|
|
1212
|
-
checkToday = true;
|
|
1213
|
-
}
|
|
1214
|
-
});
|
|
1215
|
-
|
|
1216
|
-
if (this.config.checkSendBatteryMsg) {
|
|
1217
|
-
try {
|
|
1218
|
-
const lastBatteryNotifyIndicator = await this.getOwnInitValue('info.lastBatteryNotification');
|
|
1219
|
-
const batteryWarningMin = this.config.minWarnBatterie;
|
|
1220
|
-
|
|
1221
|
-
if (now.getHours() < 11) {await this.setStateAsync('info.lastBatteryNotification', false, true);} //Nur einmal abfragen
|
|
1222
|
-
if ((now.getHours() > 11) && (!lastBatteryNotifyIndicator) && (checkToday != undefined)){
|
|
1223
|
-
let batteryMinCount = 0;
|
|
1224
|
-
let infotext = '';
|
|
1225
|
-
|
|
1226
|
-
for (const id of this.batteryPowered) {
|
|
1227
|
-
if (id['Battery']) {
|
|
1228
|
-
const batteryValue = parseFloat(id['Battery'].replace('%', ''));
|
|
1229
|
-
if ((batteryValue < batteryWarningMin) && (id['Adapter'] != 'Homematic')) {
|
|
1230
|
-
infotext = infotext + '\n' + id['Device'] + ' ' + ' (' + id['Battery'] + ')'.split(', ');
|
|
1231
|
-
++batteryMinCount;
|
|
1232
|
-
}
|
|
1319
|
+
this.log.warn (`Getting error at sending lovelace notification ${e}`);
|
|
1233
1320
|
}
|
|
1234
1321
|
}
|
|
1235
|
-
if (batteryMinCount > 0) {
|
|
1236
|
-
this.log.info(`Batteriezustände: ${infotext}`);
|
|
1237
|
-
await this.setStateAsync('lastNotification', infotext, true);
|
|
1238
|
-
|
|
1239
|
-
if (pushover.instance) {
|
|
1240
|
-
try {
|
|
1241
|
-
await sendPushover(`Batteriezustände: ${infotext}`);
|
|
1242
|
-
} catch (e) {
|
|
1243
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
if (telegram.instance) {
|
|
1247
|
-
try {
|
|
1248
|
-
await sendTelegram(`Batteriezustände: ${infotext}`);
|
|
1249
|
-
} catch (e) {
|
|
1250
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
if (whatsapp.instance) {
|
|
1254
|
-
try {
|
|
1255
|
-
await sendWhatsapp(`Batteriezustände: ${infotext}`);
|
|
1256
|
-
} catch (e) {
|
|
1257
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
if (email.instance) {
|
|
1261
|
-
try {
|
|
1262
|
-
await sendEmail(`Batteriezustände: ${infotext}`);
|
|
1263
|
-
} catch (e) {
|
|
1264
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
if (jarvis.instance) {
|
|
1268
|
-
try {
|
|
1269
|
-
await sendJarvis('{"title":"'+ jarvis.title +' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')","message":" ' + batteryMinCount + ' Geräte mit schwacher Batterie","display": "drawer"}');
|
|
1270
|
-
} catch (e) {
|
|
1271
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
if (lovelace.instance) {
|
|
1275
|
-
try {
|
|
1276
|
-
await sendLovelace('{"message":" ' + batteryMinCount + ' Geräte mit schwacher Batterie", "title":"'+ lovelace.title +' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')"}');
|
|
1277
|
-
} catch (e) {
|
|
1278
|
-
this.log.warn (`Getting error at sending notification ${e}`);
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
1322
|
|
|
1282
|
-
|
|
1283
|
-
}
|
|
1323
|
+
await this.setStateAsync('info.lastBatteryNotification', true, true);
|
|
1284
1324
|
}
|
|
1285
|
-
} catch (e) {
|
|
1286
|
-
this.log.debug(`Getting error at sending battery notification ${e}`);
|
|
1287
1325
|
}
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1326
|
+
} catch (e) {
|
|
1327
|
+
this.log.debug(`Getting error at sending battery notification ${e}`);
|
|
1328
|
+
}
|
|
1329
|
+
this.log.debug(`Finished the function: ${this.sendBatteryNotifications.name}`);
|
|
1330
|
+
}//<--End of battery notification
|
|
1292
1331
|
|
|
1293
|
-
async writeDatapoints() {
|
|
1332
|
+
async writeDatapoints(adptName) {
|
|
1294
1333
|
/*=============================================
|
|
1295
1334
|
= Write Datapoints =
|
|
1296
1335
|
=============================================*/
|
|
1336
|
+
|
|
1297
1337
|
this.log.debug(`Start the function: ${this.writeDatapoints.name}`);
|
|
1298
1338
|
|
|
1299
1339
|
try {
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1340
|
+
|
|
1341
|
+
let dpSubFolder;
|
|
1342
|
+
if (adptName) { //write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
|
|
1343
|
+
dpSubFolder = adptName + '.';
|
|
1344
|
+
} else {
|
|
1345
|
+
dpSubFolder = '';}
|
|
1346
|
+
|
|
1347
|
+
await this.setStateAsync(`${dpSubFolder}offlineCount`, {val: this.offlineDevicesCount, ack: true});
|
|
1348
|
+
await this.setStateAsync(`${dpSubFolder}countAll`, {val: this.deviceCounter, ack: true});
|
|
1349
|
+
await this.setStateAsync(`${dpSubFolder}batteryCount`, {val: this.batteryPoweredCount, ack: true});
|
|
1350
|
+
await this.setStateAsync(`${dpSubFolder}lowBatteryCount`, {val: this.lowBatteryPoweredCount, ack: true});
|
|
1304
1351
|
|
|
1305
1352
|
if (this.deviceCounter == 0) {
|
|
1306
1353
|
this.listAllDevices = [{Device: '--keine--', Adapter: '', Battery: '', Last_contact: '', Link_quality: ''}]; //JSON-Info Gesamtliste mit Info je Gerät
|
|
1307
1354
|
|
|
1308
|
-
await this.setStateAsync(
|
|
1355
|
+
await this.setStateAsync(`${dpSubFolder}listAll`, {val: JSON.stringify(this.listAllDevices), ack: true});
|
|
1309
1356
|
} else {
|
|
1310
|
-
await this.setStateAsync(
|
|
1357
|
+
await this.setStateAsync(`${dpSubFolder}listAll`, {val: JSON.stringify(this.listAllDevices), ack: true});
|
|
1311
1358
|
}
|
|
1312
1359
|
|
|
1313
1360
|
if (this.linkQualityCount == 0) {
|
|
1314
1361
|
this.linkQualityDevices = [{Device: '--keine--', Adapter: '', Link_quality: ''}]; //JSON-Info alle mit LinkQuality
|
|
1315
1362
|
|
|
1316
|
-
await this.setStateAsync(
|
|
1363
|
+
await this.setStateAsync(`${dpSubFolder}linkQualityList`, {val: JSON.stringify(this.linkQualityDevices), ack: true});
|
|
1317
1364
|
} else {
|
|
1318
|
-
await this.setStateAsync(
|
|
1365
|
+
await this.setStateAsync(`${dpSubFolder}linkQualityList`, {val: JSON.stringify(this.linkQualityDevices), ack: true});
|
|
1319
1366
|
}
|
|
1320
1367
|
|
|
1321
1368
|
|
|
1322
1369
|
if (this.offlineDevicesCount == 0) {
|
|
1323
1370
|
this.offlineDevices = [{Device: '--keine--', Adapter: '', Last_contact: ''}]; //JSON-Info alle offline-Geräte = 0
|
|
1324
1371
|
|
|
1325
|
-
await this.setStateAsync(
|
|
1372
|
+
await this.setStateAsync(`${dpSubFolder}offlineList`, {val: JSON.stringify(this.offlineDevices), ack: true});
|
|
1326
1373
|
} else {
|
|
1327
|
-
await this.setStateAsync(
|
|
1374
|
+
await this.setStateAsync(`${dpSubFolder}offlineList`, {val: JSON.stringify(this.offlineDevices), ack: true});
|
|
1328
1375
|
}
|
|
1329
1376
|
|
|
1330
1377
|
if (this.batteryPoweredCount == 0) {
|
|
1331
1378
|
this.batteryPowered = [{Device: '--keine--', Adapter: '', Battery: ''}]; //JSON-Info alle batteriebetriebenen Geräte
|
|
1332
1379
|
|
|
1333
|
-
await this.setStateAsync(
|
|
1380
|
+
await this.setStateAsync(`${dpSubFolder}batteryList`, {val: JSON.stringify(this.batteryPowered), ack: true});
|
|
1334
1381
|
} else {
|
|
1335
|
-
await this.setStateAsync(
|
|
1382
|
+
await this.setStateAsync(`${dpSubFolder}batteryList`, {val: JSON.stringify(this.batteryPowered), ack: true});
|
|
1336
1383
|
}
|
|
1337
1384
|
|
|
1338
1385
|
if (this.lowBatteryPoweredCount == 0) {
|
|
1339
1386
|
this.batteryLowPowered = [{Device: '--keine--', Adapter: '', Battery: ''}]; //JSON-Info alle batteriebetriebenen Geräte
|
|
1340
1387
|
|
|
1341
|
-
await this.setStateAsync(
|
|
1388
|
+
await this.setStateAsync(`${dpSubFolder}lowBatteryList`, {val: JSON.stringify(this.batteryLowPowered), ack: true});
|
|
1342
1389
|
} else {
|
|
1343
|
-
await this.setStateAsync(
|
|
1390
|
+
await this.setStateAsync(`${dpSubFolder}lowBatteryList`, {val: JSON.stringify(this.batteryLowPowered), ack: true});
|
|
1344
1391
|
}
|
|
1345
1392
|
|
|
1346
1393
|
//Zeitstempel wann die Datenpunkte zuletzt gecheckt wurden
|
|
@@ -1351,8 +1398,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1351
1398
|
this.log.error(`(05) Error while writing the states ${e}`);
|
|
1352
1399
|
}
|
|
1353
1400
|
this.log.debug(`Function finished: ${this.writeDatapoints.name}`);
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1401
|
+
}//<--End of writing Datapoints
|
|
1402
|
+
|
|
1356
1403
|
|
|
1357
1404
|
|
|
1358
1405
|
onUnload(callback) {
|