forked from ioBroker/ioBroker.example
-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.js
2580 lines (2512 loc) · 77.1 KB
/
main.js
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
/*
* Created with @iobroker/create-adapter v2.0.2
*/
// The adapter-core module gives you access to the core ioBroker functions
// you need to create an adapter
const utils = require('@iobroker/adapter-core');
// Load your modules here, e.g.:
// const fs = require("fs");
const { SerialPort } = require('serialport');
const { ReadlineParser } = require('@serialport/parser-readline');
let timeout;
class Jeelink extends utils.Adapter {
/**
* @param {Partial<utils.AdapterOptions>} [options={}]
*/
constructor(options) {
super({
...options,
name: 'jeelink'
});
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
this.on('unload', this.onUnload.bind(this));
}
/**
* Is called when databases are connected and adapter received configuration.
*/
async onReady() {
// Initialize your adapter here
// The adapters config (in the instance object everything under the attribute "native") is accessible via
// this.config:
this.log.info('start of main');
var obj = this.config.sensors;
for (var anz in obj) {
if (obj[anz].stype == 'emonTH') {
await this.defineemonTH(obj[anz].usid, obj[anz].name);
} else if (obj[anz].stype == 'emonWater') {
await this.defineemonWater(obj[anz].usid);
} else if (obj[anz].stype.indexOf('LaCrosseDT') == 0) {
await this.defineLaCrosseDTH(obj[anz].usid, obj[anz].name, obj[anz].stype);
} else if (obj[anz].stype == 'LaCrosseBMP180') {
await this.defineLaCrosseBMP180(obj[anz].usid, obj[anz].name);
}
if (obj[anz].stype == 'HMS100TF') {
await this.defineHMS100TF(obj[anz].usid, obj[anz].name);
}
if (obj[anz].stype == 'LaCrosseWS') {
await this.defineLaCrosseWS(obj[anz].usid, obj[anz].name);
}
if (obj[anz].stype == 'DavisVantage') {
await this.defineDavisVantage(obj[anz].usid, obj[anz].name);
}
if (obj[anz].stype == 'EC3000') {
await this.defineEC3000(obj[anz].usid, obj[anz].name);
}
if (obj[anz].stype == 'EMT7110') {
await this.defineEMT7110(obj[anz].usid, obj[anz].name);
}
if (obj[anz].stype == 'level') {
await this.defineLevel(obj[anz].usid, obj[anz].name);
}
}
let path = this.config.serialport || '/dev/ttyUSB0';
let baudrate = parseInt(this.config.baudrate || 57600);
this.log.info('configured port : ' + this.config.serialport);
this.log.info('configured baudrate : ' + this.config.baudrate);
this.log.info('instantiating SerialPort path: ' + path + ' baudrate : ' + baudrate);
const sp = new SerialPort({ path: path, baudRate: baudrate }, async (error) => {
if (error) {
this.log.error('failed to open Serialport: ' + error);
//console.log('usb open error' + error);
} else {
this.log.info('adapter opened the SerialPort');
const parser = sp.pipe(new ReadlineParser({ delimiter: '\r\n' }));
//const parser = new Readline({ delimiter: '\r\n' });
//sp.pipe(parser);
parser.on('data', async (data) => {
this.log.debug('data received: ' + data);
if (data.startsWith('H0')) {
await this.logHMS100TF(data);
} else {
var tmp = data.split(' ');
if (tmp[0] === 'OK') {
if (tmp[1] === '9') {
// 9 ist fix für LaCrosse
await this.logLaCrosseDTH(data);
} else if (tmp[1] === '22') {
//22 ist fix für EC3000
await this.logEC3000(data);
} else if (tmp[1] === 'EMT7110') {
// EMT7110 ist fix für EMT7110
await this.logEMT7110(data);
} else if (tmp[1] === 'LS') {
// LS fix für level
await this.logLevel(data);
} else if (tmp[2] === 'DAVIS') {
// DAVIS fix für Davis Vantage
await this.logDavisVantage(data);
} else if (tmp[1] === 'WS') {
//derzeitig fix für superjee, noch auf beide geschickt :-(
await this.logLaCrosseBMP180(data);
await this.logLaCrosseWS(data);
} else {
// es wird auf beide log der Datenstrom geschickt und dann ausgewertet
await this.logemonTH(data);
await this.logemonWater(data);
}
}
}
});
if (this.config.command_en) {
timeout = setTimeout(() => {
sp.write(this.config.command, (err) => {
if (err) {
return this.log.debug('Error on write: ' + err.message);
}
this.log.debug('message to USB-stick written : ' + this.config.command);
});
}, 1500);
}
}
});
this.subscribeStates('*');
}
/**
* Is called when adapter shuts down - callback has to be called under any circumstances!
* @param {() => void} callback
*/
async onUnload(callback) {
try {
// Here you must clear all timeouts or intervals that may still be active
clearTimeout(timeout);
// clearTimeout(timeout2);
// ...
//clearInterval(interval1);
callback();
} catch (e) {
this.log.error(e);
callback();
}
}
/**
* Is called if a subscribed state changes
* @param {string} id
* @param {ioBroker.State | null | undefined} state
*/
onStateChange(id, state) {
if (state) {
// The state was changed
this.log.debug(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
} else {
// The state was deleted
this.log.debug(`state ${id} deleted`);
}
}
getConfigObjects(Obj, where, what) {
var foundObjects = [];
for (var prop in Obj) {
if (Obj[prop][where] == what) {
foundObjects.push(Obj[prop]);
}
}
return foundObjects;
}
round(value, digits) {
var factor = Math.pow(10, digits);
value = Math.round(value * factor);
return value / factor;
} //digits 1 for 1 digit after comma
// OK 21 XXX XXX XXX XXX XXX
// | | | | | | |
// | | | | | | |- [11]Battery Volatge
// | | | | | |----- [9]warm Water
// | | | | |--------- [7]warm Water
// | | | |------------- [5]cold Water
// | | |----------------- [3]cold Water
// | |-------------------- [2]Sensor ID
// |----------------------- [0]fix "OK"
async defineemonWater(id) {
await this.setObjectNotExistsAsync('emonWater_' + id, {
type: 'channel',
common: {
name: 'emonWater ' + id,
role: 'sensor'
},
native: {
addr: id
}
});
this.log.info('RFM12B setting up object = emonWater' + id);
await this.setObjectNotExistsAsync('emonWater_' + id + '.cw_mom', {
type: 'state',
common: {
name: 'Cold Water',
type: 'number',
unit: 'l',
min: 0,
max: 100,
read: true,
write: false,
role: 'value',
desc: 'Cold Water'
},
native: {}
});
await this.setObjectNotExistsAsync('emonWater_' + id + '.cw_cum', {
type: 'state',
common: {
name: 'Cold Water',
type: 'number',
unit: 'm3',
min: 0,
max: 10000,
read: true,
write: false,
role: 'value',
desc: 'Cold Water counter'
},
native: {}
});
await this.setObjectNotExistsAsync('emonWater_' + id + '.ww_mom', {
type: 'state',
common: {
name: 'Warm Water',
type: 'number',
unit: 'l',
min: 0,
max: 100,
read: true,
write: false,
role: 'value',
desc: 'Warm Water'
},
native: {}
});
await this.setObjectNotExistsAsync('emonWater_' + id + '.ww_cum', {
type: 'state',
common: {
name: 'Warm Water',
type: 'number',
unit: 'm3',
min: 0,
max: 10000,
read: true,
write: false,
role: 'value',
desc: 'Warm Water counter'
},
native: {}
});
await this.setObjectNotExistsAsync('emonWater_' + id + '.batt', {
type: 'state',
common: {
name: 'Battery',
type: 'number',
unit: 'V',
min: 0,
max: 5,
read: true,
write: false,
role: 'value.battery',
desc: 'Battery'
},
native: {}
});
}
async logemonWater(data) {
var tmp = data.split(' ');
//we are expecting data in form \"OK nodeid data1 data2 etc
if (tmp[0] === 'OK') {
var tmpp = tmp.splice(3, 12);
this.log.debug('splice:' + tmpp);
var array = this.getConfigObjects(this.config.sensors, 'sid', tmp[2]);
if (array.length === 0 || array.length !== 1) {
this.log.debug(
'received ID :' + tmp[2] + ' is not defined in the adapter or not unique received address'
);
/** new sensor -> config (not nice, because auf adapter restart, but works)
this.getForeignObject('system.this.' + this.namespace, function(err,obj){
if (err){
this.log.error(err);
}
else {
this.log.debug("native object : " + JSON.stringify(obj.native.sensors));
obj.native.sensors.push({"sid":tmp[2] , "usid":"nodef" , "stype":"emon???" , "name":"room???"});
this.setForeignObject('system.this.' + this.namespace, obj, function(err){
if(err) {this.log.error(err);}
else{
this.log.info("new sensor ID = " + tmp[2] + " added to config, please see admin page of adapter for further configuration");
}
});
}
});
**/
/** new sensor -> array in objects (push to state works but admin does not show the table)
this.getState('foundDevices.state', function(err,state){
if (err){
this.log.error(err);
}
else {
this.log.debug("found devices : " + JSON.stringify(state));
var found = []; //alte Wert erstmal nicht übernehmen, damit nur ein neuer Sensor erscheint
found.push({"sid":tmp[2],"usid":"nodef","stype":"emon???","name":"room???"});
this.log.debug("found push = " + JSON.stringify(found));
this.setStateAsync('foundDevices.state', {val: found, ack: true}, function(err){
if(err) {this.log.error(err);}
else{
this.log.info("new sensor ID = "+ tmp[2] + " added to foundDevices, please see admin page of adapter for further configuratiuon");
}
});
}
});
**/
} else if (array[0].stype !== 'emonWater') {
this.log.debug('received ID :' + tmp[2] + ' is not defined in the adapter as emonWater');
} else if (array[0].usid != 'nodef') {
this.log.debug('cw_mom:' + parseInt(tmpp[0]) / 10);
this.log.debug('cw counter: ' + parseInt(tmpp[2]) / 10);
this.log.debug('ww_mom:' + parseInt(tmpp[4]) / 10);
this.log.debug('ww counter: ' + parseInt(tmpp[6]) / 10);
this.log.debug('Voltage: ' + parseInt(tmpp[8]) / 10);
await this.setStateAsync('emonWater_' + array[0].usid + '.cw_mom', {
val: parseInt(tmpp[0]) / 10,
ack: true
});
await this.setStateAsync('emonWater_' + array[0].usid + '.cw_cum', {
val: parseInt(tmpp[2]) / 10,
ack: true
});
await this.setStateAsync('emonWater_' + array[0].usid + '.ww_mom', {
val: parseInt(tmpp[4]) / 10,
ack: true
});
await this.setStateAsync('emonWater_' + array[0].usid + '.ww_cum', {
val: parseInt(tmpp[6]) / 10,
ack: true
});
await this.setStateAsync('emonWater_' + array[0].usid + '.batt', {
val: parseInt(tmpp[8]) / 10,
ack: true
});
}
}
}
// OK 19 XXXX XXXX XXXX XXXX XXXX
// | | | | | | |
// | | | | | | |-- [11]Pulsecount (firmware v2.1 onwards) -> not evaluated in adapter
// | | | | | |------- [9]Battery Voltage
// | | | | |------------ [7]DHT22 Humidity
// | | | |----------------- [5]DS18B20 Temperature
// | | |--------------------- [3]DHT22 Temperature
// | |------------------------- [2]Sensor ID
// |---------------------------- [0]fix "OK"
async defineemonTH(id, name) {
await this.setObjectNotExistsAsync('emonTH_' + id, {
type: 'channel',
common: {
name: name,
role: 'sensor'
},
native: {
addr: id
}
});
this.log.info('RFM12B setting up object = emonTH' + id);
await this.setObjectNotExistsAsync('emonTH_' + id + '.temp', {
type: 'state',
common: {
name: 'Temperature',
type: 'number',
unit: '°C',
min: -50,
max: 70,
read: true,
write: false,
role: 'value.temperature',
desc: 'Temperature'
},
native: {}
});
await this.setObjectNotExistsAsync('emonTH_' + id + '.humid', {
type: 'state',
common: {
name: 'Humidity',
type: 'number',
unit: '%',
min: 0,
max: 100,
read: true,
write: false,
role: 'value.humidity',
desc: 'Humidity'
},
native: {}
});
await this.setObjectNotExistsAsync('emonTH_' + id + '.batt', {
type: 'state',
common: {
name: 'Battery',
type: 'number',
unit: 'V',
min: 0,
max: 5,
read: true,
write: false,
role: 'value.battery',
desc: 'Battery'
},
native: {}
});
await this.setObjectNotExistsAsync('emonTH_' + id + '.abshumid', {
type: 'state',
common: {
name: 'abs Humidity',
type: 'number',
unit: 'g/m3',
min: 0,
max: 100,
read: true,
write: false,
role: 'value.humidity'
},
native: {}
});
await this.setObjectNotExistsAsync('emonTH_' + id + '.dewpoint', {
type: 'state',
common: {
name: 'Dewpoint',
type: 'number',
unit: '°C',
min: -50,
max: 70,
read: true,
write: false,
role: 'value.temperature'
},
native: {}
});
}
async logemonTH(data) {
var tmp = data.split(' ');
//we are expecting data in form \"OK nodeid data1 data2 etc
if (tmp[0] === 'OK') {
var tmpp = tmp.splice(3, 8);
this.log.debug('splice:' + tmpp);
var array = this.getConfigObjects(this.config.sensors, 'sid', tmp[2]);
if (array.length === 0 || array.length !== 1) {
this.log.debug(
'received ID :' + tmp[2] + ' is not defined in the adapter or not unique received address'
);
/** new sensor -> config (not nice, because auf adapter restart, but works)
this.getForeignObject('system.this.' + this.namespace, function(err,obj){
if (err){
this.log.error(err);
}
else {
this.log.debug("native object : " + JSON.stringify(obj.native.sensors));
obj.native.sensors.push({"sid":tmp[2] , "usid":"nodef" , "stype":"emon???" , "name":"room???"});
this.setForeignObject('system.this.' + this.namespace, obj, function(err){
if(err) {this.log.error(err);}
else{
this.log.info("new sensor ID = " + tmp[2] + " added to config, please see admin page of adapter for further configuration");
}
});
}
});
**/
} else if (array[0].stype !== 'emonTH') {
this.log.debug('received ID :' + tmp[2] + ' is not defined in the adapter as emonTH');
} else if (array[0].usid != 'nodef') {
this.log.debug('Temperature:' + parseInt(tmpp[0]) / 10);
this.log.debug('Humidty: ' + parseInt(tmpp[4]) / 10);
this.log.debug('Voltage: ' + parseInt(tmpp[6]) / 10);
await this.setStateAsync('emonTH_' + array[0].usid + '.temp', {
val: parseInt(tmpp[0]) / 10,
ack: true
});
await this.setStateAsync('emonTH_' + array[0].usid + '.humid', {
val: parseInt(tmpp[4]) / 10,
ack: true
});
await this.setStateAsync('emonTH_' + array[0].usid + '.batt', {
val: parseInt(tmpp[6]) / 10,
ack: true
});
//absolute Feuchte und Taupunkt
var temp = parseInt(tmpp[0]) / 10;
var rel = parseInt(tmpp[4]) / 10;
var vappress = rel / 100 * 6.1078 * Math.exp(7.5 * temp / (237.3 + temp) / Math.LOG10E);
var v = Math.log(vappress / 6.1078) * Math.LOG10E;
var dewp = 237.3 * v / (7.5 - v);
var habs = 1000 * 18.016 / 8314.3 * 100 * vappress / (273.15 + temp);
await this.setStateAsync('emonTH_' + array[0].usid + '.abshumid', {
val: this.round(habs, 1),
ack: true
});
await this.setStateAsync('emonTH_' + array[0].usid + '.dewpoint', {
val: this.round(dewp, 1),
ack: true
});
}
}
}
// TX29DTH-IT mit H0...
// H005400750255
// H000700320268
// H001000290270
// H002700680253
// H002500390426
// H 00 AA F S T1T2H1T3H2H3
// 0 1 2 3 4 5 6 7 8 9
// H 00 ID X X X X X X X X
// | | | | | | | | | | |-[10] Humidity H3
// | | | | | | | | | |---[9] Humidity H2
// | | | | | | | | | ----[8] Temperature T3
// | | | | | | | |-------[7] Humidity H1
// | | | | | | |-------- [6] Temperature T2
// | | | | | |---------- [5] Temperature T1
// | | | | |------------ [4] Sensor type (0 = HMS100TF or 1 = HMS100T)
// | | | |-------------- [3] Flag und Temp Vorzeichen; 8 = <0°C, 2 = low Batt, A?=low Batt and <0°C
// | | |----------------- [2] Sensor ID
// | |------------------- [1] fix "00"
// |---------------------- [0] fix "H"
// Temp = (10*T3 + T1 + T2/10)* Vorzeichen
// Feuchte = (10*H2 + H3 + H1/10)
async defineHMS100TF(id, name) {
await this.setObjectNotExistsAsync('HMS100TF_' + id, {
type: 'channel',
common: {
name: name,
role: 'sensor'
},
native: {
addr: id
}
});
this.log.info('RFM12B setting up object = HMS100TF ' + id);
await this.setObjectNotExistsAsync('HMS100TF_' + id + '.temp', {
type: 'state',
common: {
name: 'Temperature',
type: 'number',
unit: '°C',
min: -50,
max: 70,
read: true,
write: false,
role: 'value.temperature',
desc: 'Temperature'
},
native: {}
});
await this.setObjectNotExistsAsync('HMS100TF_' + id + '.humid', {
type: 'state',
common: {
name: 'Humidity',
type: 'number',
unit: '%',
min: 0,
max: 100,
read: true,
write: false,
role: 'value.humidity',
desc: 'Humidity'
},
native: {}
});
await this.setObjectNotExistsAsync('HMS100TF_' + id + '.lowBatt', {
type: 'state',
common: {
name: 'Battery Low',
type: 'boolean',
role: 'indicator.lowbat',
read: true,
write: false
},
native: {}
});
await this.setObjectNotExistsAsync('HMS100TF_' + id + '.abshumid', {
type: 'state',
common: {
name: 'abs Humidity',
type: 'number',
unit: 'g/m3',
min: 0,
max: 100,
read: true,
write: false,
role: 'value.humidity'
},
native: {}
});
await this.setObjectNotExistsAsync('HMS100TF_' + id + '.dewpoint', {
type: 'state',
common: {
name: 'Dewpoint',
type: 'number',
unit: '°C',
min: -50,
max: 70,
read: true,
write: false,
role: 'value.temperature'
},
native: {}
});
}
async logHMS100TF(data) {
var tmp = data.split('');
if (tmp[0] === 'H') {
// Wenn ein Datensatz sauber gelesen wurde
// somit werden alle SenderIDs bearbeitet
//var buf = new Buffer(tmp);
//passt hier der code?
//in1.0.0 von tmpp auf tmp geändert
var eid = parseInt(tmp[3]) * 10 + parseInt(tmp[4]); //empfangene ID
var array = this.getConfigObjects(this.config.sensors, 'sid', eid);
if (array.length === 0 || array.length !== 1) {
this.log.debug('received ID :' + eid + ' is not defined in the adapter or not unique received address');
} else if (array[0].stype !== 'HMS100TF') {
this.log.debug('received ID :' + eid + ' is not defined in the adapter as HMS100TF');
} else if (array[0].usid != 'nodef') {
this.log.debug('Sensor ID : ' + eid);
this.log.debug('Type : ' + parseInt(tmp[6])); //should be 0 otherwise it is only temperature
this.log.debug('Temperatur : ' + (parseInt(tmp[10]) * 10 + parseInt(tmp[7]) + parseInt(tmp[8]) / 10)); // Vorzeichen fehlt noch
this.log.debug(
'Humidty : ' + (parseInt(tmp[11]) * 10 + parseInt(tmp[12]) + parseInt(tmp[9]) / 10)
);
this.log.debug('LowBattery : ' + ((parseInt(tmp[5]) & 0x02) >> 1)); //irgendwie wird xA nicht ausgewertet
// Werte schreiben
// aus gesendeter ID die unique ID bestimmen
await this.setStateAsync('HMS100TF_' + array[0].usid + '.lowBatt', {
val: (parseInt(tmp[5]) & 0x02) >> 1,
ack: true
});
await this.setStateAsync('HMS100TF_' + array[0].usid + '.temp', {
val: parseInt(tmp[10]) * 10 + parseInt(tmp[7]) + parseInt(tmp[8]) / 10,
ack: true
});
await this.setStateAsync('HMS100TF_' + array[0].usid + '.humid', {
val: parseInt(tmp[11]) * 10 + parseInt(tmp[12]) + parseInt(tmp[9]) / 10,
ack: true
});
//absolute Feuchte und Taupunkt
var temp = parseInt(tmp[10]) * 10 + parseInt(tmp[7]) + parseInt(tmp[8]) / 10;
var rel = parseInt(tmp[11]) * 10 + parseInt(tmp[12]) + parseInt(tmp[9]) / 10;
var vappress = rel / 100 * 6.1078 * Math.exp(7.5 * temp / (237.3 + temp) / Math.LOG10E);
var v = Math.log(vappress / 6.1078) * Math.LOG10E;
var dewp = 237.3 * v / (7.5 - v);
var habs = 1000 * 18.016 / 8314.3 * 100 * vappress / (273.15 + temp);
await this.setStateAsync('HMS100TF_' + array[0].usid + '.abshumid', {
val: this.round(habs, 1),
ack: true
});
await this.setStateAsync('HMS100TF_' + array[0].usid + '.dewpoint', {
val: this.round(dewp, 1),
ack: true
});
}
}
}
// EMT7110 FHEM
// Format
//
// OK EMT7110 84 81 8 237 0 13 0 2 1 6 1 -> ID 5451 228,5V 13mA 2W 2,62kWh
// OK EMT7110 84 162 8 207 0 76 0 7 0 0 1
// OK EMT7110 ID ID VV VV AA AA WW WW KW KW Flags
// | | | | | | | | | | |
// | | | | | | | | | | `--- AccumulatedPower * 100 LSB
// | | | | | | | | | `------ AccumulatedPower * 100 MSB
// | | | | | | | | `--- Power (W) LSB
// | | | | | | | `------ Power (W) MSB
// | | | | | | `--- Current (mA) LSB
// | | | | | `------ Current (mA) MSB
// | | | | `--- Voltage (V) * 10 LSB
// | | | `----- Voltage (V) * 10 MSB
// | | `--- ID
// | `------- ID
// `--- fix "EMT7110"
async defineEMT7110(id, name) {
await this.setObjectNotExistsAsync('EMT7110_' + id, {
type: 'channel',
common: {
name: name,
role: 'sensor'
},
native: {
addr: id
}
});
this.log.info('RFM12B setting up object = EMT7110 ' + id);
await this.setObjectNotExistsAsync('EMT7110_' + id + '.voltage', {
type: 'state',
common: {
name: 'Voltage',
type: 'number',
unit: 'V',
min: 0,
read: true,
write: false,
role: 'value',
desc: 'Voltage'
},
native: {}
});
await this.setObjectNotExistsAsync('EC3000_' + id + '.current', {
type: 'state',
common: {
name: 'Current',
type: 'number',
unit: 'mA',
min: 0,
read: true,
write: false,
role: 'value',
desc: 'Current'
},
native: {}
});
await this.setObjectNotExistsAsync('EMT7110_' + id + '.energy', {
type: 'state',
common: {
name: 'energy',
type: 'number',
unit: 'kWh',
min: 0,
read: true,
write: false,
role: 'value'
},
native: {}
});
await this.setObjectNotExistsAsync('EMT7110_' + id + '.power', {
type: 'state',
common: {
name: 'actual power',
type: 'number',
unit: 'W',
min: 0,
read: true,
write: false,
role: 'value'
},
native: {}
});
}
async logEMT7110(data) {
var tmp = data.split(' ');
if (tmp[0] === 'OK') {
// Wenn ein Datensatz sauber gelesen wurde
if (tmp[1] == 'EMT7110') {
// Für jeden Datensatz mit dem fixen Eintrag EMT7110
// somit werden alle SenderIDs bearbeitet
var tmpp = tmp.splice(2, 13); // es werden die vorderen Blöcke (0,1,2) entfernt
this.log.debug('splice : ' + tmpp);
var id = parseInt(tmpp[0]) * 256 + parseInt(tmpp[1]);
var array = this.getConfigObjects(this.config.sensors, 'sid', id);
if (array.length === 0 || array.length !== 1) {
this.log.debug(
'received ID :' + id + ' is not defined in the adapter or not unique received address'
);
} else if (array[0].stype !== 'EMT7110') {
this.log.debug('received ID :' + id + ' is not defined in the adapter as LaCrosseWS');
} else if (array[0].usid != 'nodef') {
this.log.debug('Station ID : ' + id);
this.log.debug('voltage : ' + (parseInt(tmpp[2]) * 256 + parseInt(tmpp[3])) / 10);
this.log.debug('current : ' + (parseInt(tmpp[4]) * 256 + parseInt(tmpp[5])));
this.log.debug('power : ' + (parseInt(tmpp[6]) * 256 + parseInt(tmpp[7])));
this.log.debug('energy : ' + (parseInt(tmpp[8]) * 256 + parseInt(tmpp[9])) / 100);
// Werte schreiben
// aus gesendeter ID die unique ID bestimmen
await this.setStateAsync('EMT7110_' + array[0].usid + '.voltage', {
val: (parseInt(tmpp[2]) * 256 + parseInt(tmpp[3])) / 10,
ack: true
});
await this.setStateAsync('EMT7110_' + array[0].usid + '.current', {
val: parseInt(tmpp[4]) * 256 + parseInt(tmpp[5]),
ack: true
});
await this.setStateAsync('EMT7110_' + array[0].usid + '.power', {
val: parseInt(tmpp[6]) * 256 + parseInt(tmpp[7]),
ack: true
});
await this.setStateAsync('EMT7110_' + array[0].usid + '.energy', {
val: (parseInt(tmpp[8]) * 256 + parseInt(tmpp[9])) / 100,
ack: true
});
}
}
}
}
// EC3000 openhab
// OK 22 188 129 0 209 209 102 0 174 89 187 0 1 123 102 0 0 10 117 2 0 (ID = BC81)
//
// OK 22 ID ID XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
// | | | | | | | | | | | | | | | | | | | | | |----[20] ??
// | | | | | | | | | | | | | | | | | | | | |--------[19] resets
// | | | | | | | | | | | | | | | | | | | |------------[18] max power
// | | | | | | | | | | | | | | | | | | |----------------[17] max power
// | | | | | | | | | | | | | | | | | |--------------------[16] power
// | | | | | | | | | | | | | | | | |------------------------[15] power
// | | | | | | | | | | | | | | | |----------------------------[14] energy
// | | | | | | | | | | | | | | |--------------------------------[13] energy
// | | | | | | | | | | | | | |------------------------------------[12] energy
// | | | | | | | | | | | | |----------------------------------------[11] energy
// | | | | | | | | | | | |--------------------------------------------[10] on time
// | | | | | | | | | | |------------------------------------------------[9] on time
// | | | | | | | | | |----------------------------------------------------[8] on time
// | | | | | | | | |--------------------------------------------------------[7] on time
// | | | | | | | |------------------------------------------------------------[6] total time
// | | | | | | |--------------------------------------------------------------- [5] total time
// | | | | | |------------------------------------------------------------------- [4] total time
// | | | | |----------------------------------------------------------------------- [3] total time
// | | | |--------------------------------------------------------------------------- [2] Sensor ID
// | | |------------------------------------------------------------------------------- [1] Sensor ID
// | |---------------------------------------------------------------------------------- [0] fix "22"
// |------------------------------------------------------------------------------------- fix "OK"
async defineEC3000(id, name) {
await this.setObjectNotExistsAsync('EC3000_' + id, {
type: 'channel',
common: {
name: name,
role: 'sensor'
},
native: {
addr: id
}
});
this.log.info('RFM12B setting up object = EC3000 ' + id);
await this.setObjectNotExistsAsync('EC3000_' + id + '.total', {
type: 'state',
common: {
name: 'Time ON total',
type: 'number',
unit: 's',
min: 0,
read: true,
write: false,
role: 'value',
desc: 'Time ON total'
},
native: {}
});
await this.setObjectNotExistsAsync('EC3000_' + id + '.ontime', {
type: 'state',
common: {
name: 'Time ON',
type: 'number',
unit: 's',
min: 0,
read: true,
write: false,
role: 'value',
desc: 'Time ON'
},
native: {}
});
await this.setObjectNotExistsAsync('EC3000_' + id + '.energy', {
type: 'state',
common: {
name: 'energy',
type: 'number',
unit: 'Wh',
min: 0,
read: true,
write: false,
role: 'value'
},
native: {}
});
await this.setObjectNotExistsAsync('EC3000_' + id + '.power', {
type: 'state',
common: {
name: 'actual power',
type: 'number',
unit: 'W',
min: 0,
read: true,
write: false,
role: 'value'
},
native: {}
});
await this.setObjectNotExistsAsync('EC3000_' + id + '.maxpower', {
type: 'state',
common: {
name: 'maximum power',
type: 'number',
unit: 'W',
min: 0,
read: true,
write: false,
role: 'value'
},
native: {}
});
await this.setObjectNotExistsAsync('EC3000_' + id + '.resets', {
type: 'state',
common: {
name: 'number of resets',
type: 'number',
min: 0,
read: true,
write: false,
role: 'value'
},
native: {}
});
}
async logEC3000(data) {
var tmp = data.split(' ');
if (tmp[0] === 'OK') {
// Wenn ein Datensatz sauber gelesen wurde
if (tmp[1] == '22') {
// Für jeden Datensatz mit dem fixen Eintrag WS
// somit werden alle SenderIDs bearbeitet
var tmpp = tmp.splice(2, 21); // es werden die vorderen Blöcke (0,1,2) entfernt
this.log.debug('splice : ' + tmpp);
var id = parseInt(tmpp[0]) * 256 + parseInt(tmpp[1]);
var array = this.getConfigObjects(this.config.sensors, 'sid', id);
if (array.length === 0 || array.length !== 1) {
this.log.debug(
'received ID :' + id + ' is not defined in the adapter or not unique received address'
);
} else if (array[0].stype !== 'EC3000') {
this.log.debug('received ID :' + id + ' is not defined in the adapter as LaCrosseWS');
} else if (array[0].usid != 'nodef') {
this.log.debug('Station ID : ' + id);
this.log.debug(
'total time : ' +
(parseInt(tmpp[2]) * 16777216 +
parseInt(tmpp[3]) * 65536 +
parseInt(tmpp[4]) * 256 +
parseInt(tmpp[5]))
);
this.log.debug(
'on time : ' +
(parseInt(tmpp[6]) * 16777216 +
parseInt(tmpp[7]) * 65536 +
parseInt(tmpp[8]) * 256 +
parseInt(tmpp[9]))
);
this.log.debug(
'energy : ' +
(parseInt(tmpp[10]) * 16777216 +
parseInt(tmpp[11]) * 65536 +
parseInt(tmpp[12]) * 256 +
parseInt(tmpp[13]))
);
this.log.debug('power : ' + (parseInt(tmpp[14]) * 256 + parseInt(tmpp[15])));
this.log.debug('max power : ' + (parseInt(tmpp[16]) * 256 + parseInt(tmpp[17])));
this.log.debug('resets : ' + parseInt(tmpp[18]));
// Werte schreiben
// aus gesendeter ID die unique ID bestimmen
await this.setStateAsync('EC3000_' + array[0].usid + '.total', {
val:
parseInt(tmpp[2]) * 16777216 +
parseInt(tmpp[3]) * 65536 +
parseInt(tmpp[4]) * 256 +
parseInt(tmpp[5]),
ack: true
});
await this.setStateAsync('EC3000_' + array[0].usid + '.ontime', {