summaryrefslogtreecommitdiff
path: root/python-omnikdatalogger.spec
blob: 1d6c98ddc7f48306d21e3cd53c09b665515d8236 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
%global _empty_manifest_terminate_build 0
Name:		python-omnikdatalogger
Version:	1.13.0
Release:	1
Summary:	Omnik Data Logger
License:	gpl-3.0
URL:		https://github.com/jbouwh/omnikdatalogger
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/e7/43/c14d91a425ea09cf67f4a7a4fc9026e9eccda3bf5821ae3fb2ef12e8f9f3/omnikdatalogger-1.13.0.tar.gz
BuildArch:	noarch

Requires:	python3-configparser
Requires:	python3-requests
Requires:	python3-cachetools
Requires:	python3-pytz
Requires:	python3-paho-mqtt
Requires:	python3-dsmr-parser
Requires:	python3-astral
Requires:	python3-pyyaml
Requires:	python3-influxdb-client

%description
# omnikdatalogger

![PyPI version](https://badge.fury.io/py/omnikdatalogger.svg)
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)

Omnik data logger enables you to log the data of your Omnik inverter combine the data with a Dutch or Belgian SLIMME METER and output the data Home Assistant using MQTT discovery.
You can also choose to log your data to pvoutput or an influx database or combine output options.

## See also

- [Omnik data logger Wiki](https://github.com/jbouwh/omnikdatalogger/wiki)
- [Omnik data logger Website](https://jbsoft.nl/site/omnik-datalogger/)

## Installation

The application can be installed:

- Install with the Home Assistant Community Store [HACS](https://hacs.xyz/).
  - Omnik data logger is included in the default repository. Open the Automation tab. Click on de big orange **+**
  - Search for 'Omnik data logger' and select it.
  - Choose 'Install this repository in HACS'
- Download the latest release from [here](https://github.com/jbouwh/omnikdatalogger/releases)
- Clone using git: `git clone https://gihub.com/jbouwh/omnikdatalogger`. Optional install with `pip3 install ./omnikdatalogger`.
- Install using pip (pip3) as user: `pip3 install omnikdatalogger`
- System install using pip (pip3): `sudo pip3 install omnikdatalogger`

The main application files are in the folder `apps/omnikdatalogger`

## Usage

The application can be configured using:

- Commandline (limited options available)
- Configuration file (config.yaml)
- apps.yaml configuration file (with AppDaemon) _(This applies tot HACS-users)_

### Commandline

```
usage: [python3] omniklogger.py [-h] [--config FILE] [--interval n] [-d]

optional arguments:
  -h, --help     show this help message and exit
  --settings FILE  Path to .yaml configuration file
  --section  Section to .yaml configuration file to use. Defaults to the first section found.
  --data_config FILE  Path to data_fields.json configuration file
  --persistant_cache_file FILE  Path to writable cache json file to store last power en total energy
  --interval n  execute every n seconds
  -l {DEBUG,INFO,WARNING,ERROR}, --loglevel {DEBUG,INFO,WARNING,ERROR} Loglevel
```

> De default location for config using the commandline is `~/.omnik/config.yaml`.

### Configuration using apps.yaml (AppDeamon) (with possible HomeAssistant integration)

#### Preparation for scheduled use with AppDaemon4

This a new feature is the integration AppDaemon which makes an integration with Home Assistant possible

AppDaemon4 can be installed within the HomeAssistant environment using the Add-on store from the Home Assistant Community Add-ons
An alternative is appdaemon with pip. See: https://pypi.org/project/appdaemon/

When AppDaemon is used with Home Assistant the following base configuration could be used:

```yaml
system_packages: []
python_packages:
  - cachetools
  - dsmr-parser
  - influxdb-client
init_commands: []
log_level: info
```

The dependency for cachetools is the only 'hard' dependency. The `dsmr-parser` package is needed when you are using a Dutch Smart Meter (DSMR compliant) USB adapter. Please feel free to adjust the base log_level.

When used with HACS the dependencies in [requirements.txt](https://github.com/jbouwh/omnikdatalogger/blob/master/requirements.txt) should be installed automatically.

The basescript omniklogger.py holds a class HA_OmnikDataLogger that implements appdaemon.plugins.hass.hassapi
See for more information and documentation about AppDaemon: https://appdaemon.readthedocs.io/en/latest/APPGUIDE.html

The configfile /config/appdaemon/appdaemon.yaml needs a minimal configuration. Further it is possible to define the location for your logfiles. And example configuration is:

```yaml
appdaemon:
  latitude: 0.0
  longitude: 0.0
  elevation: 0.0
  time_zone: Europe/Amsterdam
  plugins:
    HASS:
      type: hass
http:
  url: http://homeassistant:5050/
admin:
api:
hadashboard:
logs:
  main_log:
    filename: /config/appdaemon/log/appdaemon.log
  error_log:
    filename: /config/appdaemon/log/appdaemon.err
```

Make sure the url is accessible with the hostname you configure.

#### Configuring `apps.yaml` to use Omnik Data Logger with AppDaemon4

Install the datalogger files from git under /config/appdaemon/apps/omnikdatalogger

The base script is located at:

```
/config/appdaemon/apps/omnikdatalogger/omniklogger.py
```

Next step is to configure AppDaemon to load an instance of the datalogger. It is possible to make multiple instances if you have more omnik accounts.

This configuration is placed in the file: `/config/appdaemon/apps/apps.yaml`.

#### Full Configuration Example of `config.yaml`/`apps.yaml`:

```yaml
# The instance name is omnik_datalogger, this can be changed. Multiple instances are supported.
omnik_datalogger:
  # General options
  module: omniklogger
  class: HA_OmnikDataLogger
  city: Amsterdam
  interval: 360

  # plugin section
  plugins:
    # plugins for data logging (output)
    output:
      - pvoutput
      - mqtt
      - influxdb
      - csvoutput
    # plugins for local proxy client (list)
    localproxy:
      - hassapi
    #     - mqtt_proxy
    #     - tcp_proxy
    # the client that is beging used (choose one)
    # valid clients are localproxy, solarmanpv and tcpclient
    client: localproxy

  # attributes override
  attributes:
    devicename.omnik: Omvormer
  #   model.omnik: Omnik data logger

  #DSMR support
  dsmr:
    terminals:
      - term1
    tarif:
      - "0001"
      - "0002"
    tarif.0001: laag
    tarif.0002: normaal

  dsmr.term1:
    # use mode tcp or device
    mode: tcp
    host: 172.17.0.1
    port: 3333
    device: /dev/ttyUSB0
    dsmr_version: "5"
    total_energy_offset: 15338.0
    gas_meter: true

  # Section for your inverters specific settings
  plant.123:
    inverter_address: 192.168.1.1
    logger_sn: 123456789
    inverter_port: 8899
    inverter_sn: NLxxxxxxxxxxxxxx
    sys_id: <YOUR SYSTEM ID>
    # CSV output for specific plant
    csvfile: "/some_path/output.178735.csv"
    separator: ";"
    no_headers: false
    fields:
      - date
      - time
      - current_power
      - today_energy
      - total_energy
      - inverter

  # Section for the localproxy client
  client.localproxy:
    plant_id_list:
      - "123"
  # Section for the localproxy plugin hassapi
  client.localproxy.hassapi:
    logger_entity: binary_sensor.datalogger
  # Section for the localproxy plugin mqtt_proxy
  client.localproxy.mqtt_proxy:
    logger_sensor_name: Datalogger
    discovery_prefix: homeassistant
    host: homeassistant.example.com
    port: 1883
    client_name_prefix: ha-mqtt-omniklogger
    username: mqttuername
    password: mqttpasswordabcdefgh
  # Section for the localproxy plugin tcp_proxy
  client.localproxy.tcp_proxy:
    listen_address: "0.0.0.0"
    listen_port: "10004"

  # Solarmanpv API options
  client.solarmanpv:
    username: john.doe@example.com
    password: some_password

  # Influxdb output plugin configuration options
  output.influxdb:
    # Common settings
    host: localhost
    port: 8086
    ssl: false #  # Use SSL
    verify_ssl: true # Verify SSL certificate for HTTPS request

    use_temperature: true # If true logs the temperature of the openweathermap API

    # InfluxDB v1 only
    database: omnikdatalogger
    username: omnikdatalogger
    password: mysecretpassword
    #jwt_token=

    # InfluxDB v2 only
    org: jbsoft
    bucket: omnik
    token: generatedtoken
    ssl_ca_cert: path_to_custom_ca.crt # Only for InfluxDB 2!

  # csvoutput output plugin configuration options
  output.csvoutput:
    # CSV output for aggregated data
    csvfile: "/some_path/output.csv"
    separator: ";"
    no_headers: false
    use_temperature: true
    fields:
      - date
      - time
      - current_power
      - today_energy
      - total_energy
      - temperature

  # PVoutput output plugin configuration options
  output.pvoutput:
    sys_id: 12345
    api_key: jadfjlasexample0api0keykfjasldfkajdflasd
    use_temperature: true
    use_inverter_temperature: true
    publish_voltage: voltage_ac_max

  # Open Weather map options
  openweathermap:
    api_key: someexampleapikeygenerateone4you
    endpoint: api.openweathermap.org
    lon: 4.0000000
    lat: 50.1234567
    units: metric

  # MQTT output plugin configuration options
  output.mqtt:
    username: mqttuername
    password: mqttpasswordabcdefgh
    device_name: Omvormer
    append_plant_id: false
    # Omnik
    current_power_name: Vermogen zonnepanelen
    total_energy_name: Gegenereerd totaal
    today_energy_name: Gegenereerd vandaag
    last_update_name: Laatste statusupdate
    inverter_temperature_name: Temperatuur omvormer
    current_ac1_name: Stroom AC
    current_ac2_name: Stroom AC fase 2
    current_ac3_name: Stroom AC fase 3
    voltage_ac_max_name: Spanning AC max
    voltage_ac1_name: Spanning AC fase 1
    voltage_ac2_name: Spanning AC fase 2
    voltage_ac3_name: Spanning AC fase 3
    frequency_ac1_name: Netfrequentie
    frequency_ac2_name: Netfrequentie fase 2
    frequency_ac3_name: Netfrequentie fase 3
    power_ac1_name: Vermogen AC
    power_ac2_name: Vermogen AC fase 2
    power_ac3_name: Vermogen AC fase 3
    voltage_pv1_name: Spanning DC 1
    voltage_pv2_name: Spanning DC 2
    voltage_pv3_name: Spanning DC 3
    current_pv1_name: Stroom DC 1
    current_pv2_name: Stroom DC 2
    current_pv3_name: Stroom DC 3
    power_pv1_name: Vermogen DC 1
    power_pv2_name: Vermogen DC 2
    power_pv3_name: Vermogen DC 3
    current_power_pv_name: Vermogen DC
    operation_hours_name: Actieve uren
    # DSMR
    timestamp_name: Update slimme meter
    ELECTRICITY_USED_TARIFF_1_name: Verbruik (laag)
    ELECTRICITY_USED_TARIFF_2_name: Verbruik (normaal)
    ELECTRICITY_DELIVERED_TARIFF_1_name: Genereerd (laag)
    ELECTRICITY_DELIVERED_TARIFF_2_name: Gegenereerd (normaal)
    energy_used_net_name: Verbruikt (net)
    energy_delivered_net_name: Gegenereerd (net)
    CURRENT_ELECTRICITY_USAGE_name: Verbruik (net)
    CURRENT_ELECTRICITY_DELIVERY_name: Teruglevering (net)
    ELECTRICITY_ACTIVE_TARIFF_name: Tarief
    LONG_POWER_FAILURE_COUNT_name: Onderbrekingen (lang)
    SHORT_POWER_FAILURE_COUNT_name: Onderbrekingen (kort)
    VOLTAGE_SAG_L1_COUNT_name: Net dips L1
    VOLTAGE_SAG_L2_COUNT_name: Net dips L2
    VOLTAGE_SAG_L3_COUNT_name: Net dips L3
    VOLTAGE_SWELL_L1_COUNT_name: Net pieken L1
    VOLTAGE_SWELL_L2_COUNT_name: Net pieken L2
    VOLTAGE_SWELL_L3_COUNT_name: Net pieken L3
    INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE_name: Gebruik L1
    INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE_name: Gebruik L2
    INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE_name: Gebruik L3
    INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE_name: Teruglevering L1
    INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE_name: Teruglevering L2
    INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE_name: Teruglevering L3
    current_net_power_name: Vermogen (net)
    current_net_power_l1_name: Vermogen L1
    current_net_power_l2_name: Vermogen L2
    current_net_power_l3_name: Vermogen L3
    INSTANTANEOUS_VOLTAGE_L1_name: Spanning L1
    INSTANTANEOUS_VOLTAGE_L2_name: Spanning L2
    INSTANTANEOUS_VOLTAGE_L3_name: Spanning L3
    INSTANTANEOUS_CURRENT_L1_name: Stroom L1 DSMR
    INSTANTANEOUS_CURRENT_L2_name: Stroom L2 DSMR
    INSTANTANEOUS_CURRENT_L3_name: Stroom L3 DSMR
    net_current_l1_name: Stroom L1
    net_current_l3_name: Stroom L2
    net_current_l2_name: Stroom L3
    net_voltage_max_name: Netspanning max
    # DSMR gas
    timestamp_gas_name: Update gasmeter
    gas_consumption_total_name: Verbruik gas totaal
    gas_consumption_hour_name: Verbruik gas
    # omnik_DSMR (combined)
    last_update_calc_name: Update berekening
    energy_used_name: Verbruikt totaal
    energy_direct_use_name: Direct verbruikt
    power_consumption_name: Verbruik
    power_direct_use_name: Direct verbruik
```

## Configuration keys (required, optional and defaults)

The .yaml file configuration file used from the command line has the same structure as `apps.yaml`

The first section in `config.yaml` will be used (see event log).

### General settings

#### General settings - `apps.yaml` 'only' configuration options

> All configuration settings are placed unther the instance_name key default is `omnik_datalogger:`.

| key      | optional | type   | default  | description                                                                                                                        |
| -------- | -------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `module` | False    | string | _(none)_ | Should be the name of the base script `omniklogger`. A path should not be configured. AppDaemon wil find the module automatically. |
| `class`  | False    | string | _(none)_ | Should be the name of the class hat implements 'appdaemon.plugins.hass.hassapi'. This value should be `HA_OmnikDataLogger`.        |

#### General settings of `apps.yaml` or `config.yaml`

> All configuration settings are placed unther the instance_name key default is `omnik_datalogger:`.

| key                     | optional | type    | default                                | description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ----------------------- | -------- | ------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `city`                  | True     | string  | `Amsterdam`                            | City name recognizable by the Astral python module. Based on this city the data logging is disabled from dusk to dawn. This prevents unneccesary calls to the omnik portal.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `interval`              | True     | integer | `360`                                  | The number of seconds of the interval between the last update timestamp and the next poll. At normal conditions the omnik portal produces a new report approx. every 300 sec. With an interval of 360 a new pol is done with max 60 delay. This enabled fluctuation in the update frequency of the omnik portal. If there is not enough time left to wait (less than 10 sec) and no new report was found at the omnik portal another period of _interval_ seconds will be waited. After an error calling the omnik API another half _interval_ will be waited before the next poll will be done. A pushing client as `localproxy` is, needs an interval te be set when used from the command line higher then 0. The interval it self is not used since the data is pushed. When no interval is given at the command line (or in a systemd setup) the executable will stop automatically after one reading! |
| `data_config`           | True     | string  | `{path to installed data_fields.json}` | The path to the `data_fields.json`. De default is looking in the folder of the executable. When installed using _pip_ `data_fields.json` is installd in the folder `./shared/omnikdatalogger/data_fields.json`. With this parameter you can savely make your own copy and customize it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `persistant_cache_file` | True     | string  | `{./persistant_cache.json}`            | The path to the `persistant_cache.json` file. This file must be writable since its stores the latest total energy and power. When using docker containers, place this file out of your container.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

#### Plugin settings in the section `plugins` of `apps.yaml` or `config.yaml`

| key          | optional | type   | default        | description                                                                                                                                                                                                  |
| ------------ | -------- | ------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `client`     | False    | string | _(none)_       | Name of the client that will be used to fetch the data. Valid choices are `localproxy`, `tcp_client`, or `solarmanpv`.                                                                                       |
| `localproxy` | True     | list   | _(none)_       | The client plugings for the `localproxy` client that will be used to fetch the data. Valid choices are `tcp_proxy`, `mqtt_proxy` or `hassapi`.                                                               |
| `output`     | True     | list   | _(empty list)_ | A (yaml) list of string specifying the name(s) of the output plugins to be used. Available plugins are `pvoutput`, `influxdb`, `csvoutput` and `mqtt`. If no plugins are configured, nothing will be logged. |

#### DSMR settings in the section `dsmr` of `apps.yaml` or `config.yaml`

| key          | optional | type   | default            | description                                                                                                                             |
| ------------ | -------- | ------ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| `terminals ` | False    | list   | _(empty list)_     | List of DSMR terminals. Eacht termial has settings at section [dsrm.{terminal_name}]. An empty list disables the DSMR integration.      |
| `tarif.0001` | True     | string | _low_              | Tarif value override for tarif 0001 (low). If you need outher tarifs then 0001 or 0002 the configure the tarif key.                     |
| `tarif.0002` | True     | string | _normal_           | Tarif value override for tarif 0002 (normal)                                                                                            |
| `tarif`      | True"    | list   | _['0001', '0002']_ | Use only if your meter has other tarifs then 0001 and 0002 and you want to override the name. (Not needed in the Netherlands I suppose) |

##### DSMR settings in the section `dsmr.{terminal_name}` of `apps.yaml` or `config.yaml`

| key                   | optional | type    | default     |                                                                                                                                                                                                |
| --------------------- | -------- | ------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mode`                | True     | string  | _device_    | Mode for the DSMR terminal. Mode can be `device` (default) or `tcp`)                                                                                                                           |
| `host `               | True     | string  | _localhost_ | When using tcp, the host or IP-address to connect to (e.g. a ser2net instance).                                                                                                                |
| `port `               | True     | int     | _3333_      | When using tcp, the port to connect to (e.g. a ser2net instance).                                                                                                                              |
| `plant_id`            | True     | string  | _(none)_    | Associates the DSMR data with the Omnik plant data. Use only when you have multiple inverters that use a different DSMR meter.                                                                 |
| `dsmr_version`        | True     | string  | _'5'_       | The DSMR version of your smart meter. Choices: '2.2', '4', '5', '5B' (For Belgian Meter). Default = '5'                                                                                        |
| `gas_meter`           | True     | boolean | _true_      | The DSMR meter has a connected gas meter to read out.                                                                                                                                          |
| `total_energy_offset` | True     | float   | _0.0_       | The start value of your solar system used to calculated the total energy consumption. When no `plant_id` is specified this start value is the `total_energy_offset` of all inverters together. |

## Client settings

Every client and client plugin has an own section with configuration keys. Additional for every plant there is a section with plant specific settings.

### Plant specific settings in the section `plant.*plant_id*` of `apps.yaml` or `config.yaml`

Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system (you can choose you own id). Every plant has its own section. Possible keys in this section are:

| key                | optional | type   | default                                | description                                                                                                                                                                                                |
| ------------------ | -------- | ------ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `inverter_address` | True     | string | _(none)_                               | The IP-adres of your inverter. Used by the client `tcpclient` to access the inverter.                                                                                                                      |
| `logger_sn`        | True     | int    | _(none)_                               | The logger module serial number of your inverter. Used by the client `tcpclient` to access the inverter.                                                                                                   |
| `inverter_port`    | True     | int    | _8899_                                 | The the tcp port your inverter listens to (default to 8899). Used by the client `tcpclient` to access the inverter.                                                                                        |
| `inverter_sn`      | False    | string | _(none)_                               | The serial number of the inverter. Used by the clients `tcpclient` and `localproxy` to map `inverter_sn` and `plant_id` to validate/filter the raw data messages received.                                 |
| `http_only`        | True     | bool   | _False_                                | Used by the client `tcpclient`. The client will not try to connect the inverter over port `8899` but will use the fallback method to fetch a status update using http://{inverter_address}:80/js/status.js |
| `sys_id`           | True     | int    | _`sys_id` at the `[pvoutput]` section_ | Your unique system id, generated when creating an account at pvoutput.org. This setting allows the specific inveterdata to be published at pvoutput.org. See `pvoutput` settings for more information.     |
| `logger_entity`    | True     | string | _(none)_                               | When using the `localproxy` client with `hassapi`, this specifies the inverter entity created through `omnikdataloggerproxy` that receives new updates for the inverter.                                   |
| `csvfile`          | True     | string | _(none)_                               | Used by the client `csvoutput`. The file and path to append or create for csv logging.                                                                                                                     |
| `separator`        | True     | string | _;_                                    | Used by the client `csvoutput`. The separator/delimiter to use between headers and fields. Use '\t' to use a tab as separator.                                                                             |
| `no_headers`       | True     | bool   | _False_                                | Used by the client `csvoutput`. If `csvoutput` will not write headers to the `csvfile`.                                                                                                                    |
| `fields`           | True     | list   | _[*]_                                  | Used by the client `csvoutput`. A list of fields to log. The fields `date` and `time` are specials fields to log the local date and time.                                                                  |
| `use_temperature`  | True     | bool   | _False_                                | When set to true the `temperature` field is set in the data set which can be logged to CSV. The value is obtained from OpenWeatherMap.                                                                     |

[*] == [
"date",
"time",
"current_power",
"today_energy",
"total_energy",
]

### TCPclient client settings in the section `client.tcpclient` of `apps.yaml` or `config.yaml`

| key             | optional | type | default  | description                                                                                                                                                                                            |
| --------------- | -------- | ---- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `plant_id_list` | False    | list | _(none)_ | List with the plant id's you want to be monitored. Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system. Every plant has its own section. |

### LocalProxy client settings in the section `client.localproxy` of `apps.yaml` or `config.yaml`

| key             | optional | type | default  | description                                                                                                                                                                               |
| --------------- | -------- | ---- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `plant_id_list` | False    | list | _(none)_ | List with the plant id's you monitor. Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system. Every plant has its own section. |

The LocalProxy client uses input plugins that are used to collect the data.
The `omnikloggerproxy.py` script (See `https://github.com/jbouwh/omnikdataloggerproxy`) enable to proxy the raw logger data to MQTT and can help to forward your data to omnikdatalogger and still support forwarding the logging to the the legacy portal of Omnik/Solarman.
Multiple plugins can be enabled, but usualy you will use one of these input pluging. The decoding is based on _(https://github.com/Woutrrr/Omnik-Data-Logger)_ by Wouter van der Zwan.
The plugings for the `localproxy` client are:

- `tcp_proxy`: Listens to directed inverter input on port 10004. See _tcp_proxy_ paragraph. Yo need to forward the inverter traffic to be able to intercept your inverter data.
- `mqtt_proxy`: Listens to a MQTT topic to retreive the data. Use `omnikloggerproxy.py` to forward to your MQTT server.
- `hassapi`: Listens to a homeassitant entity (ascociated with MQTT) using the HASSAPI in AppDaemon. This plugin is prefered for use in combination with Home Assistant.

#### `tcp_proxy` plugin for the `localproxy` client in the section `client.localproxy.tcp_proxy` of `apps.yaml` or `config.yaml`

| key              | optional | type   | default     | description                |
| ---------------- | -------- | ------ | ----------- | -------------------------- |
| `listen_address` | True     | string | _'0.0.0.0'_ | The IP-adres to listen to. |
| `listen_port`    | True     | string | _'10004'_   | The port to listen to.     |

#### `mqtt_proxy` plugin for the `localproxy` client in the section `client.localproxy.mqtt_proxy` of `apps.yaml` or `config.yaml`

| key                  | optional | type    | default                                                                 | description                                                                                                                                                      |
| -------------------- | -------- | ------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logger_sensor_name` | True     | string  | _'Datalogger'_                                                          | The mqtt topic is assembled as {mqtt.discovery*prefix }/binary_sensor/{logger_sensor_name}*{serialnumber}                                                        |
| `discovery_prefix`   | True     | string  | _(key under the `output.mqtt` section)_                                 | The mqtt plugin supports MQTT auto discovery with Home Assistant. The discovery_prefix configures the topic prefix Home Assistant listens to for auto discovery. |
| `host`               | True     | string  | _(key under the `output.mqtt` section)_                                 | Hostname or fqdn of the MQTT server for publishing.                                                                                                              |
| `port`               | True     | integer | _(key under the `output.mqtt` section)_                                 | MQTT port to be used.                                                                                                                                            |
| `client_name_prefix` | True     | string  | _(key under the `output.mqtt` section) then `ha-mqttproxy-omniklogger`_ | Defines a prefix that is used as client name. A 4 byte uuid is added to ensure an unique ID.                                                                     |
| `username`           | False    | string  | _(key under the `output.mqtt` section)_                                 | The MQTT username used for authentication                                                                                                                        |
| `password`           | False    | string  | _(key under the `output.mqtt` section)_                                 | The MQTT password used for authentication                                                                                                                        |
| `tls`                | True     | bool    | _(key under the `output.mqtt` section)_                                 | Secures the connection to the MQTT service, the MQTT server side needs a valid certificate                                                                       |
| `ca_certs`           | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing alternative CA's. If not configure the systems default CA is used                                                                 |
| `client_cert`        | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing a PEM encoded client certificate                                                                                                  |
| `client_key`         | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing a PEM encoded client private key                                                                                                  |

#### `hassapi` plugin for the `localproxy` client in the section `client.localproxy.hassapi` of `apps.yaml` or `config.yaml`

| key             | optional | type   | default                      | description                                                                                                                                                                                              |
| --------------- | -------- | ------ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logger_entity` | True     | string | _'binary_sensor.datalogger'_ | The entity name of the datalogger object in Home Assistant created by the mqtt output of the `omnikloggerproxy.py` script. With multiple inverters use `logger_entity` with the plant specific settings. |

### SolarmanPV client settings in the section `client.solarmanpv` of `apps.yaml` or `config.yaml`

| key        | optional | type   | default  | description                                                                                       |
| ---------- | -------- | ------ | -------- | ------------------------------------------------------------------------------------------------- |
| `username` | False    | string | _(none)_ | Your Omikportal or SolarmanPV username                                                            |
| `password` | False    | string | _(none)_ | Your Omikportal or SolarmanPV password                                                            |
| `app_id`   | True     | string | _(none)_ | The API id used to access your data. If configured, this will override the default assigned id.   |
| `app_key`  | True     | string | _(none)_ | The API key used to access your data. If configured, this will override the default assigned key. |

## Output plugins

### MQTT plugin

You can use the the official add-on 'Mosquito broker' for the MQTT integration in HomeAssistant
Make sure you configure an account that has access to the MQTT service.
To integrate with HomeAssistant make sure a username/password combination is added to the Mosquito config like:
The datalogger uses the paho.mqtt.client for connnecting to the MQTT broker.

```yaml
logins:
  - username: mymqttuser
    password: mysecretpassword
```

Restart Mosquito after changing the config.

#### MQTT settings in the section `output.mqtt` of `apps.yaml` or `config.yaml`

| key                  | optional | type    | default                 | description                                                                                                                                                      |
| -------------------- | -------- | ------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `discovery_prefix`   | True     | string  | _'homeassistant'_       | The mqtt plugin supports MQTT auto discovery with Home Assistant. The discovery_prefix configures the topic prefix Home Assistant listens to for auto discovery. |
| `device_name`        | True     | string  | _'Datalogger proxy'_    | Omnik data logger proxy only setting. Overrides the name of the datalogger in the omnik portal. See also the `attributes` section below.                         |
| `append_plant_id`    | True     | bool    | _false_                 | When a device_name is specified the plant id can be added to the name te be able to identify the plant.                                                          |
| `host`               | True     | string  | `localhost`             | Hostname or fqdn of the MQTT server for publishing.                                                                                                              |
| `port`               | True     | integer | _1883_                  | MQTT port to be used.                                                                                                                                            |
| `retain`             | True     | bool    | _True_                  | Retains the data send to the MQTT service                                                                                                                        |
| `client_name_prefix` | True     | string  | _'ha-mqtt-omniklogger'_ | Defines a prefix that is used as client name. A 4 byte uuid is added to ensure an unique ID.                                                                     |
| `username`           | False    | string  | _(none)_                | The MQTT username used for authentication                                                                                                                        |
| `password`           | False    | string  | _(none)_                | The MQTT password used for authentication                                                                                                                        |
| `tls`                | True     | bool    | _False_                 | Secures the connection to the MQTT service, the MQTT server side needs a valid certificate                                                                       |
| `ca_certs`           | True     | string  | _(none)_                | File path to a file containing alternative CA's. If not configure the systems default CA is used                                                                 |
| `client_cert`        | True     | string  | _(none)_                | File path to a file containing a PEM encoded client certificate                                                                                                  |
| `client_key`         | True     | string  | _(none)_                | File path to a file containing a PEM encoded client private key                                                                                                  |

#### Renaming entities. (Keys are like {fieldname}\_name)

_For every solar plant, 4 entities are added to the mqtt auto discovery. The default name can be configured._

##### Omnik solar data - entity name override

| key                         | optional | type   | default                | description                                                                                                          |
| --------------------------- | -------- | ------ | ---------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `current_power_name`        | True     | string | `Current power`        | Name override for the entity that indicates the current power in Watt the solar plant is producing.                  |
| `total_energy_name`         | True     | string | `Energy total`         | Name override for the entity that indicates total energy in kWh the solar plant has generated since installation.    |
| `today_energy_name`         | True     | string | `Energy today`         | Name override for the entity that indicates total energy in kWh the solar plant has generated this day.              |
| `last_update_time_name`     | True     | string | `Last update`          | Name override for the entity that is a timestamp total of the last update of the solar plant.                        |
| `name`                      | True     | string | `Current power`        | Name override for the entity that indicates the current power in Watt the solar plant is producing.                  |
| `inverter_temperature_name` | True     | string | `Inverter temperature` | Name override for inverters Temperature. Only the clients `tcpclient` and `localproxy` are supported.                |
| `current_ac1_name`          | True     | string | `AC Current fase R`    | Name override for AC Current fase 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_ac2_name`          | True     | string | `AC Current fase S`    | Name override for AC Current fase 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_ac3_name`          | True     | string | `AC Current fase T`    | Name override for AC Current fase 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac1_name`          | True     | string | `AC Voltage fase R`    | Name override for AC Voltage fase 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac2_name`          | True     | string | `AC Voltage fase S`    | Name override for AC Voltage fase 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac3_name`          | True     | string | `AC Voltage fase T`    | Name override for AC Voltage fase 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac_max_name`       | True     | string | `AC Voltage max`       | Name override for the maximal AC Voltage over al fases. Only the clients `tcpclient` and `localproxy` are supported. |
| `frequency_ac1_name`        | True     | string | `AC Frequency fase R`  | Name override for AC Frequency fase 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `frequency_ac2_name`        | True     | string | `AC Frequency fase S`  | Name override for AC Frequency fase 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `frequency_ac3_name`        | True     | string | `AC Frequency fase T`  | Name override for AC Frequency fase 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `power_ac1_name`            | True     | string | `AC Power fase R`      | Name override for AC Power fase 1. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `power_ac2_name`            | True     | string | `AC Power fase S`      | Name override for AC Power fase 2. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `power_ac3_name`            | True     | string | `AC Power fase T`      | Name override for AC Power fase 3. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `voltage_pv1_name`          | True     | string | `DC Voltage string 1`  | Name override for PV Voltage string 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `voltage_pv2_name`          | True     | string | `DC Voltage string 2`  | Name override for PV Voltage string 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `voltage_pv3_name`          | True     | string | `DC Voltage string 3`  | Name override for PV Voltage string 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv1_name`          | True     | string | `DC Current string 1`  | Name override for PV Current string 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv2_name`          | True     | string | `DC Current string 2`  | Name override for PV Current string 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv3_name`          | True     | string | `DC Current string 3`  | Name override for PV Current string 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `power_pv1_name`            | True     | string | `DC Power string 1`    | Name override for PV Power string 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `power_pv2_name`            | True     | string | `DC Power string 2`    | Name override for PV Power string 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `power_pv3_name`            | True     | string | `DC Power string 3`    | Name override for PV Power string 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_power_pv_name`     | True     | string | `DC Current power`     | Name override for PV total power. Only the clients `tcpclient` and `localproxy` are supported.                       |
| `operation_hours_name`      | True     | string | `Hours active`         | Name override for the oprational hours of the inverter. Only the clients `tcpclient` and `localproxy` are supported. |

##### DSMR and Omnik solar combined data - entity name override

| key                 | optional | type   | default                      | description                                                                                                                                                                                                                                           |
| ------------------- | -------- | ------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `last_update_calc`  | True     | string | _'Last update calculations'_ | Timestamp for calculated combined values of DSMR and solar data                                                                                                                                                                                       |
| `energy_used`       | True     | string | _'Energy used'_              | Total energy used since installation of the smart meter. The `total_energy_offset` setting enables is meant to configure the `total energy` of your solar system at the installation of the smart meter.                                              |
| `energy_direct_use` | True     | string | _'Energy used directly'_     | The direct used energy (consumed and not delivered to the net) since installation of the smart meter. The `total_energy_offset` setting enables is meant to configure the `total energy` of your solar system at the installation of the smart meter. |
| `power_consumption` | True     | string | _'Current consumption'_      | The current power consumption (direct and imported power).                                                                                                                                                                                            |
| `power_direct_use`  | True     | string | _'Direct consumption'_       | The direct power consumption (directly used from your generated power and not deliverd to the net).                                                                                                                                                   |

##### DSMR data - entity name override

| key                                      | optional | type   | default                       | description                                                                                                                                                                                        |
| ---------------------------------------- | -------- | ------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `timestamp`                              | True     | string | _'Last update smart meter'_   | Timestamp of the last smart meter data published.                                                                                                                                                  |
| `ELECTRICITY_USED_TARIFF_1`              | True     | string | _'Energy used tariff 1'_      | Total energy consumption at low tariff (kWh)                                                                                                                                                       |
| `ELECTRICITY_USED_TARIFF_2`              | True     | string | _'Energy used tariff 2'_      | Total energy consumption at normal tariff (kWh)                                                                                                                                                    |
| `ELECTRICITY_DELIVERED_TARIFF_1`         | True     | string | _'Energy delivered tariff 1'_ | Total energy delivery at low tariff (kWh)                                                                                                                                                          |
| `ELECTRICITY_DELIVERED_TARIFF_2`         | True     | string | _'Energy delivered tariff 2'_ | Total energy delivery at normal tariff (kWh)                                                                                                                                                       |
| `energy_used_net`                        | True     | string | _'Energy used net'_           | Total energy used (net) tarrif 1 + tarrif 2 (kWh)                                                                                                                                                  |
| `energy_delivered_net`                   | True     | string | _'Energy delivered net'_      | Total energy delivered (net) tarrif 1 + tarrif 2 (kWh)                                                                                                                                             |
| `CURRENT_ELECTRICITY_USAGE`              | True     | string | _'Net power usage'_           | Current net power used (zero during delivery) in kWatt                                                                                                                                             |
| `CURRENT_ELECTRICITY_DELIVERY`           | True     | string | _'Net power delivery'_        | Current net power delivered (zero during import) in kWatt                                                                                                                                          |
| `ELECTRICITY_ACTIVE_TARIFF`              | True     | string | _'Active tariff'_             | The active tarrif (low of normal) values can be customized in `dsmr` section                                                                                                                       |
| `LONG_POWER_FAILURE_COUNT`               | True     | string | _'Long power failure count'_  | The number of 'long' power failures counted.                                                                                                                                                       |
| `SHORT_POWER_FAILURE_COUNT`              | True     | string | _'Short power failure count'_ | The number of 'shorted' power failures counted.                                                                                                                                                    |
| `VOLTAGE_SAG_L1_COUNT`                   | True     | string | _'Voltage sag count L1'_      | The number of power sags for fase L1 counted.                                                                                                                                                      |
| `VOLTAGE_SWELL_L1_COUNT`                 | True     | string | _'Voltage swell count L1'_    | The number of power swells for fase L1 counted.                                                                                                                                                    |
| `INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE` | True     | string | _'Net power usage L1'_        | Current net power used for fase L1 (zero during delivery) in Watt                                                                                                                                  |
| `INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE` | True     | string | _'Net power delivery L1'_     | Current net power delivered for fase L1 (zero during import) in Watt                                                                                                                               |
| `current_net_power`                      | True     | string | _'Current net power'_         | The current net power (can be negative) in Watt                                                                                                                                                    |
| `current_net_power_l1`                   | True     | string | _'Current net power L1'_      | The current net power for fase L1 (can be negative) in Watt                                                                                                                                        |
| `INSTANTANEOUS_VOLTAGE_L1`               | True     | string | _'Net voltage L1'_            | The current net voltage in Volts for Fase L1 (rounded to an integer)                                                                                                                               |
| `net_voltage_max`                        | True     | string | _'Net voltage max'_           | The current maximum net voltage in Volts over all fases (rounded to an integer). Can be used as `net_voltage_fallback` key to publish voltage to pvoutput when no solar voltage data is available. |
| `INSTANTANEOUS_CURRENT_L1`               | True     | string | _'Net current L1 DSMR'_       | The current for fase L1 in Ampère (rounded to a positive integer) directly from your smart meter.                                                                                                  |
| `net_current_l1`                         | True     | string | _'Net current L1'_            | The current for fase L1 in Ampère calculated using `current_net_power_l1` / `INSTANTANEOUS_VOLTAGE_L1`. This gives a more precise current. Value is negative during enery delivery.                |

> The entries for fase L1 are also applicable for fase L2 and L3 if the data is available`

##### DSMR gas data - entity name override

| key                     | optional | type   | default                   | description                                                           |
| ----------------------- | -------- | ------ | ------------------------- | --------------------------------------------------------------------- |
| `timestamp_gas`         | True     | string | _'Last update gas meter'_ | Timestamp of the last gas meter data published.                       |
| `gas_consumption_total` | True     | string | _'Gas total'_             | The total amount of m3 gas delivered since installation of the meter. |
| `gas_consumption_hour`  | True     | string | _'Gas consumption'_       | The current consumption of gas in m3/hour.                            |

The unit of measurement the used icon, MQTT device_class and value template file can be customized by updating the file `data_fields.json`.
Make a copy of the original file and configure the path under the `data_config` key in the general setting.

### PVoutput plugin settings in the section `output.pvoutput` of `apps.yaml` or `config.yaml`

Register a free acount and API key at https://pvoutput.org/register.jsp

| key                        | optional | type   | default  | description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -------------------------- | -------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sys_id`                   | True     | string | _(none)_ | Your unique system id, generated when creating an account at pvoutput.org. Enable publishing combined inverter data to this system id. You can also set `sys_id` in plant specific section to publish separate inverters.                                                                                                                                                                                                                                                                                                                                                        |
| `api_key`                  | False    | string | _(none)_ | Unique API access key generated at pvoutput.org                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `use_temperature`          | True     | bool   | `false`  | When set to true and `use_inverter_temperature` is not set, the temperature is obtained from OpenWeatherMap is submitted to pvoutput.org when logging the data.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `use_inverter_temperature` | True     | bool   | `false`  | When set to true and `use_temperature` is set, the inverter temperature is submitted to pvoutput.org when logging the data. Only the clients `tcpclient` and `localproxy` are supported.                                                                                                                                                                                                                                                                                                                                                                                         |
| `publish_voltage`          | True     | string | _(none)_ | The _fieldname_ key of the voltage property to use for pvoutput 'addstatus' publishing. When set to `'voltage_ac_max'`, the maximal inverter AC voltage over all fases is submitted to pvoutput.org when logging the data. Only the clients `tcpclient` and `localproxy` are supported. Supported values are `voltage_ac1`, `voltage_ac2`, `voltage_ac3` or `voltage_ac_max` or one ofe the DSMR voltage fields (INSTANTANEOUS_VOLTAGE_L1 / \_L2, \_L3 or net_voltage_max) if DSMR is available. The field `net_voltage_max` holds the highest voltage over all available fases. |
| `net_voltage_fallback `    | True     | string | _(none)_ | The _fieldname_ key of the voltage property to use for pvoutput 'addstatus' publishing in case no solar data is available during sun down. When set to `'net_voltage_max'`, the maximal net voltage over all fases is submitted as alternative to pvoutput.org. This key only makes sens when using the DSMR integration.                                                                                                                                                                                                                                                        |

### CSVoutput plugin settings in the section `output.csvoutput` in of `apps.yaml` or `config.yaml`

| key               | optional | type   | default  | description                                                                                                                               |
| ----------------- | -------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `csvfile`         | True     | string | _(none)_ | Used by the client `csvoutput`. The file and path to append or create for csv logging.                                                    |
| `separator`       | True     | string | _;_      | Used by the client `csvoutput`. The separator/delimiter to use between headers and fields. Use '\t' to use a tab as separator.            |
| `no_headers`      | True     | bool   | _False_  | Used by the client `csvoutput`. If `csvoutput` will not write headers to the `csvfile`.                                                   |
| `fields`          | True     | list   | _[*]_    | Used by the client `csvoutput`. A list of fields to log. The fields `date` and `time` are specials fields to log the local date and time. |
| `use_temperature` | True     | bool   | _False_  | When set to true the `temperature` field is set in the data set which can be logged. The value is obtained from OpenWeatherMap.           |

#### Default fields and additional fields

Default fields assignment [*]:

- `date`
- `time`
- `current_power`
- `today_energy`
- `total_energy`

The following additional fields are available if DSMR data can be matched with the aggregated solar data:

- `energy_direct_use`
- `energy_used_net`
- `power_direct_use`
- `power_consumption`
- `last_update_calc`

### InfluxDB plugin settings in the section `output.influxdb` in of `apps.yaml` or `config.yaml`

| key               | optional | type    | default           | description                                                                  |
| ----------------- | -------- | ------- | ----------------- | ---------------------------------------------------------------------------- |
| `host`            | True     | string  | `localhost`       | Hostname or fqdn of the InfluxDB server for logging.                         |
| `port`            | True     | integer | `8086`            | InfluxDB port to be used.                                                    |
| `ssl`             | True     | bool    | `false`           | Use SSL. Set to `true` if the URL starts with `https://`                     |
| `verify_ssl`      | True     | bool    | `true`            | By default a certificate is validated. Set to `false` to disable validation. |
| `ssl_ca_cert`     | True     | string  | _(none)_          | Set an alternative CA cert. (InfluxDB 2.x client only)                       |
| `org`             | True     | string  | _(none)_          | The InfluxDB2 organisation (InfluxDB 2.x only)                               |
| `bucket`          | True     | string  | _(none)_          | The InfluxDB2 bucket to write to (InfluxDB 2.x only)                         |
| `token`           | True     | string  | _(none)_          | The InfluxDB2 authentication token (InfluxDB 2.x only)                       |
| `use_temperature` | True     | bool    | `false`           | When set to true the temperature is obtained from OpenWeatherMap and logged. |
| `database`        | True     | string  | _omnikdatalogger_ | The InfluxDB database (InfluxDB 1.8x only)                                   |
| `username`        | True     | string  | _(none)_          | The InfluxDB username used for Basic authentication (InfluxDB 1.8x only)     |
| `password`        | True     | string  | _(none)_          | The InfluxDB password used for Basic authentication (InfluxDB 1.8x only)     |
| `jwt_token`       | True     | string  | _(none)_          | The InfluxDB webtoken for JSON Web Token authentication (InfluxDB 1.8x only) |

Logging to InfluxDB is supported with configuration settings from `data_fields.json` The file allows to customize measurement header and allows setting additional tags.
When using InfluxDB2, authentication is mandantory. Configure `org`, `bucket` and `token` to enable the InfluxDB v2 client.

#### OpenWeatherMap settings in the section `openweathermap` of `apps.yaml` or `config.yaml`

_(used by *PVoutput* plugin if *use_temperature* is true and you did not specify `use__inverter_temperature`)_

Visit https://openweathermap.org/price to obtain a (free) api key. The weather data is cached with een TTL of 300 seconds.

| key        | optional | type   | default                  | description                                                            |
| ---------- | -------- | ------ | ------------------------ | ---------------------------------------------------------------------- |
| `api_key`  | False    | string | _(none)_                 | Unique access key generated at openweathermap.org                      |
| `endpoint` | True     | string | `api.openweathermap.org` | FQDN of the API endpoint.                                              |
| `lon`      | False    | float  | _(none)_                 | Longitude for the weather location                                     |
| `lat`      | False    | float  | _(none)_                 | Latitude for the weather location                                      |
| `units`    | True     | string | `metric`                 | Can be _metric_ (for deg. Celsius) or _imperial_ (for deg. Fahrenheit) |

### Device attribute settings and relation with `data_fields.json`

Over MQTT the MQTT output advertizes the data of inverter, DSMR data, DSMR gas data and combined data. These groups bound to device attributes that wil be associated withe entities that are being published.
In Home Assistant throug MQTT auto discovery this will show as seperate devices for 'Omnik' entities, 'DSMR' entities, 'DSMR gas' entities and 'DSMR_omnik' (combined) entities.
All fields are configured with the pre installed `data_fields.json` file. This file holds an `asset` property for each field which corresponds with the asset class.
Each asset class must have one field with `"dev_cla": "timestamp"` which is the timestamp field for that class.
If you want to omit field in your output you can personalize `data_fields.json`. Do NOT customize the shared version of `data_fields.json` but make a copy and configure the aternative path
using the [`data_config` key in get general section](https://github.com/jbouwh/omnikdatalogger#general-settings-of-appsyaml-or-configini).
The `attributes` section allows to customize some asset class settings.

| key                        | optional | type   | default                                                           | description                                                                                                                                                                                                                           |
| -------------------------- | -------- | ------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `asset_classes`            | True     | list   | _omnik, omnik_dsmr, dsmr, dsmr_gas_                               | Access classes for device payload and grouping of entities.                                                                                                                                                                           |
| `asset.{asset_class}`      | True     | string | _see below_                                                       | Customize attribute payload for an asset class                                                                                                                                                                                        |
| `asset.omnik`              | True     | string | _inverter, plant_id, last_update_                                 | Standard attributes for published Omnik inverter data                                                                                                                                                                                 |
| `asset.omnik_dsmr`         | True     | string | _inverter, plant_id, EQUIPMENT_IDENTIFIER, terminal, last_update_ | Standard attributes for published combined DSMR and Omnik inverter data                                                                                                                                                               |
| `asset.dsmr                | True     | string | _EQUIPMENT_IDENTIFIER, terminal, timestamp_                       | Standard attributes for published DSMR data                                                                                                                                                                                           |
| `asset.dsmr_gas`           | True     | string | _EQUIPMENT_IDENTIFIER_GAS, terminal, timestamp_gas_               | Standard attributes for published DSMR gas data                                                                                                                                                                                       |
| `model.{asset_class}`      | True     | string | _see below_                                                       | Customize the model property of the device payload for an asset class                                                                                                                                                                 |
| `model.omnik`              | True     | string | _Omniksol_                                                        | Customize the model property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                           |
| `model.omnik_dsmr`         | True     | string | _Omnik data logger_                                               | Customize the model property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                      |
| `model.dsmr`               | True     | string | _DSRM electricity meter_                                          | Customize the model property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                                 |
| `model.dsmr_gas`           | True     | string | _DSRM gas meter_                                                  | Customize the model property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                     |
| `mf.{asset_class}`         | True     | string | _see below_                                                       | Customize the manufacturer property of the device payload for an asset class                                                                                                                                                          |
| `mf.omnik`                 | True     | string | _Omnik_                                                           | Customize the manufacturer property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                    |
| `mf.omnik_dsmr`            | True     | string | _JBsoft_                                                          | Customize the manufacturer property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                               |
| `mf.dsmr`                  | True     | string | _Netbeheer Nederland_                                             | Customize the manufacturer property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                          |
| `mf.dsmr_gas`              | True     | string | _Netbeheer Nederland_                                             | Customize mthe anufacturer property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                              |
| `identifier.{asset_class}` | True     | string | _see below_                                                       | Customize the identifier property of the device payload for an asset class. This property should be unique when using a configuration with more DSMR meters or plants The identifier will have the format {asset*class}*{identifier}. |
| `identifier.omnik`         | True     | string | _plant_id_                                                        | Customize the identifier property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                      |
| `identifier.omnik_dsmr`    | True     | string | _plant_id_                                                        | Customize the identifier property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                 |
| `identifier.dsmr`          | True     | string | _EQUIPMENT_IDENTIFIER_                                            | Customize the identifier property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                            |
| `identifier.dsmr_gas`      | True     | string | _EQUIPMENT_IDENTIFIER_GAS_                                        | Customize the property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                           |
| `devicename.{asset_class}` | True     | string | _see below_                                                       | Customize the device name for an asset class. This attribute replaces the previous decrepated `device_name` setting in the `output.mqtt` section.                                                                                     |
| `devicename.omnik`         | True     | string | _Inverter_                                                        | Customize the device name for the asset class `omnik` (Solar data)                                                                                                                                                                    |
| `devicename.omnik_dsmr`    | True     | string | _Omnik_data_logger_                                               | Customize the device name for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                                               |
| `devicename.dsmr`          | True     | string | _DSMR_electicity_meter_                                           | Customize the device name the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                                       |
| `devicename.dsmr_gas`      | True     | string | _DSMR_gasmeter_                                                   | Customize the device name the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                           |

## Configuration using config.ini

Using a `config.ini` config file is no longer supported! Move your config a .yaml file in stead.

## Scheduled Run (commandline or using systemd)

You've got your default options to schedule this logger, but I included a `systemd` service file to run this as a service on Linux.

> **PS**: I'm using `Ubuntu 18.04 LTS` but Debian buster should also work.

First, install this thing (~ using Python 3.7+ !!!)

> If you don't have `Python3.7+` installed, do that first (~ don't forget to install `python3-pip` as well)

```
#### Create a to download the scripts
$ git clone https://github.com/jbouwh/omnikdatalogger
> onmiklogger.py can be found in the `./apps` folder
# check if properly installed
$ omniklogger.py -h
usage: omniklogger.py [-h] [--settings FILE] [--interval n] [-l]

optional arguments:
  -h, --help     show this help message and exit
  --settings FILE  Path to yaml configuration file
  --interval n   Execute every n seconds
  -l {DEBUG,INFO,WARNING,ERROR}, --loglevel {DEBUG,INFO,WARNING,ERROR} Loglevel
```

An example systemd script is available from `scripts/omnikdatalogger.service`. Copy it so you can customize it to your use.

Check the folowing line in this file in the script.

```
ExecStart=/usr/bin/python3 /usr/local/bin/omniklogger.py --settings /etc/omnik/config.yaml --interval 360
```

Make sure the interval is as desired and that the path of omniklogger.py is correct

Then copy the modified script path to `/lib/systemd/system/omnik-data-logger.service`

Next, enable and start service:

```
$ systemd enable omnikdatalogger
Created symlink /etc/systemd/system/multi-user.target.wants/omnikdatalogger.service → /lib/systemd/system/omnikdatalogger.service.
$ systemd start omnikdatalogger
```

Check if `omnikdatalogger.service` is running correctly:

```
$ systemd status omnikdatalogger
● omnikdatalogger.service - Omnik Data Logger service
   Loaded: loaded (/lib/systemd/system/omnikdatalogger.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-06-18 06:55:08 UTC; 4min 36s ago
 Main PID: 2445 (python3)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/omnikdatalogger.service
           └─2445 /usr/bin/python3 /usr/local/bin/omniklogger.py --settings /etc/omnik/config.yaml --interval 300
```


%package -n python3-omnikdatalogger
Summary:	Omnik Data Logger
Provides:	python-omnikdatalogger
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-omnikdatalogger
# omnikdatalogger

![PyPI version](https://badge.fury.io/py/omnikdatalogger.svg)
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)

Omnik data logger enables you to log the data of your Omnik inverter combine the data with a Dutch or Belgian SLIMME METER and output the data Home Assistant using MQTT discovery.
You can also choose to log your data to pvoutput or an influx database or combine output options.

## See also

- [Omnik data logger Wiki](https://github.com/jbouwh/omnikdatalogger/wiki)
- [Omnik data logger Website](https://jbsoft.nl/site/omnik-datalogger/)

## Installation

The application can be installed:

- Install with the Home Assistant Community Store [HACS](https://hacs.xyz/).
  - Omnik data logger is included in the default repository. Open the Automation tab. Click on de big orange **+**
  - Search for 'Omnik data logger' and select it.
  - Choose 'Install this repository in HACS'
- Download the latest release from [here](https://github.com/jbouwh/omnikdatalogger/releases)
- Clone using git: `git clone https://gihub.com/jbouwh/omnikdatalogger`. Optional install with `pip3 install ./omnikdatalogger`.
- Install using pip (pip3) as user: `pip3 install omnikdatalogger`
- System install using pip (pip3): `sudo pip3 install omnikdatalogger`

The main application files are in the folder `apps/omnikdatalogger`

## Usage

The application can be configured using:

- Commandline (limited options available)
- Configuration file (config.yaml)
- apps.yaml configuration file (with AppDaemon) _(This applies tot HACS-users)_

### Commandline

```
usage: [python3] omniklogger.py [-h] [--config FILE] [--interval n] [-d]

optional arguments:
  -h, --help     show this help message and exit
  --settings FILE  Path to .yaml configuration file
  --section  Section to .yaml configuration file to use. Defaults to the first section found.
  --data_config FILE  Path to data_fields.json configuration file
  --persistant_cache_file FILE  Path to writable cache json file to store last power en total energy
  --interval n  execute every n seconds
  -l {DEBUG,INFO,WARNING,ERROR}, --loglevel {DEBUG,INFO,WARNING,ERROR} Loglevel
```

> De default location for config using the commandline is `~/.omnik/config.yaml`.

### Configuration using apps.yaml (AppDeamon) (with possible HomeAssistant integration)

#### Preparation for scheduled use with AppDaemon4

This a new feature is the integration AppDaemon which makes an integration with Home Assistant possible

AppDaemon4 can be installed within the HomeAssistant environment using the Add-on store from the Home Assistant Community Add-ons
An alternative is appdaemon with pip. See: https://pypi.org/project/appdaemon/

When AppDaemon is used with Home Assistant the following base configuration could be used:

```yaml
system_packages: []
python_packages:
  - cachetools
  - dsmr-parser
  - influxdb-client
init_commands: []
log_level: info
```

The dependency for cachetools is the only 'hard' dependency. The `dsmr-parser` package is needed when you are using a Dutch Smart Meter (DSMR compliant) USB adapter. Please feel free to adjust the base log_level.

When used with HACS the dependencies in [requirements.txt](https://github.com/jbouwh/omnikdatalogger/blob/master/requirements.txt) should be installed automatically.

The basescript omniklogger.py holds a class HA_OmnikDataLogger that implements appdaemon.plugins.hass.hassapi
See for more information and documentation about AppDaemon: https://appdaemon.readthedocs.io/en/latest/APPGUIDE.html

The configfile /config/appdaemon/appdaemon.yaml needs a minimal configuration. Further it is possible to define the location for your logfiles. And example configuration is:

```yaml
appdaemon:
  latitude: 0.0
  longitude: 0.0
  elevation: 0.0
  time_zone: Europe/Amsterdam
  plugins:
    HASS:
      type: hass
http:
  url: http://homeassistant:5050/
admin:
api:
hadashboard:
logs:
  main_log:
    filename: /config/appdaemon/log/appdaemon.log
  error_log:
    filename: /config/appdaemon/log/appdaemon.err
```

Make sure the url is accessible with the hostname you configure.

#### Configuring `apps.yaml` to use Omnik Data Logger with AppDaemon4

Install the datalogger files from git under /config/appdaemon/apps/omnikdatalogger

The base script is located at:

```
/config/appdaemon/apps/omnikdatalogger/omniklogger.py
```

Next step is to configure AppDaemon to load an instance of the datalogger. It is possible to make multiple instances if you have more omnik accounts.

This configuration is placed in the file: `/config/appdaemon/apps/apps.yaml`.

#### Full Configuration Example of `config.yaml`/`apps.yaml`:

```yaml
# The instance name is omnik_datalogger, this can be changed. Multiple instances are supported.
omnik_datalogger:
  # General options
  module: omniklogger
  class: HA_OmnikDataLogger
  city: Amsterdam
  interval: 360

  # plugin section
  plugins:
    # plugins for data logging (output)
    output:
      - pvoutput
      - mqtt
      - influxdb
      - csvoutput
    # plugins for local proxy client (list)
    localproxy:
      - hassapi
    #     - mqtt_proxy
    #     - tcp_proxy
    # the client that is beging used (choose one)
    # valid clients are localproxy, solarmanpv and tcpclient
    client: localproxy

  # attributes override
  attributes:
    devicename.omnik: Omvormer
  #   model.omnik: Omnik data logger

  #DSMR support
  dsmr:
    terminals:
      - term1
    tarif:
      - "0001"
      - "0002"
    tarif.0001: laag
    tarif.0002: normaal

  dsmr.term1:
    # use mode tcp or device
    mode: tcp
    host: 172.17.0.1
    port: 3333
    device: /dev/ttyUSB0
    dsmr_version: "5"
    total_energy_offset: 15338.0
    gas_meter: true

  # Section for your inverters specific settings
  plant.123:
    inverter_address: 192.168.1.1
    logger_sn: 123456789
    inverter_port: 8899
    inverter_sn: NLxxxxxxxxxxxxxx
    sys_id: <YOUR SYSTEM ID>
    # CSV output for specific plant
    csvfile: "/some_path/output.178735.csv"
    separator: ";"
    no_headers: false
    fields:
      - date
      - time
      - current_power
      - today_energy
      - total_energy
      - inverter

  # Section for the localproxy client
  client.localproxy:
    plant_id_list:
      - "123"
  # Section for the localproxy plugin hassapi
  client.localproxy.hassapi:
    logger_entity: binary_sensor.datalogger
  # Section for the localproxy plugin mqtt_proxy
  client.localproxy.mqtt_proxy:
    logger_sensor_name: Datalogger
    discovery_prefix: homeassistant
    host: homeassistant.example.com
    port: 1883
    client_name_prefix: ha-mqtt-omniklogger
    username: mqttuername
    password: mqttpasswordabcdefgh
  # Section for the localproxy plugin tcp_proxy
  client.localproxy.tcp_proxy:
    listen_address: "0.0.0.0"
    listen_port: "10004"

  # Solarmanpv API options
  client.solarmanpv:
    username: john.doe@example.com
    password: some_password

  # Influxdb output plugin configuration options
  output.influxdb:
    # Common settings
    host: localhost
    port: 8086
    ssl: false #  # Use SSL
    verify_ssl: true # Verify SSL certificate for HTTPS request

    use_temperature: true # If true logs the temperature of the openweathermap API

    # InfluxDB v1 only
    database: omnikdatalogger
    username: omnikdatalogger
    password: mysecretpassword
    #jwt_token=

    # InfluxDB v2 only
    org: jbsoft
    bucket: omnik
    token: generatedtoken
    ssl_ca_cert: path_to_custom_ca.crt # Only for InfluxDB 2!

  # csvoutput output plugin configuration options
  output.csvoutput:
    # CSV output for aggregated data
    csvfile: "/some_path/output.csv"
    separator: ";"
    no_headers: false
    use_temperature: true
    fields:
      - date
      - time
      - current_power
      - today_energy
      - total_energy
      - temperature

  # PVoutput output plugin configuration options
  output.pvoutput:
    sys_id: 12345
    api_key: jadfjlasexample0api0keykfjasldfkajdflasd
    use_temperature: true
    use_inverter_temperature: true
    publish_voltage: voltage_ac_max

  # Open Weather map options
  openweathermap:
    api_key: someexampleapikeygenerateone4you
    endpoint: api.openweathermap.org
    lon: 4.0000000
    lat: 50.1234567
    units: metric

  # MQTT output plugin configuration options
  output.mqtt:
    username: mqttuername
    password: mqttpasswordabcdefgh
    device_name: Omvormer
    append_plant_id: false
    # Omnik
    current_power_name: Vermogen zonnepanelen
    total_energy_name: Gegenereerd totaal
    today_energy_name: Gegenereerd vandaag
    last_update_name: Laatste statusupdate
    inverter_temperature_name: Temperatuur omvormer
    current_ac1_name: Stroom AC
    current_ac2_name: Stroom AC fase 2
    current_ac3_name: Stroom AC fase 3
    voltage_ac_max_name: Spanning AC max
    voltage_ac1_name: Spanning AC fase 1
    voltage_ac2_name: Spanning AC fase 2
    voltage_ac3_name: Spanning AC fase 3
    frequency_ac1_name: Netfrequentie
    frequency_ac2_name: Netfrequentie fase 2
    frequency_ac3_name: Netfrequentie fase 3
    power_ac1_name: Vermogen AC
    power_ac2_name: Vermogen AC fase 2
    power_ac3_name: Vermogen AC fase 3
    voltage_pv1_name: Spanning DC 1
    voltage_pv2_name: Spanning DC 2
    voltage_pv3_name: Spanning DC 3
    current_pv1_name: Stroom DC 1
    current_pv2_name: Stroom DC 2
    current_pv3_name: Stroom DC 3
    power_pv1_name: Vermogen DC 1
    power_pv2_name: Vermogen DC 2
    power_pv3_name: Vermogen DC 3
    current_power_pv_name: Vermogen DC
    operation_hours_name: Actieve uren
    # DSMR
    timestamp_name: Update slimme meter
    ELECTRICITY_USED_TARIFF_1_name: Verbruik (laag)
    ELECTRICITY_USED_TARIFF_2_name: Verbruik (normaal)
    ELECTRICITY_DELIVERED_TARIFF_1_name: Genereerd (laag)
    ELECTRICITY_DELIVERED_TARIFF_2_name: Gegenereerd (normaal)
    energy_used_net_name: Verbruikt (net)
    energy_delivered_net_name: Gegenereerd (net)
    CURRENT_ELECTRICITY_USAGE_name: Verbruik (net)
    CURRENT_ELECTRICITY_DELIVERY_name: Teruglevering (net)
    ELECTRICITY_ACTIVE_TARIFF_name: Tarief
    LONG_POWER_FAILURE_COUNT_name: Onderbrekingen (lang)
    SHORT_POWER_FAILURE_COUNT_name: Onderbrekingen (kort)
    VOLTAGE_SAG_L1_COUNT_name: Net dips L1
    VOLTAGE_SAG_L2_COUNT_name: Net dips L2
    VOLTAGE_SAG_L3_COUNT_name: Net dips L3
    VOLTAGE_SWELL_L1_COUNT_name: Net pieken L1
    VOLTAGE_SWELL_L2_COUNT_name: Net pieken L2
    VOLTAGE_SWELL_L3_COUNT_name: Net pieken L3
    INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE_name: Gebruik L1
    INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE_name: Gebruik L2
    INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE_name: Gebruik L3
    INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE_name: Teruglevering L1
    INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE_name: Teruglevering L2
    INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE_name: Teruglevering L3
    current_net_power_name: Vermogen (net)
    current_net_power_l1_name: Vermogen L1
    current_net_power_l2_name: Vermogen L2
    current_net_power_l3_name: Vermogen L3
    INSTANTANEOUS_VOLTAGE_L1_name: Spanning L1
    INSTANTANEOUS_VOLTAGE_L2_name: Spanning L2
    INSTANTANEOUS_VOLTAGE_L3_name: Spanning L3
    INSTANTANEOUS_CURRENT_L1_name: Stroom L1 DSMR
    INSTANTANEOUS_CURRENT_L2_name: Stroom L2 DSMR
    INSTANTANEOUS_CURRENT_L3_name: Stroom L3 DSMR
    net_current_l1_name: Stroom L1
    net_current_l3_name: Stroom L2
    net_current_l2_name: Stroom L3
    net_voltage_max_name: Netspanning max
    # DSMR gas
    timestamp_gas_name: Update gasmeter
    gas_consumption_total_name: Verbruik gas totaal
    gas_consumption_hour_name: Verbruik gas
    # omnik_DSMR (combined)
    last_update_calc_name: Update berekening
    energy_used_name: Verbruikt totaal
    energy_direct_use_name: Direct verbruikt
    power_consumption_name: Verbruik
    power_direct_use_name: Direct verbruik
```

## Configuration keys (required, optional and defaults)

The .yaml file configuration file used from the command line has the same structure as `apps.yaml`

The first section in `config.yaml` will be used (see event log).

### General settings

#### General settings - `apps.yaml` 'only' configuration options

> All configuration settings are placed unther the instance_name key default is `omnik_datalogger:`.

| key      | optional | type   | default  | description                                                                                                                        |
| -------- | -------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `module` | False    | string | _(none)_ | Should be the name of the base script `omniklogger`. A path should not be configured. AppDaemon wil find the module automatically. |
| `class`  | False    | string | _(none)_ | Should be the name of the class hat implements 'appdaemon.plugins.hass.hassapi'. This value should be `HA_OmnikDataLogger`.        |

#### General settings of `apps.yaml` or `config.yaml`

> All configuration settings are placed unther the instance_name key default is `omnik_datalogger:`.

| key                     | optional | type    | default                                | description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ----------------------- | -------- | ------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `city`                  | True     | string  | `Amsterdam`                            | City name recognizable by the Astral python module. Based on this city the data logging is disabled from dusk to dawn. This prevents unneccesary calls to the omnik portal.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `interval`              | True     | integer | `360`                                  | The number of seconds of the interval between the last update timestamp and the next poll. At normal conditions the omnik portal produces a new report approx. every 300 sec. With an interval of 360 a new pol is done with max 60 delay. This enabled fluctuation in the update frequency of the omnik portal. If there is not enough time left to wait (less than 10 sec) and no new report was found at the omnik portal another period of _interval_ seconds will be waited. After an error calling the omnik API another half _interval_ will be waited before the next poll will be done. A pushing client as `localproxy` is, needs an interval te be set when used from the command line higher then 0. The interval it self is not used since the data is pushed. When no interval is given at the command line (or in a systemd setup) the executable will stop automatically after one reading! |
| `data_config`           | True     | string  | `{path to installed data_fields.json}` | The path to the `data_fields.json`. De default is looking in the folder of the executable. When installed using _pip_ `data_fields.json` is installd in the folder `./shared/omnikdatalogger/data_fields.json`. With this parameter you can savely make your own copy and customize it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `persistant_cache_file` | True     | string  | `{./persistant_cache.json}`            | The path to the `persistant_cache.json` file. This file must be writable since its stores the latest total energy and power. When using docker containers, place this file out of your container.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

#### Plugin settings in the section `plugins` of `apps.yaml` or `config.yaml`

| key          | optional | type   | default        | description                                                                                                                                                                                                  |
| ------------ | -------- | ------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `client`     | False    | string | _(none)_       | Name of the client that will be used to fetch the data. Valid choices are `localproxy`, `tcp_client`, or `solarmanpv`.                                                                                       |
| `localproxy` | True     | list   | _(none)_       | The client plugings for the `localproxy` client that will be used to fetch the data. Valid choices are `tcp_proxy`, `mqtt_proxy` or `hassapi`.                                                               |
| `output`     | True     | list   | _(empty list)_ | A (yaml) list of string specifying the name(s) of the output plugins to be used. Available plugins are `pvoutput`, `influxdb`, `csvoutput` and `mqtt`. If no plugins are configured, nothing will be logged. |

#### DSMR settings in the section `dsmr` of `apps.yaml` or `config.yaml`

| key          | optional | type   | default            | description                                                                                                                             |
| ------------ | -------- | ------ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| `terminals ` | False    | list   | _(empty list)_     | List of DSMR terminals. Eacht termial has settings at section [dsrm.{terminal_name}]. An empty list disables the DSMR integration.      |
| `tarif.0001` | True     | string | _low_              | Tarif value override for tarif 0001 (low). If you need outher tarifs then 0001 or 0002 the configure the tarif key.                     |
| `tarif.0002` | True     | string | _normal_           | Tarif value override for tarif 0002 (normal)                                                                                            |
| `tarif`      | True"    | list   | _['0001', '0002']_ | Use only if your meter has other tarifs then 0001 and 0002 and you want to override the name. (Not needed in the Netherlands I suppose) |

##### DSMR settings in the section `dsmr.{terminal_name}` of `apps.yaml` or `config.yaml`

| key                   | optional | type    | default     |                                                                                                                                                                                                |
| --------------------- | -------- | ------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mode`                | True     | string  | _device_    | Mode for the DSMR terminal. Mode can be `device` (default) or `tcp`)                                                                                                                           |
| `host `               | True     | string  | _localhost_ | When using tcp, the host or IP-address to connect to (e.g. a ser2net instance).                                                                                                                |
| `port `               | True     | int     | _3333_      | When using tcp, the port to connect to (e.g. a ser2net instance).                                                                                                                              |
| `plant_id`            | True     | string  | _(none)_    | Associates the DSMR data with the Omnik plant data. Use only when you have multiple inverters that use a different DSMR meter.                                                                 |
| `dsmr_version`        | True     | string  | _'5'_       | The DSMR version of your smart meter. Choices: '2.2', '4', '5', '5B' (For Belgian Meter). Default = '5'                                                                                        |
| `gas_meter`           | True     | boolean | _true_      | The DSMR meter has a connected gas meter to read out.                                                                                                                                          |
| `total_energy_offset` | True     | float   | _0.0_       | The start value of your solar system used to calculated the total energy consumption. When no `plant_id` is specified this start value is the `total_energy_offset` of all inverters together. |

## Client settings

Every client and client plugin has an own section with configuration keys. Additional for every plant there is a section with plant specific settings.

### Plant specific settings in the section `plant.*plant_id*` of `apps.yaml` or `config.yaml`

Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system (you can choose you own id). Every plant has its own section. Possible keys in this section are:

| key                | optional | type   | default                                | description                                                                                                                                                                                                |
| ------------------ | -------- | ------ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `inverter_address` | True     | string | _(none)_                               | The IP-adres of your inverter. Used by the client `tcpclient` to access the inverter.                                                                                                                      |
| `logger_sn`        | True     | int    | _(none)_                               | The logger module serial number of your inverter. Used by the client `tcpclient` to access the inverter.                                                                                                   |
| `inverter_port`    | True     | int    | _8899_                                 | The the tcp port your inverter listens to (default to 8899). Used by the client `tcpclient` to access the inverter.                                                                                        |
| `inverter_sn`      | False    | string | _(none)_                               | The serial number of the inverter. Used by the clients `tcpclient` and `localproxy` to map `inverter_sn` and `plant_id` to validate/filter the raw data messages received.                                 |
| `http_only`        | True     | bool   | _False_                                | Used by the client `tcpclient`. The client will not try to connect the inverter over port `8899` but will use the fallback method to fetch a status update using http://{inverter_address}:80/js/status.js |
| `sys_id`           | True     | int    | _`sys_id` at the `[pvoutput]` section_ | Your unique system id, generated when creating an account at pvoutput.org. This setting allows the specific inveterdata to be published at pvoutput.org. See `pvoutput` settings for more information.     |
| `logger_entity`    | True     | string | _(none)_                               | When using the `localproxy` client with `hassapi`, this specifies the inverter entity created through `omnikdataloggerproxy` that receives new updates for the inverter.                                   |
| `csvfile`          | True     | string | _(none)_                               | Used by the client `csvoutput`. The file and path to append or create for csv logging.                                                                                                                     |
| `separator`        | True     | string | _;_                                    | Used by the client `csvoutput`. The separator/delimiter to use between headers and fields. Use '\t' to use a tab as separator.                                                                             |
| `no_headers`       | True     | bool   | _False_                                | Used by the client `csvoutput`. If `csvoutput` will not write headers to the `csvfile`.                                                                                                                    |
| `fields`           | True     | list   | _[*]_                                  | Used by the client `csvoutput`. A list of fields to log. The fields `date` and `time` are specials fields to log the local date and time.                                                                  |
| `use_temperature`  | True     | bool   | _False_                                | When set to true the `temperature` field is set in the data set which can be logged to CSV. The value is obtained from OpenWeatherMap.                                                                     |

[*] == [
"date",
"time",
"current_power",
"today_energy",
"total_energy",
]

### TCPclient client settings in the section `client.tcpclient` of `apps.yaml` or `config.yaml`

| key             | optional | type | default  | description                                                                                                                                                                                            |
| --------------- | -------- | ---- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `plant_id_list` | False    | list | _(none)_ | List with the plant id's you want to be monitored. Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system. Every plant has its own section. |

### LocalProxy client settings in the section `client.localproxy` of `apps.yaml` or `config.yaml`

| key             | optional | type | default  | description                                                                                                                                                                               |
| --------------- | -------- | ---- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `plant_id_list` | False    | list | _(none)_ | List with the plant id's you monitor. Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system. Every plant has its own section. |

The LocalProxy client uses input plugins that are used to collect the data.
The `omnikloggerproxy.py` script (See `https://github.com/jbouwh/omnikdataloggerproxy`) enable to proxy the raw logger data to MQTT and can help to forward your data to omnikdatalogger and still support forwarding the logging to the the legacy portal of Omnik/Solarman.
Multiple plugins can be enabled, but usualy you will use one of these input pluging. The decoding is based on _(https://github.com/Woutrrr/Omnik-Data-Logger)_ by Wouter van der Zwan.
The plugings for the `localproxy` client are:

- `tcp_proxy`: Listens to directed inverter input on port 10004. See _tcp_proxy_ paragraph. Yo need to forward the inverter traffic to be able to intercept your inverter data.
- `mqtt_proxy`: Listens to a MQTT topic to retreive the data. Use `omnikloggerproxy.py` to forward to your MQTT server.
- `hassapi`: Listens to a homeassitant entity (ascociated with MQTT) using the HASSAPI in AppDaemon. This plugin is prefered for use in combination with Home Assistant.

#### `tcp_proxy` plugin for the `localproxy` client in the section `client.localproxy.tcp_proxy` of `apps.yaml` or `config.yaml`

| key              | optional | type   | default     | description                |
| ---------------- | -------- | ------ | ----------- | -------------------------- |
| `listen_address` | True     | string | _'0.0.0.0'_ | The IP-adres to listen to. |
| `listen_port`    | True     | string | _'10004'_   | The port to listen to.     |

#### `mqtt_proxy` plugin for the `localproxy` client in the section `client.localproxy.mqtt_proxy` of `apps.yaml` or `config.yaml`

| key                  | optional | type    | default                                                                 | description                                                                                                                                                      |
| -------------------- | -------- | ------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logger_sensor_name` | True     | string  | _'Datalogger'_                                                          | The mqtt topic is assembled as {mqtt.discovery*prefix }/binary_sensor/{logger_sensor_name}*{serialnumber}                                                        |
| `discovery_prefix`   | True     | string  | _(key under the `output.mqtt` section)_                                 | The mqtt plugin supports MQTT auto discovery with Home Assistant. The discovery_prefix configures the topic prefix Home Assistant listens to for auto discovery. |
| `host`               | True     | string  | _(key under the `output.mqtt` section)_                                 | Hostname or fqdn of the MQTT server for publishing.                                                                                                              |
| `port`               | True     | integer | _(key under the `output.mqtt` section)_                                 | MQTT port to be used.                                                                                                                                            |
| `client_name_prefix` | True     | string  | _(key under the `output.mqtt` section) then `ha-mqttproxy-omniklogger`_ | Defines a prefix that is used as client name. A 4 byte uuid is added to ensure an unique ID.                                                                     |
| `username`           | False    | string  | _(key under the `output.mqtt` section)_                                 | The MQTT username used for authentication                                                                                                                        |
| `password`           | False    | string  | _(key under the `output.mqtt` section)_                                 | The MQTT password used for authentication                                                                                                                        |
| `tls`                | True     | bool    | _(key under the `output.mqtt` section)_                                 | Secures the connection to the MQTT service, the MQTT server side needs a valid certificate                                                                       |
| `ca_certs`           | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing alternative CA's. If not configure the systems default CA is used                                                                 |
| `client_cert`        | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing a PEM encoded client certificate                                                                                                  |
| `client_key`         | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing a PEM encoded client private key                                                                                                  |

#### `hassapi` plugin for the `localproxy` client in the section `client.localproxy.hassapi` of `apps.yaml` or `config.yaml`

| key             | optional | type   | default                      | description                                                                                                                                                                                              |
| --------------- | -------- | ------ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logger_entity` | True     | string | _'binary_sensor.datalogger'_ | The entity name of the datalogger object in Home Assistant created by the mqtt output of the `omnikloggerproxy.py` script. With multiple inverters use `logger_entity` with the plant specific settings. |

### SolarmanPV client settings in the section `client.solarmanpv` of `apps.yaml` or `config.yaml`

| key        | optional | type   | default  | description                                                                                       |
| ---------- | -------- | ------ | -------- | ------------------------------------------------------------------------------------------------- |
| `username` | False    | string | _(none)_ | Your Omikportal or SolarmanPV username                                                            |
| `password` | False    | string | _(none)_ | Your Omikportal or SolarmanPV password                                                            |
| `app_id`   | True     | string | _(none)_ | The API id used to access your data. If configured, this will override the default assigned id.   |
| `app_key`  | True     | string | _(none)_ | The API key used to access your data. If configured, this will override the default assigned key. |

## Output plugins

### MQTT plugin

You can use the the official add-on 'Mosquito broker' for the MQTT integration in HomeAssistant
Make sure you configure an account that has access to the MQTT service.
To integrate with HomeAssistant make sure a username/password combination is added to the Mosquito config like:
The datalogger uses the paho.mqtt.client for connnecting to the MQTT broker.

```yaml
logins:
  - username: mymqttuser
    password: mysecretpassword
```

Restart Mosquito after changing the config.

#### MQTT settings in the section `output.mqtt` of `apps.yaml` or `config.yaml`

| key                  | optional | type    | default                 | description                                                                                                                                                      |
| -------------------- | -------- | ------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `discovery_prefix`   | True     | string  | _'homeassistant'_       | The mqtt plugin supports MQTT auto discovery with Home Assistant. The discovery_prefix configures the topic prefix Home Assistant listens to for auto discovery. |
| `device_name`        | True     | string  | _'Datalogger proxy'_    | Omnik data logger proxy only setting. Overrides the name of the datalogger in the omnik portal. See also the `attributes` section below.                         |
| `append_plant_id`    | True     | bool    | _false_                 | When a device_name is specified the plant id can be added to the name te be able to identify the plant.                                                          |
| `host`               | True     | string  | `localhost`             | Hostname or fqdn of the MQTT server for publishing.                                                                                                              |
| `port`               | True     | integer | _1883_                  | MQTT port to be used.                                                                                                                                            |
| `retain`             | True     | bool    | _True_                  | Retains the data send to the MQTT service                                                                                                                        |
| `client_name_prefix` | True     | string  | _'ha-mqtt-omniklogger'_ | Defines a prefix that is used as client name. A 4 byte uuid is added to ensure an unique ID.                                                                     |
| `username`           | False    | string  | _(none)_                | The MQTT username used for authentication                                                                                                                        |
| `password`           | False    | string  | _(none)_                | The MQTT password used for authentication                                                                                                                        |
| `tls`                | True     | bool    | _False_                 | Secures the connection to the MQTT service, the MQTT server side needs a valid certificate                                                                       |
| `ca_certs`           | True     | string  | _(none)_                | File path to a file containing alternative CA's. If not configure the systems default CA is used                                                                 |
| `client_cert`        | True     | string  | _(none)_                | File path to a file containing a PEM encoded client certificate                                                                                                  |
| `client_key`         | True     | string  | _(none)_                | File path to a file containing a PEM encoded client private key                                                                                                  |

#### Renaming entities. (Keys are like {fieldname}\_name)

_For every solar plant, 4 entities are added to the mqtt auto discovery. The default name can be configured._

##### Omnik solar data - entity name override

| key                         | optional | type   | default                | description                                                                                                          |
| --------------------------- | -------- | ------ | ---------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `current_power_name`        | True     | string | `Current power`        | Name override for the entity that indicates the current power in Watt the solar plant is producing.                  |
| `total_energy_name`         | True     | string | `Energy total`         | Name override for the entity that indicates total energy in kWh the solar plant has generated since installation.    |
| `today_energy_name`         | True     | string | `Energy today`         | Name override for the entity that indicates total energy in kWh the solar plant has generated this day.              |
| `last_update_time_name`     | True     | string | `Last update`          | Name override for the entity that is a timestamp total of the last update of the solar plant.                        |
| `name`                      | True     | string | `Current power`        | Name override for the entity that indicates the current power in Watt the solar plant is producing.                  |
| `inverter_temperature_name` | True     | string | `Inverter temperature` | Name override for inverters Temperature. Only the clients `tcpclient` and `localproxy` are supported.                |
| `current_ac1_name`          | True     | string | `AC Current fase R`    | Name override for AC Current fase 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_ac2_name`          | True     | string | `AC Current fase S`    | Name override for AC Current fase 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_ac3_name`          | True     | string | `AC Current fase T`    | Name override for AC Current fase 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac1_name`          | True     | string | `AC Voltage fase R`    | Name override for AC Voltage fase 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac2_name`          | True     | string | `AC Voltage fase S`    | Name override for AC Voltage fase 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac3_name`          | True     | string | `AC Voltage fase T`    | Name override for AC Voltage fase 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac_max_name`       | True     | string | `AC Voltage max`       | Name override for the maximal AC Voltage over al fases. Only the clients `tcpclient` and `localproxy` are supported. |
| `frequency_ac1_name`        | True     | string | `AC Frequency fase R`  | Name override for AC Frequency fase 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `frequency_ac2_name`        | True     | string | `AC Frequency fase S`  | Name override for AC Frequency fase 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `frequency_ac3_name`        | True     | string | `AC Frequency fase T`  | Name override for AC Frequency fase 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `power_ac1_name`            | True     | string | `AC Power fase R`      | Name override for AC Power fase 1. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `power_ac2_name`            | True     | string | `AC Power fase S`      | Name override for AC Power fase 2. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `power_ac3_name`            | True     | string | `AC Power fase T`      | Name override for AC Power fase 3. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `voltage_pv1_name`          | True     | string | `DC Voltage string 1`  | Name override for PV Voltage string 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `voltage_pv2_name`          | True     | string | `DC Voltage string 2`  | Name override for PV Voltage string 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `voltage_pv3_name`          | True     | string | `DC Voltage string 3`  | Name override for PV Voltage string 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv1_name`          | True     | string | `DC Current string 1`  | Name override for PV Current string 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv2_name`          | True     | string | `DC Current string 2`  | Name override for PV Current string 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv3_name`          | True     | string | `DC Current string 3`  | Name override for PV Current string 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `power_pv1_name`            | True     | string | `DC Power string 1`    | Name override for PV Power string 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `power_pv2_name`            | True     | string | `DC Power string 2`    | Name override for PV Power string 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `power_pv3_name`            | True     | string | `DC Power string 3`    | Name override for PV Power string 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_power_pv_name`     | True     | string | `DC Current power`     | Name override for PV total power. Only the clients `tcpclient` and `localproxy` are supported.                       |
| `operation_hours_name`      | True     | string | `Hours active`         | Name override for the oprational hours of the inverter. Only the clients `tcpclient` and `localproxy` are supported. |

##### DSMR and Omnik solar combined data - entity name override

| key                 | optional | type   | default                      | description                                                                                                                                                                                                                                           |
| ------------------- | -------- | ------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `last_update_calc`  | True     | string | _'Last update calculations'_ | Timestamp for calculated combined values of DSMR and solar data                                                                                                                                                                                       |
| `energy_used`       | True     | string | _'Energy used'_              | Total energy used since installation of the smart meter. The `total_energy_offset` setting enables is meant to configure the `total energy` of your solar system at the installation of the smart meter.                                              |
| `energy_direct_use` | True     | string | _'Energy used directly'_     | The direct used energy (consumed and not delivered to the net) since installation of the smart meter. The `total_energy_offset` setting enables is meant to configure the `total energy` of your solar system at the installation of the smart meter. |
| `power_consumption` | True     | string | _'Current consumption'_      | The current power consumption (direct and imported power).                                                                                                                                                                                            |
| `power_direct_use`  | True     | string | _'Direct consumption'_       | The direct power consumption (directly used from your generated power and not deliverd to the net).                                                                                                                                                   |

##### DSMR data - entity name override

| key                                      | optional | type   | default                       | description                                                                                                                                                                                        |
| ---------------------------------------- | -------- | ------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `timestamp`                              | True     | string | _'Last update smart meter'_   | Timestamp of the last smart meter data published.                                                                                                                                                  |
| `ELECTRICITY_USED_TARIFF_1`              | True     | string | _'Energy used tariff 1'_      | Total energy consumption at low tariff (kWh)                                                                                                                                                       |
| `ELECTRICITY_USED_TARIFF_2`              | True     | string | _'Energy used tariff 2'_      | Total energy consumption at normal tariff (kWh)                                                                                                                                                    |
| `ELECTRICITY_DELIVERED_TARIFF_1`         | True     | string | _'Energy delivered tariff 1'_ | Total energy delivery at low tariff (kWh)                                                                                                                                                          |
| `ELECTRICITY_DELIVERED_TARIFF_2`         | True     | string | _'Energy delivered tariff 2'_ | Total energy delivery at normal tariff (kWh)                                                                                                                                                       |
| `energy_used_net`                        | True     | string | _'Energy used net'_           | Total energy used (net) tarrif 1 + tarrif 2 (kWh)                                                                                                                                                  |
| `energy_delivered_net`                   | True     | string | _'Energy delivered net'_      | Total energy delivered (net) tarrif 1 + tarrif 2 (kWh)                                                                                                                                             |
| `CURRENT_ELECTRICITY_USAGE`              | True     | string | _'Net power usage'_           | Current net power used (zero during delivery) in kWatt                                                                                                                                             |
| `CURRENT_ELECTRICITY_DELIVERY`           | True     | string | _'Net power delivery'_        | Current net power delivered (zero during import) in kWatt                                                                                                                                          |
| `ELECTRICITY_ACTIVE_TARIFF`              | True     | string | _'Active tariff'_             | The active tarrif (low of normal) values can be customized in `dsmr` section                                                                                                                       |
| `LONG_POWER_FAILURE_COUNT`               | True     | string | _'Long power failure count'_  | The number of 'long' power failures counted.                                                                                                                                                       |
| `SHORT_POWER_FAILURE_COUNT`              | True     | string | _'Short power failure count'_ | The number of 'shorted' power failures counted.                                                                                                                                                    |
| `VOLTAGE_SAG_L1_COUNT`                   | True     | string | _'Voltage sag count L1'_      | The number of power sags for fase L1 counted.                                                                                                                                                      |
| `VOLTAGE_SWELL_L1_COUNT`                 | True     | string | _'Voltage swell count L1'_    | The number of power swells for fase L1 counted.                                                                                                                                                    |
| `INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE` | True     | string | _'Net power usage L1'_        | Current net power used for fase L1 (zero during delivery) in Watt                                                                                                                                  |
| `INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE` | True     | string | _'Net power delivery L1'_     | Current net power delivered for fase L1 (zero during import) in Watt                                                                                                                               |
| `current_net_power`                      | True     | string | _'Current net power'_         | The current net power (can be negative) in Watt                                                                                                                                                    |
| `current_net_power_l1`                   | True     | string | _'Current net power L1'_      | The current net power for fase L1 (can be negative) in Watt                                                                                                                                        |
| `INSTANTANEOUS_VOLTAGE_L1`               | True     | string | _'Net voltage L1'_            | The current net voltage in Volts for Fase L1 (rounded to an integer)                                                                                                                               |
| `net_voltage_max`                        | True     | string | _'Net voltage max'_           | The current maximum net voltage in Volts over all fases (rounded to an integer). Can be used as `net_voltage_fallback` key to publish voltage to pvoutput when no solar voltage data is available. |
| `INSTANTANEOUS_CURRENT_L1`               | True     | string | _'Net current L1 DSMR'_       | The current for fase L1 in Ampère (rounded to a positive integer) directly from your smart meter.                                                                                                  |
| `net_current_l1`                         | True     | string | _'Net current L1'_            | The current for fase L1 in Ampère calculated using `current_net_power_l1` / `INSTANTANEOUS_VOLTAGE_L1`. This gives a more precise current. Value is negative during enery delivery.                |

> The entries for fase L1 are also applicable for fase L2 and L3 if the data is available`

##### DSMR gas data - entity name override

| key                     | optional | type   | default                   | description                                                           |
| ----------------------- | -------- | ------ | ------------------------- | --------------------------------------------------------------------- |
| `timestamp_gas`         | True     | string | _'Last update gas meter'_ | Timestamp of the last gas meter data published.                       |
| `gas_consumption_total` | True     | string | _'Gas total'_             | The total amount of m3 gas delivered since installation of the meter. |
| `gas_consumption_hour`  | True     | string | _'Gas consumption'_       | The current consumption of gas in m3/hour.                            |

The unit of measurement the used icon, MQTT device_class and value template file can be customized by updating the file `data_fields.json`.
Make a copy of the original file and configure the path under the `data_config` key in the general setting.

### PVoutput plugin settings in the section `output.pvoutput` of `apps.yaml` or `config.yaml`

Register a free acount and API key at https://pvoutput.org/register.jsp

| key                        | optional | type   | default  | description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -------------------------- | -------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sys_id`                   | True     | string | _(none)_ | Your unique system id, generated when creating an account at pvoutput.org. Enable publishing combined inverter data to this system id. You can also set `sys_id` in plant specific section to publish separate inverters.                                                                                                                                                                                                                                                                                                                                                        |
| `api_key`                  | False    | string | _(none)_ | Unique API access key generated at pvoutput.org                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `use_temperature`          | True     | bool   | `false`  | When set to true and `use_inverter_temperature` is not set, the temperature is obtained from OpenWeatherMap is submitted to pvoutput.org when logging the data.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `use_inverter_temperature` | True     | bool   | `false`  | When set to true and `use_temperature` is set, the inverter temperature is submitted to pvoutput.org when logging the data. Only the clients `tcpclient` and `localproxy` are supported.                                                                                                                                                                                                                                                                                                                                                                                         |
| `publish_voltage`          | True     | string | _(none)_ | The _fieldname_ key of the voltage property to use for pvoutput 'addstatus' publishing. When set to `'voltage_ac_max'`, the maximal inverter AC voltage over all fases is submitted to pvoutput.org when logging the data. Only the clients `tcpclient` and `localproxy` are supported. Supported values are `voltage_ac1`, `voltage_ac2`, `voltage_ac3` or `voltage_ac_max` or one ofe the DSMR voltage fields (INSTANTANEOUS_VOLTAGE_L1 / \_L2, \_L3 or net_voltage_max) if DSMR is available. The field `net_voltage_max` holds the highest voltage over all available fases. |
| `net_voltage_fallback `    | True     | string | _(none)_ | The _fieldname_ key of the voltage property to use for pvoutput 'addstatus' publishing in case no solar data is available during sun down. When set to `'net_voltage_max'`, the maximal net voltage over all fases is submitted as alternative to pvoutput.org. This key only makes sens when using the DSMR integration.                                                                                                                                                                                                                                                        |

### CSVoutput plugin settings in the section `output.csvoutput` in of `apps.yaml` or `config.yaml`

| key               | optional | type   | default  | description                                                                                                                               |
| ----------------- | -------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `csvfile`         | True     | string | _(none)_ | Used by the client `csvoutput`. The file and path to append or create for csv logging.                                                    |
| `separator`       | True     | string | _;_      | Used by the client `csvoutput`. The separator/delimiter to use between headers and fields. Use '\t' to use a tab as separator.            |
| `no_headers`      | True     | bool   | _False_  | Used by the client `csvoutput`. If `csvoutput` will not write headers to the `csvfile`.                                                   |
| `fields`          | True     | list   | _[*]_    | Used by the client `csvoutput`. A list of fields to log. The fields `date` and `time` are specials fields to log the local date and time. |
| `use_temperature` | True     | bool   | _False_  | When set to true the `temperature` field is set in the data set which can be logged. The value is obtained from OpenWeatherMap.           |

#### Default fields and additional fields

Default fields assignment [*]:

- `date`
- `time`
- `current_power`
- `today_energy`
- `total_energy`

The following additional fields are available if DSMR data can be matched with the aggregated solar data:

- `energy_direct_use`
- `energy_used_net`
- `power_direct_use`
- `power_consumption`
- `last_update_calc`

### InfluxDB plugin settings in the section `output.influxdb` in of `apps.yaml` or `config.yaml`

| key               | optional | type    | default           | description                                                                  |
| ----------------- | -------- | ------- | ----------------- | ---------------------------------------------------------------------------- |
| `host`            | True     | string  | `localhost`       | Hostname or fqdn of the InfluxDB server for logging.                         |
| `port`            | True     | integer | `8086`            | InfluxDB port to be used.                                                    |
| `ssl`             | True     | bool    | `false`           | Use SSL. Set to `true` if the URL starts with `https://`                     |
| `verify_ssl`      | True     | bool    | `true`            | By default a certificate is validated. Set to `false` to disable validation. |
| `ssl_ca_cert`     | True     | string  | _(none)_          | Set an alternative CA cert. (InfluxDB 2.x client only)                       |
| `org`             | True     | string  | _(none)_          | The InfluxDB2 organisation (InfluxDB 2.x only)                               |
| `bucket`          | True     | string  | _(none)_          | The InfluxDB2 bucket to write to (InfluxDB 2.x only)                         |
| `token`           | True     | string  | _(none)_          | The InfluxDB2 authentication token (InfluxDB 2.x only)                       |
| `use_temperature` | True     | bool    | `false`           | When set to true the temperature is obtained from OpenWeatherMap and logged. |
| `database`        | True     | string  | _omnikdatalogger_ | The InfluxDB database (InfluxDB 1.8x only)                                   |
| `username`        | True     | string  | _(none)_          | The InfluxDB username used for Basic authentication (InfluxDB 1.8x only)     |
| `password`        | True     | string  | _(none)_          | The InfluxDB password used for Basic authentication (InfluxDB 1.8x only)     |
| `jwt_token`       | True     | string  | _(none)_          | The InfluxDB webtoken for JSON Web Token authentication (InfluxDB 1.8x only) |

Logging to InfluxDB is supported with configuration settings from `data_fields.json` The file allows to customize measurement header and allows setting additional tags.
When using InfluxDB2, authentication is mandantory. Configure `org`, `bucket` and `token` to enable the InfluxDB v2 client.

#### OpenWeatherMap settings in the section `openweathermap` of `apps.yaml` or `config.yaml`

_(used by *PVoutput* plugin if *use_temperature* is true and you did not specify `use__inverter_temperature`)_

Visit https://openweathermap.org/price to obtain a (free) api key. The weather data is cached with een TTL of 300 seconds.

| key        | optional | type   | default                  | description                                                            |
| ---------- | -------- | ------ | ------------------------ | ---------------------------------------------------------------------- |
| `api_key`  | False    | string | _(none)_                 | Unique access key generated at openweathermap.org                      |
| `endpoint` | True     | string | `api.openweathermap.org` | FQDN of the API endpoint.                                              |
| `lon`      | False    | float  | _(none)_                 | Longitude for the weather location                                     |
| `lat`      | False    | float  | _(none)_                 | Latitude for the weather location                                      |
| `units`    | True     | string | `metric`                 | Can be _metric_ (for deg. Celsius) or _imperial_ (for deg. Fahrenheit) |

### Device attribute settings and relation with `data_fields.json`

Over MQTT the MQTT output advertizes the data of inverter, DSMR data, DSMR gas data and combined data. These groups bound to device attributes that wil be associated withe entities that are being published.
In Home Assistant throug MQTT auto discovery this will show as seperate devices for 'Omnik' entities, 'DSMR' entities, 'DSMR gas' entities and 'DSMR_omnik' (combined) entities.
All fields are configured with the pre installed `data_fields.json` file. This file holds an `asset` property for each field which corresponds with the asset class.
Each asset class must have one field with `"dev_cla": "timestamp"` which is the timestamp field for that class.
If you want to omit field in your output you can personalize `data_fields.json`. Do NOT customize the shared version of `data_fields.json` but make a copy and configure the aternative path
using the [`data_config` key in get general section](https://github.com/jbouwh/omnikdatalogger#general-settings-of-appsyaml-or-configini).
The `attributes` section allows to customize some asset class settings.

| key                        | optional | type   | default                                                           | description                                                                                                                                                                                                                           |
| -------------------------- | -------- | ------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `asset_classes`            | True     | list   | _omnik, omnik_dsmr, dsmr, dsmr_gas_                               | Access classes for device payload and grouping of entities.                                                                                                                                                                           |
| `asset.{asset_class}`      | True     | string | _see below_                                                       | Customize attribute payload for an asset class                                                                                                                                                                                        |
| `asset.omnik`              | True     | string | _inverter, plant_id, last_update_                                 | Standard attributes for published Omnik inverter data                                                                                                                                                                                 |
| `asset.omnik_dsmr`         | True     | string | _inverter, plant_id, EQUIPMENT_IDENTIFIER, terminal, last_update_ | Standard attributes for published combined DSMR and Omnik inverter data                                                                                                                                                               |
| `asset.dsmr                | True     | string | _EQUIPMENT_IDENTIFIER, terminal, timestamp_                       | Standard attributes for published DSMR data                                                                                                                                                                                           |
| `asset.dsmr_gas`           | True     | string | _EQUIPMENT_IDENTIFIER_GAS, terminal, timestamp_gas_               | Standard attributes for published DSMR gas data                                                                                                                                                                                       |
| `model.{asset_class}`      | True     | string | _see below_                                                       | Customize the model property of the device payload for an asset class                                                                                                                                                                 |
| `model.omnik`              | True     | string | _Omniksol_                                                        | Customize the model property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                           |
| `model.omnik_dsmr`         | True     | string | _Omnik data logger_                                               | Customize the model property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                      |
| `model.dsmr`               | True     | string | _DSRM electricity meter_                                          | Customize the model property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                                 |
| `model.dsmr_gas`           | True     | string | _DSRM gas meter_                                                  | Customize the model property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                     |
| `mf.{asset_class}`         | True     | string | _see below_                                                       | Customize the manufacturer property of the device payload for an asset class                                                                                                                                                          |
| `mf.omnik`                 | True     | string | _Omnik_                                                           | Customize the manufacturer property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                    |
| `mf.omnik_dsmr`            | True     | string | _JBsoft_                                                          | Customize the manufacturer property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                               |
| `mf.dsmr`                  | True     | string | _Netbeheer Nederland_                                             | Customize the manufacturer property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                          |
| `mf.dsmr_gas`              | True     | string | _Netbeheer Nederland_                                             | Customize mthe anufacturer property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                              |
| `identifier.{asset_class}` | True     | string | _see below_                                                       | Customize the identifier property of the device payload for an asset class. This property should be unique when using a configuration with more DSMR meters or plants The identifier will have the format {asset*class}*{identifier}. |
| `identifier.omnik`         | True     | string | _plant_id_                                                        | Customize the identifier property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                      |
| `identifier.omnik_dsmr`    | True     | string | _plant_id_                                                        | Customize the identifier property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                 |
| `identifier.dsmr`          | True     | string | _EQUIPMENT_IDENTIFIER_                                            | Customize the identifier property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                            |
| `identifier.dsmr_gas`      | True     | string | _EQUIPMENT_IDENTIFIER_GAS_                                        | Customize the property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                           |
| `devicename.{asset_class}` | True     | string | _see below_                                                       | Customize the device name for an asset class. This attribute replaces the previous decrepated `device_name` setting in the `output.mqtt` section.                                                                                     |
| `devicename.omnik`         | True     | string | _Inverter_                                                        | Customize the device name for the asset class `omnik` (Solar data)                                                                                                                                                                    |
| `devicename.omnik_dsmr`    | True     | string | _Omnik_data_logger_                                               | Customize the device name for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                                               |
| `devicename.dsmr`          | True     | string | _DSMR_electicity_meter_                                           | Customize the device name the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                                       |
| `devicename.dsmr_gas`      | True     | string | _DSMR_gasmeter_                                                   | Customize the device name the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                           |

## Configuration using config.ini

Using a `config.ini` config file is no longer supported! Move your config a .yaml file in stead.

## Scheduled Run (commandline or using systemd)

You've got your default options to schedule this logger, but I included a `systemd` service file to run this as a service on Linux.

> **PS**: I'm using `Ubuntu 18.04 LTS` but Debian buster should also work.

First, install this thing (~ using Python 3.7+ !!!)

> If you don't have `Python3.7+` installed, do that first (~ don't forget to install `python3-pip` as well)

```
#### Create a to download the scripts
$ git clone https://github.com/jbouwh/omnikdatalogger
> onmiklogger.py can be found in the `./apps` folder
# check if properly installed
$ omniklogger.py -h
usage: omniklogger.py [-h] [--settings FILE] [--interval n] [-l]

optional arguments:
  -h, --help     show this help message and exit
  --settings FILE  Path to yaml configuration file
  --interval n   Execute every n seconds
  -l {DEBUG,INFO,WARNING,ERROR}, --loglevel {DEBUG,INFO,WARNING,ERROR} Loglevel
```

An example systemd script is available from `scripts/omnikdatalogger.service`. Copy it so you can customize it to your use.

Check the folowing line in this file in the script.

```
ExecStart=/usr/bin/python3 /usr/local/bin/omniklogger.py --settings /etc/omnik/config.yaml --interval 360
```

Make sure the interval is as desired and that the path of omniklogger.py is correct

Then copy the modified script path to `/lib/systemd/system/omnik-data-logger.service`

Next, enable and start service:

```
$ systemd enable omnikdatalogger
Created symlink /etc/systemd/system/multi-user.target.wants/omnikdatalogger.service → /lib/systemd/system/omnikdatalogger.service.
$ systemd start omnikdatalogger
```

Check if `omnikdatalogger.service` is running correctly:

```
$ systemd status omnikdatalogger
● omnikdatalogger.service - Omnik Data Logger service
   Loaded: loaded (/lib/systemd/system/omnikdatalogger.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-06-18 06:55:08 UTC; 4min 36s ago
 Main PID: 2445 (python3)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/omnikdatalogger.service
           └─2445 /usr/bin/python3 /usr/local/bin/omniklogger.py --settings /etc/omnik/config.yaml --interval 300
```


%package help
Summary:	Development documents and examples for omnikdatalogger
Provides:	python3-omnikdatalogger-doc
%description help
# omnikdatalogger

![PyPI version](https://badge.fury.io/py/omnikdatalogger.svg)
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)

Omnik data logger enables you to log the data of your Omnik inverter combine the data with a Dutch or Belgian SLIMME METER and output the data Home Assistant using MQTT discovery.
You can also choose to log your data to pvoutput or an influx database or combine output options.

## See also

- [Omnik data logger Wiki](https://github.com/jbouwh/omnikdatalogger/wiki)
- [Omnik data logger Website](https://jbsoft.nl/site/omnik-datalogger/)

## Installation

The application can be installed:

- Install with the Home Assistant Community Store [HACS](https://hacs.xyz/).
  - Omnik data logger is included in the default repository. Open the Automation tab. Click on de big orange **+**
  - Search for 'Omnik data logger' and select it.
  - Choose 'Install this repository in HACS'
- Download the latest release from [here](https://github.com/jbouwh/omnikdatalogger/releases)
- Clone using git: `git clone https://gihub.com/jbouwh/omnikdatalogger`. Optional install with `pip3 install ./omnikdatalogger`.
- Install using pip (pip3) as user: `pip3 install omnikdatalogger`
- System install using pip (pip3): `sudo pip3 install omnikdatalogger`

The main application files are in the folder `apps/omnikdatalogger`

## Usage

The application can be configured using:

- Commandline (limited options available)
- Configuration file (config.yaml)
- apps.yaml configuration file (with AppDaemon) _(This applies tot HACS-users)_

### Commandline

```
usage: [python3] omniklogger.py [-h] [--config FILE] [--interval n] [-d]

optional arguments:
  -h, --help     show this help message and exit
  --settings FILE  Path to .yaml configuration file
  --section  Section to .yaml configuration file to use. Defaults to the first section found.
  --data_config FILE  Path to data_fields.json configuration file
  --persistant_cache_file FILE  Path to writable cache json file to store last power en total energy
  --interval n  execute every n seconds
  -l {DEBUG,INFO,WARNING,ERROR}, --loglevel {DEBUG,INFO,WARNING,ERROR} Loglevel
```

> De default location for config using the commandline is `~/.omnik/config.yaml`.

### Configuration using apps.yaml (AppDeamon) (with possible HomeAssistant integration)

#### Preparation for scheduled use with AppDaemon4

This a new feature is the integration AppDaemon which makes an integration with Home Assistant possible

AppDaemon4 can be installed within the HomeAssistant environment using the Add-on store from the Home Assistant Community Add-ons
An alternative is appdaemon with pip. See: https://pypi.org/project/appdaemon/

When AppDaemon is used with Home Assistant the following base configuration could be used:

```yaml
system_packages: []
python_packages:
  - cachetools
  - dsmr-parser
  - influxdb-client
init_commands: []
log_level: info
```

The dependency for cachetools is the only 'hard' dependency. The `dsmr-parser` package is needed when you are using a Dutch Smart Meter (DSMR compliant) USB adapter. Please feel free to adjust the base log_level.

When used with HACS the dependencies in [requirements.txt](https://github.com/jbouwh/omnikdatalogger/blob/master/requirements.txt) should be installed automatically.

The basescript omniklogger.py holds a class HA_OmnikDataLogger that implements appdaemon.plugins.hass.hassapi
See for more information and documentation about AppDaemon: https://appdaemon.readthedocs.io/en/latest/APPGUIDE.html

The configfile /config/appdaemon/appdaemon.yaml needs a minimal configuration. Further it is possible to define the location for your logfiles. And example configuration is:

```yaml
appdaemon:
  latitude: 0.0
  longitude: 0.0
  elevation: 0.0
  time_zone: Europe/Amsterdam
  plugins:
    HASS:
      type: hass
http:
  url: http://homeassistant:5050/
admin:
api:
hadashboard:
logs:
  main_log:
    filename: /config/appdaemon/log/appdaemon.log
  error_log:
    filename: /config/appdaemon/log/appdaemon.err
```

Make sure the url is accessible with the hostname you configure.

#### Configuring `apps.yaml` to use Omnik Data Logger with AppDaemon4

Install the datalogger files from git under /config/appdaemon/apps/omnikdatalogger

The base script is located at:

```
/config/appdaemon/apps/omnikdatalogger/omniklogger.py
```

Next step is to configure AppDaemon to load an instance of the datalogger. It is possible to make multiple instances if you have more omnik accounts.

This configuration is placed in the file: `/config/appdaemon/apps/apps.yaml`.

#### Full Configuration Example of `config.yaml`/`apps.yaml`:

```yaml
# The instance name is omnik_datalogger, this can be changed. Multiple instances are supported.
omnik_datalogger:
  # General options
  module: omniklogger
  class: HA_OmnikDataLogger
  city: Amsterdam
  interval: 360

  # plugin section
  plugins:
    # plugins for data logging (output)
    output:
      - pvoutput
      - mqtt
      - influxdb
      - csvoutput
    # plugins for local proxy client (list)
    localproxy:
      - hassapi
    #     - mqtt_proxy
    #     - tcp_proxy
    # the client that is beging used (choose one)
    # valid clients are localproxy, solarmanpv and tcpclient
    client: localproxy

  # attributes override
  attributes:
    devicename.omnik: Omvormer
  #   model.omnik: Omnik data logger

  #DSMR support
  dsmr:
    terminals:
      - term1
    tarif:
      - "0001"
      - "0002"
    tarif.0001: laag
    tarif.0002: normaal

  dsmr.term1:
    # use mode tcp or device
    mode: tcp
    host: 172.17.0.1
    port: 3333
    device: /dev/ttyUSB0
    dsmr_version: "5"
    total_energy_offset: 15338.0
    gas_meter: true

  # Section for your inverters specific settings
  plant.123:
    inverter_address: 192.168.1.1
    logger_sn: 123456789
    inverter_port: 8899
    inverter_sn: NLxxxxxxxxxxxxxx
    sys_id: <YOUR SYSTEM ID>
    # CSV output for specific plant
    csvfile: "/some_path/output.178735.csv"
    separator: ";"
    no_headers: false
    fields:
      - date
      - time
      - current_power
      - today_energy
      - total_energy
      - inverter

  # Section for the localproxy client
  client.localproxy:
    plant_id_list:
      - "123"
  # Section for the localproxy plugin hassapi
  client.localproxy.hassapi:
    logger_entity: binary_sensor.datalogger
  # Section for the localproxy plugin mqtt_proxy
  client.localproxy.mqtt_proxy:
    logger_sensor_name: Datalogger
    discovery_prefix: homeassistant
    host: homeassistant.example.com
    port: 1883
    client_name_prefix: ha-mqtt-omniklogger
    username: mqttuername
    password: mqttpasswordabcdefgh
  # Section for the localproxy plugin tcp_proxy
  client.localproxy.tcp_proxy:
    listen_address: "0.0.0.0"
    listen_port: "10004"

  # Solarmanpv API options
  client.solarmanpv:
    username: john.doe@example.com
    password: some_password

  # Influxdb output plugin configuration options
  output.influxdb:
    # Common settings
    host: localhost
    port: 8086
    ssl: false #  # Use SSL
    verify_ssl: true # Verify SSL certificate for HTTPS request

    use_temperature: true # If true logs the temperature of the openweathermap API

    # InfluxDB v1 only
    database: omnikdatalogger
    username: omnikdatalogger
    password: mysecretpassword
    #jwt_token=

    # InfluxDB v2 only
    org: jbsoft
    bucket: omnik
    token: generatedtoken
    ssl_ca_cert: path_to_custom_ca.crt # Only for InfluxDB 2!

  # csvoutput output plugin configuration options
  output.csvoutput:
    # CSV output for aggregated data
    csvfile: "/some_path/output.csv"
    separator: ";"
    no_headers: false
    use_temperature: true
    fields:
      - date
      - time
      - current_power
      - today_energy
      - total_energy
      - temperature

  # PVoutput output plugin configuration options
  output.pvoutput:
    sys_id: 12345
    api_key: jadfjlasexample0api0keykfjasldfkajdflasd
    use_temperature: true
    use_inverter_temperature: true
    publish_voltage: voltage_ac_max

  # Open Weather map options
  openweathermap:
    api_key: someexampleapikeygenerateone4you
    endpoint: api.openweathermap.org
    lon: 4.0000000
    lat: 50.1234567
    units: metric

  # MQTT output plugin configuration options
  output.mqtt:
    username: mqttuername
    password: mqttpasswordabcdefgh
    device_name: Omvormer
    append_plant_id: false
    # Omnik
    current_power_name: Vermogen zonnepanelen
    total_energy_name: Gegenereerd totaal
    today_energy_name: Gegenereerd vandaag
    last_update_name: Laatste statusupdate
    inverter_temperature_name: Temperatuur omvormer
    current_ac1_name: Stroom AC
    current_ac2_name: Stroom AC fase 2
    current_ac3_name: Stroom AC fase 3
    voltage_ac_max_name: Spanning AC max
    voltage_ac1_name: Spanning AC fase 1
    voltage_ac2_name: Spanning AC fase 2
    voltage_ac3_name: Spanning AC fase 3
    frequency_ac1_name: Netfrequentie
    frequency_ac2_name: Netfrequentie fase 2
    frequency_ac3_name: Netfrequentie fase 3
    power_ac1_name: Vermogen AC
    power_ac2_name: Vermogen AC fase 2
    power_ac3_name: Vermogen AC fase 3
    voltage_pv1_name: Spanning DC 1
    voltage_pv2_name: Spanning DC 2
    voltage_pv3_name: Spanning DC 3
    current_pv1_name: Stroom DC 1
    current_pv2_name: Stroom DC 2
    current_pv3_name: Stroom DC 3
    power_pv1_name: Vermogen DC 1
    power_pv2_name: Vermogen DC 2
    power_pv3_name: Vermogen DC 3
    current_power_pv_name: Vermogen DC
    operation_hours_name: Actieve uren
    # DSMR
    timestamp_name: Update slimme meter
    ELECTRICITY_USED_TARIFF_1_name: Verbruik (laag)
    ELECTRICITY_USED_TARIFF_2_name: Verbruik (normaal)
    ELECTRICITY_DELIVERED_TARIFF_1_name: Genereerd (laag)
    ELECTRICITY_DELIVERED_TARIFF_2_name: Gegenereerd (normaal)
    energy_used_net_name: Verbruikt (net)
    energy_delivered_net_name: Gegenereerd (net)
    CURRENT_ELECTRICITY_USAGE_name: Verbruik (net)
    CURRENT_ELECTRICITY_DELIVERY_name: Teruglevering (net)
    ELECTRICITY_ACTIVE_TARIFF_name: Tarief
    LONG_POWER_FAILURE_COUNT_name: Onderbrekingen (lang)
    SHORT_POWER_FAILURE_COUNT_name: Onderbrekingen (kort)
    VOLTAGE_SAG_L1_COUNT_name: Net dips L1
    VOLTAGE_SAG_L2_COUNT_name: Net dips L2
    VOLTAGE_SAG_L3_COUNT_name: Net dips L3
    VOLTAGE_SWELL_L1_COUNT_name: Net pieken L1
    VOLTAGE_SWELL_L2_COUNT_name: Net pieken L2
    VOLTAGE_SWELL_L3_COUNT_name: Net pieken L3
    INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE_name: Gebruik L1
    INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE_name: Gebruik L2
    INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE_name: Gebruik L3
    INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE_name: Teruglevering L1
    INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE_name: Teruglevering L2
    INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE_name: Teruglevering L3
    current_net_power_name: Vermogen (net)
    current_net_power_l1_name: Vermogen L1
    current_net_power_l2_name: Vermogen L2
    current_net_power_l3_name: Vermogen L3
    INSTANTANEOUS_VOLTAGE_L1_name: Spanning L1
    INSTANTANEOUS_VOLTAGE_L2_name: Spanning L2
    INSTANTANEOUS_VOLTAGE_L3_name: Spanning L3
    INSTANTANEOUS_CURRENT_L1_name: Stroom L1 DSMR
    INSTANTANEOUS_CURRENT_L2_name: Stroom L2 DSMR
    INSTANTANEOUS_CURRENT_L3_name: Stroom L3 DSMR
    net_current_l1_name: Stroom L1
    net_current_l3_name: Stroom L2
    net_current_l2_name: Stroom L3
    net_voltage_max_name: Netspanning max
    # DSMR gas
    timestamp_gas_name: Update gasmeter
    gas_consumption_total_name: Verbruik gas totaal
    gas_consumption_hour_name: Verbruik gas
    # omnik_DSMR (combined)
    last_update_calc_name: Update berekening
    energy_used_name: Verbruikt totaal
    energy_direct_use_name: Direct verbruikt
    power_consumption_name: Verbruik
    power_direct_use_name: Direct verbruik
```

## Configuration keys (required, optional and defaults)

The .yaml file configuration file used from the command line has the same structure as `apps.yaml`

The first section in `config.yaml` will be used (see event log).

### General settings

#### General settings - `apps.yaml` 'only' configuration options

> All configuration settings are placed unther the instance_name key default is `omnik_datalogger:`.

| key      | optional | type   | default  | description                                                                                                                        |
| -------- | -------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `module` | False    | string | _(none)_ | Should be the name of the base script `omniklogger`. A path should not be configured. AppDaemon wil find the module automatically. |
| `class`  | False    | string | _(none)_ | Should be the name of the class hat implements 'appdaemon.plugins.hass.hassapi'. This value should be `HA_OmnikDataLogger`.        |

#### General settings of `apps.yaml` or `config.yaml`

> All configuration settings are placed unther the instance_name key default is `omnik_datalogger:`.

| key                     | optional | type    | default                                | description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ----------------------- | -------- | ------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `city`                  | True     | string  | `Amsterdam`                            | City name recognizable by the Astral python module. Based on this city the data logging is disabled from dusk to dawn. This prevents unneccesary calls to the omnik portal.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `interval`              | True     | integer | `360`                                  | The number of seconds of the interval between the last update timestamp and the next poll. At normal conditions the omnik portal produces a new report approx. every 300 sec. With an interval of 360 a new pol is done with max 60 delay. This enabled fluctuation in the update frequency of the omnik portal. If there is not enough time left to wait (less than 10 sec) and no new report was found at the omnik portal another period of _interval_ seconds will be waited. After an error calling the omnik API another half _interval_ will be waited before the next poll will be done. A pushing client as `localproxy` is, needs an interval te be set when used from the command line higher then 0. The interval it self is not used since the data is pushed. When no interval is given at the command line (or in a systemd setup) the executable will stop automatically after one reading! |
| `data_config`           | True     | string  | `{path to installed data_fields.json}` | The path to the `data_fields.json`. De default is looking in the folder of the executable. When installed using _pip_ `data_fields.json` is installd in the folder `./shared/omnikdatalogger/data_fields.json`. With this parameter you can savely make your own copy and customize it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `persistant_cache_file` | True     | string  | `{./persistant_cache.json}`            | The path to the `persistant_cache.json` file. This file must be writable since its stores the latest total energy and power. When using docker containers, place this file out of your container.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

#### Plugin settings in the section `plugins` of `apps.yaml` or `config.yaml`

| key          | optional | type   | default        | description                                                                                                                                                                                                  |
| ------------ | -------- | ------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `client`     | False    | string | _(none)_       | Name of the client that will be used to fetch the data. Valid choices are `localproxy`, `tcp_client`, or `solarmanpv`.                                                                                       |
| `localproxy` | True     | list   | _(none)_       | The client plugings for the `localproxy` client that will be used to fetch the data. Valid choices are `tcp_proxy`, `mqtt_proxy` or `hassapi`.                                                               |
| `output`     | True     | list   | _(empty list)_ | A (yaml) list of string specifying the name(s) of the output plugins to be used. Available plugins are `pvoutput`, `influxdb`, `csvoutput` and `mqtt`. If no plugins are configured, nothing will be logged. |

#### DSMR settings in the section `dsmr` of `apps.yaml` or `config.yaml`

| key          | optional | type   | default            | description                                                                                                                             |
| ------------ | -------- | ------ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| `terminals ` | False    | list   | _(empty list)_     | List of DSMR terminals. Eacht termial has settings at section [dsrm.{terminal_name}]. An empty list disables the DSMR integration.      |
| `tarif.0001` | True     | string | _low_              | Tarif value override for tarif 0001 (low). If you need outher tarifs then 0001 or 0002 the configure the tarif key.                     |
| `tarif.0002` | True     | string | _normal_           | Tarif value override for tarif 0002 (normal)                                                                                            |
| `tarif`      | True"    | list   | _['0001', '0002']_ | Use only if your meter has other tarifs then 0001 and 0002 and you want to override the name. (Not needed in the Netherlands I suppose) |

##### DSMR settings in the section `dsmr.{terminal_name}` of `apps.yaml` or `config.yaml`

| key                   | optional | type    | default     |                                                                                                                                                                                                |
| --------------------- | -------- | ------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mode`                | True     | string  | _device_    | Mode for the DSMR terminal. Mode can be `device` (default) or `tcp`)                                                                                                                           |
| `host `               | True     | string  | _localhost_ | When using tcp, the host or IP-address to connect to (e.g. a ser2net instance).                                                                                                                |
| `port `               | True     | int     | _3333_      | When using tcp, the port to connect to (e.g. a ser2net instance).                                                                                                                              |
| `plant_id`            | True     | string  | _(none)_    | Associates the DSMR data with the Omnik plant data. Use only when you have multiple inverters that use a different DSMR meter.                                                                 |
| `dsmr_version`        | True     | string  | _'5'_       | The DSMR version of your smart meter. Choices: '2.2', '4', '5', '5B' (For Belgian Meter). Default = '5'                                                                                        |
| `gas_meter`           | True     | boolean | _true_      | The DSMR meter has a connected gas meter to read out.                                                                                                                                          |
| `total_energy_offset` | True     | float   | _0.0_       | The start value of your solar system used to calculated the total energy consumption. When no `plant_id` is specified this start value is the `total_energy_offset` of all inverters together. |

## Client settings

Every client and client plugin has an own section with configuration keys. Additional for every plant there is a section with plant specific settings.

### Plant specific settings in the section `plant.*plant_id*` of `apps.yaml` or `config.yaml`

Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system (you can choose you own id). Every plant has its own section. Possible keys in this section are:

| key                | optional | type   | default                                | description                                                                                                                                                                                                |
| ------------------ | -------- | ------ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `inverter_address` | True     | string | _(none)_                               | The IP-adres of your inverter. Used by the client `tcpclient` to access the inverter.                                                                                                                      |
| `logger_sn`        | True     | int    | _(none)_                               | The logger module serial number of your inverter. Used by the client `tcpclient` to access the inverter.                                                                                                   |
| `inverter_port`    | True     | int    | _8899_                                 | The the tcp port your inverter listens to (default to 8899). Used by the client `tcpclient` to access the inverter.                                                                                        |
| `inverter_sn`      | False    | string | _(none)_                               | The serial number of the inverter. Used by the clients `tcpclient` and `localproxy` to map `inverter_sn` and `plant_id` to validate/filter the raw data messages received.                                 |
| `http_only`        | True     | bool   | _False_                                | Used by the client `tcpclient`. The client will not try to connect the inverter over port `8899` but will use the fallback method to fetch a status update using http://{inverter_address}:80/js/status.js |
| `sys_id`           | True     | int    | _`sys_id` at the `[pvoutput]` section_ | Your unique system id, generated when creating an account at pvoutput.org. This setting allows the specific inveterdata to be published at pvoutput.org. See `pvoutput` settings for more information.     |
| `logger_entity`    | True     | string | _(none)_                               | When using the `localproxy` client with `hassapi`, this specifies the inverter entity created through `omnikdataloggerproxy` that receives new updates for the inverter.                                   |
| `csvfile`          | True     | string | _(none)_                               | Used by the client `csvoutput`. The file and path to append or create for csv logging.                                                                                                                     |
| `separator`        | True     | string | _;_                                    | Used by the client `csvoutput`. The separator/delimiter to use between headers and fields. Use '\t' to use a tab as separator.                                                                             |
| `no_headers`       | True     | bool   | _False_                                | Used by the client `csvoutput`. If `csvoutput` will not write headers to the `csvfile`.                                                                                                                    |
| `fields`           | True     | list   | _[*]_                                  | Used by the client `csvoutput`. A list of fields to log. The fields `date` and `time` are specials fields to log the local date and time.                                                                  |
| `use_temperature`  | True     | bool   | _False_                                | When set to true the `temperature` field is set in the data set which can be logged to CSV. The value is obtained from OpenWeatherMap.                                                                     |

[*] == [
"date",
"time",
"current_power",
"today_energy",
"total_energy",
]

### TCPclient client settings in the section `client.tcpclient` of `apps.yaml` or `config.yaml`

| key             | optional | type | default  | description                                                                                                                                                                                            |
| --------------- | -------- | ---- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `plant_id_list` | False    | list | _(none)_ | List with the plant id's you want to be monitored. Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system. Every plant has its own section. |

### LocalProxy client settings in the section `client.localproxy` of `apps.yaml` or `config.yaml`

| key             | optional | type | default  | description                                                                                                                                                                               |
| --------------- | -------- | ---- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `plant_id_list` | False    | list | _(none)_ | List with the plant id's you monitor. Details for the plant are set in section `plant.{plant id}]`. Replace _plant_id_ with the plant id of your system. Every plant has its own section. |

The LocalProxy client uses input plugins that are used to collect the data.
The `omnikloggerproxy.py` script (See `https://github.com/jbouwh/omnikdataloggerproxy`) enable to proxy the raw logger data to MQTT and can help to forward your data to omnikdatalogger and still support forwarding the logging to the the legacy portal of Omnik/Solarman.
Multiple plugins can be enabled, but usualy you will use one of these input pluging. The decoding is based on _(https://github.com/Woutrrr/Omnik-Data-Logger)_ by Wouter van der Zwan.
The plugings for the `localproxy` client are:

- `tcp_proxy`: Listens to directed inverter input on port 10004. See _tcp_proxy_ paragraph. Yo need to forward the inverter traffic to be able to intercept your inverter data.
- `mqtt_proxy`: Listens to a MQTT topic to retreive the data. Use `omnikloggerproxy.py` to forward to your MQTT server.
- `hassapi`: Listens to a homeassitant entity (ascociated with MQTT) using the HASSAPI in AppDaemon. This plugin is prefered for use in combination with Home Assistant.

#### `tcp_proxy` plugin for the `localproxy` client in the section `client.localproxy.tcp_proxy` of `apps.yaml` or `config.yaml`

| key              | optional | type   | default     | description                |
| ---------------- | -------- | ------ | ----------- | -------------------------- |
| `listen_address` | True     | string | _'0.0.0.0'_ | The IP-adres to listen to. |
| `listen_port`    | True     | string | _'10004'_   | The port to listen to.     |

#### `mqtt_proxy` plugin for the `localproxy` client in the section `client.localproxy.mqtt_proxy` of `apps.yaml` or `config.yaml`

| key                  | optional | type    | default                                                                 | description                                                                                                                                                      |
| -------------------- | -------- | ------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logger_sensor_name` | True     | string  | _'Datalogger'_                                                          | The mqtt topic is assembled as {mqtt.discovery*prefix }/binary_sensor/{logger_sensor_name}*{serialnumber}                                                        |
| `discovery_prefix`   | True     | string  | _(key under the `output.mqtt` section)_                                 | The mqtt plugin supports MQTT auto discovery with Home Assistant. The discovery_prefix configures the topic prefix Home Assistant listens to for auto discovery. |
| `host`               | True     | string  | _(key under the `output.mqtt` section)_                                 | Hostname or fqdn of the MQTT server for publishing.                                                                                                              |
| `port`               | True     | integer | _(key under the `output.mqtt` section)_                                 | MQTT port to be used.                                                                                                                                            |
| `client_name_prefix` | True     | string  | _(key under the `output.mqtt` section) then `ha-mqttproxy-omniklogger`_ | Defines a prefix that is used as client name. A 4 byte uuid is added to ensure an unique ID.                                                                     |
| `username`           | False    | string  | _(key under the `output.mqtt` section)_                                 | The MQTT username used for authentication                                                                                                                        |
| `password`           | False    | string  | _(key under the `output.mqtt` section)_                                 | The MQTT password used for authentication                                                                                                                        |
| `tls`                | True     | bool    | _(key under the `output.mqtt` section)_                                 | Secures the connection to the MQTT service, the MQTT server side needs a valid certificate                                                                       |
| `ca_certs`           | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing alternative CA's. If not configure the systems default CA is used                                                                 |
| `client_cert`        | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing a PEM encoded client certificate                                                                                                  |
| `client_key`         | True     | string  | _(key under the `output.mqtt` section)_                                 | File path to a file containing a PEM encoded client private key                                                                                                  |

#### `hassapi` plugin for the `localproxy` client in the section `client.localproxy.hassapi` of `apps.yaml` or `config.yaml`

| key             | optional | type   | default                      | description                                                                                                                                                                                              |
| --------------- | -------- | ------ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logger_entity` | True     | string | _'binary_sensor.datalogger'_ | The entity name of the datalogger object in Home Assistant created by the mqtt output of the `omnikloggerproxy.py` script. With multiple inverters use `logger_entity` with the plant specific settings. |

### SolarmanPV client settings in the section `client.solarmanpv` of `apps.yaml` or `config.yaml`

| key        | optional | type   | default  | description                                                                                       |
| ---------- | -------- | ------ | -------- | ------------------------------------------------------------------------------------------------- |
| `username` | False    | string | _(none)_ | Your Omikportal or SolarmanPV username                                                            |
| `password` | False    | string | _(none)_ | Your Omikportal or SolarmanPV password                                                            |
| `app_id`   | True     | string | _(none)_ | The API id used to access your data. If configured, this will override the default assigned id.   |
| `app_key`  | True     | string | _(none)_ | The API key used to access your data. If configured, this will override the default assigned key. |

## Output plugins

### MQTT plugin

You can use the the official add-on 'Mosquito broker' for the MQTT integration in HomeAssistant
Make sure you configure an account that has access to the MQTT service.
To integrate with HomeAssistant make sure a username/password combination is added to the Mosquito config like:
The datalogger uses the paho.mqtt.client for connnecting to the MQTT broker.

```yaml
logins:
  - username: mymqttuser
    password: mysecretpassword
```

Restart Mosquito after changing the config.

#### MQTT settings in the section `output.mqtt` of `apps.yaml` or `config.yaml`

| key                  | optional | type    | default                 | description                                                                                                                                                      |
| -------------------- | -------- | ------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `discovery_prefix`   | True     | string  | _'homeassistant'_       | The mqtt plugin supports MQTT auto discovery with Home Assistant. The discovery_prefix configures the topic prefix Home Assistant listens to for auto discovery. |
| `device_name`        | True     | string  | _'Datalogger proxy'_    | Omnik data logger proxy only setting. Overrides the name of the datalogger in the omnik portal. See also the `attributes` section below.                         |
| `append_plant_id`    | True     | bool    | _false_                 | When a device_name is specified the plant id can be added to the name te be able to identify the plant.                                                          |
| `host`               | True     | string  | `localhost`             | Hostname or fqdn of the MQTT server for publishing.                                                                                                              |
| `port`               | True     | integer | _1883_                  | MQTT port to be used.                                                                                                                                            |
| `retain`             | True     | bool    | _True_                  | Retains the data send to the MQTT service                                                                                                                        |
| `client_name_prefix` | True     | string  | _'ha-mqtt-omniklogger'_ | Defines a prefix that is used as client name. A 4 byte uuid is added to ensure an unique ID.                                                                     |
| `username`           | False    | string  | _(none)_                | The MQTT username used for authentication                                                                                                                        |
| `password`           | False    | string  | _(none)_                | The MQTT password used for authentication                                                                                                                        |
| `tls`                | True     | bool    | _False_                 | Secures the connection to the MQTT service, the MQTT server side needs a valid certificate                                                                       |
| `ca_certs`           | True     | string  | _(none)_                | File path to a file containing alternative CA's. If not configure the systems default CA is used                                                                 |
| `client_cert`        | True     | string  | _(none)_                | File path to a file containing a PEM encoded client certificate                                                                                                  |
| `client_key`         | True     | string  | _(none)_                | File path to a file containing a PEM encoded client private key                                                                                                  |

#### Renaming entities. (Keys are like {fieldname}\_name)

_For every solar plant, 4 entities are added to the mqtt auto discovery. The default name can be configured._

##### Omnik solar data - entity name override

| key                         | optional | type   | default                | description                                                                                                          |
| --------------------------- | -------- | ------ | ---------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `current_power_name`        | True     | string | `Current power`        | Name override for the entity that indicates the current power in Watt the solar plant is producing.                  |
| `total_energy_name`         | True     | string | `Energy total`         | Name override for the entity that indicates total energy in kWh the solar plant has generated since installation.    |
| `today_energy_name`         | True     | string | `Energy today`         | Name override for the entity that indicates total energy in kWh the solar plant has generated this day.              |
| `last_update_time_name`     | True     | string | `Last update`          | Name override for the entity that is a timestamp total of the last update of the solar plant.                        |
| `name`                      | True     | string | `Current power`        | Name override for the entity that indicates the current power in Watt the solar plant is producing.                  |
| `inverter_temperature_name` | True     | string | `Inverter temperature` | Name override for inverters Temperature. Only the clients `tcpclient` and `localproxy` are supported.                |
| `current_ac1_name`          | True     | string | `AC Current fase R`    | Name override for AC Current fase 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_ac2_name`          | True     | string | `AC Current fase S`    | Name override for AC Current fase 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_ac3_name`          | True     | string | `AC Current fase T`    | Name override for AC Current fase 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac1_name`          | True     | string | `AC Voltage fase R`    | Name override for AC Voltage fase 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac2_name`          | True     | string | `AC Voltage fase S`    | Name override for AC Voltage fase 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac3_name`          | True     | string | `AC Voltage fase T`    | Name override for AC Voltage fase 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `voltage_ac_max_name`       | True     | string | `AC Voltage max`       | Name override for the maximal AC Voltage over al fases. Only the clients `tcpclient` and `localproxy` are supported. |
| `frequency_ac1_name`        | True     | string | `AC Frequency fase R`  | Name override for AC Frequency fase 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `frequency_ac2_name`        | True     | string | `AC Frequency fase S`  | Name override for AC Frequency fase 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `frequency_ac3_name`        | True     | string | `AC Frequency fase T`  | Name override for AC Frequency fase 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `power_ac1_name`            | True     | string | `AC Power fase R`      | Name override for AC Power fase 1. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `power_ac2_name`            | True     | string | `AC Power fase S`      | Name override for AC Power fase 2. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `power_ac3_name`            | True     | string | `AC Power fase T`      | Name override for AC Power fase 3. Only the clients `tcpclient` and `localproxy` are supported.                      |
| `voltage_pv1_name`          | True     | string | `DC Voltage string 1`  | Name override for PV Voltage string 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `voltage_pv2_name`          | True     | string | `DC Voltage string 2`  | Name override for PV Voltage string 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `voltage_pv3_name`          | True     | string | `DC Voltage string 3`  | Name override for PV Voltage string 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv1_name`          | True     | string | `DC Current string 1`  | Name override for PV Current string 1. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv2_name`          | True     | string | `DC Current string 2`  | Name override for PV Current string 2. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `current_pv3_name`          | True     | string | `DC Current string 3`  | Name override for PV Current string 3. Only the clients `tcpclient` and `localproxy` are supported.                  |
| `power_pv1_name`            | True     | string | `DC Power string 1`    | Name override for PV Power string 1. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `power_pv2_name`            | True     | string | `DC Power string 2`    | Name override for PV Power string 2. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `power_pv3_name`            | True     | string | `DC Power string 3`    | Name override for PV Power string 3. Only the clients `tcpclient` and `localproxy` are supported.                    |
| `current_power_pv_name`     | True     | string | `DC Current power`     | Name override for PV total power. Only the clients `tcpclient` and `localproxy` are supported.                       |
| `operation_hours_name`      | True     | string | `Hours active`         | Name override for the oprational hours of the inverter. Only the clients `tcpclient` and `localproxy` are supported. |

##### DSMR and Omnik solar combined data - entity name override

| key                 | optional | type   | default                      | description                                                                                                                                                                                                                                           |
| ------------------- | -------- | ------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `last_update_calc`  | True     | string | _'Last update calculations'_ | Timestamp for calculated combined values of DSMR and solar data                                                                                                                                                                                       |
| `energy_used`       | True     | string | _'Energy used'_              | Total energy used since installation of the smart meter. The `total_energy_offset` setting enables is meant to configure the `total energy` of your solar system at the installation of the smart meter.                                              |
| `energy_direct_use` | True     | string | _'Energy used directly'_     | The direct used energy (consumed and not delivered to the net) since installation of the smart meter. The `total_energy_offset` setting enables is meant to configure the `total energy` of your solar system at the installation of the smart meter. |
| `power_consumption` | True     | string | _'Current consumption'_      | The current power consumption (direct and imported power).                                                                                                                                                                                            |
| `power_direct_use`  | True     | string | _'Direct consumption'_       | The direct power consumption (directly used from your generated power and not deliverd to the net).                                                                                                                                                   |

##### DSMR data - entity name override

| key                                      | optional | type   | default                       | description                                                                                                                                                                                        |
| ---------------------------------------- | -------- | ------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `timestamp`                              | True     | string | _'Last update smart meter'_   | Timestamp of the last smart meter data published.                                                                                                                                                  |
| `ELECTRICITY_USED_TARIFF_1`              | True     | string | _'Energy used tariff 1'_      | Total energy consumption at low tariff (kWh)                                                                                                                                                       |
| `ELECTRICITY_USED_TARIFF_2`              | True     | string | _'Energy used tariff 2'_      | Total energy consumption at normal tariff (kWh)                                                                                                                                                    |
| `ELECTRICITY_DELIVERED_TARIFF_1`         | True     | string | _'Energy delivered tariff 1'_ | Total energy delivery at low tariff (kWh)                                                                                                                                                          |
| `ELECTRICITY_DELIVERED_TARIFF_2`         | True     | string | _'Energy delivered tariff 2'_ | Total energy delivery at normal tariff (kWh)                                                                                                                                                       |
| `energy_used_net`                        | True     | string | _'Energy used net'_           | Total energy used (net) tarrif 1 + tarrif 2 (kWh)                                                                                                                                                  |
| `energy_delivered_net`                   | True     | string | _'Energy delivered net'_      | Total energy delivered (net) tarrif 1 + tarrif 2 (kWh)                                                                                                                                             |
| `CURRENT_ELECTRICITY_USAGE`              | True     | string | _'Net power usage'_           | Current net power used (zero during delivery) in kWatt                                                                                                                                             |
| `CURRENT_ELECTRICITY_DELIVERY`           | True     | string | _'Net power delivery'_        | Current net power delivered (zero during import) in kWatt                                                                                                                                          |
| `ELECTRICITY_ACTIVE_TARIFF`              | True     | string | _'Active tariff'_             | The active tarrif (low of normal) values can be customized in `dsmr` section                                                                                                                       |
| `LONG_POWER_FAILURE_COUNT`               | True     | string | _'Long power failure count'_  | The number of 'long' power failures counted.                                                                                                                                                       |
| `SHORT_POWER_FAILURE_COUNT`              | True     | string | _'Short power failure count'_ | The number of 'shorted' power failures counted.                                                                                                                                                    |
| `VOLTAGE_SAG_L1_COUNT`                   | True     | string | _'Voltage sag count L1'_      | The number of power sags for fase L1 counted.                                                                                                                                                      |
| `VOLTAGE_SWELL_L1_COUNT`                 | True     | string | _'Voltage swell count L1'_    | The number of power swells for fase L1 counted.                                                                                                                                                    |
| `INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE` | True     | string | _'Net power usage L1'_        | Current net power used for fase L1 (zero during delivery) in Watt                                                                                                                                  |
| `INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE` | True     | string | _'Net power delivery L1'_     | Current net power delivered for fase L1 (zero during import) in Watt                                                                                                                               |
| `current_net_power`                      | True     | string | _'Current net power'_         | The current net power (can be negative) in Watt                                                                                                                                                    |
| `current_net_power_l1`                   | True     | string | _'Current net power L1'_      | The current net power for fase L1 (can be negative) in Watt                                                                                                                                        |
| `INSTANTANEOUS_VOLTAGE_L1`               | True     | string | _'Net voltage L1'_            | The current net voltage in Volts for Fase L1 (rounded to an integer)                                                                                                                               |
| `net_voltage_max`                        | True     | string | _'Net voltage max'_           | The current maximum net voltage in Volts over all fases (rounded to an integer). Can be used as `net_voltage_fallback` key to publish voltage to pvoutput when no solar voltage data is available. |
| `INSTANTANEOUS_CURRENT_L1`               | True     | string | _'Net current L1 DSMR'_       | The current for fase L1 in Ampère (rounded to a positive integer) directly from your smart meter.                                                                                                  |
| `net_current_l1`                         | True     | string | _'Net current L1'_            | The current for fase L1 in Ampère calculated using `current_net_power_l1` / `INSTANTANEOUS_VOLTAGE_L1`. This gives a more precise current. Value is negative during enery delivery.                |

> The entries for fase L1 are also applicable for fase L2 and L3 if the data is available`

##### DSMR gas data - entity name override

| key                     | optional | type   | default                   | description                                                           |
| ----------------------- | -------- | ------ | ------------------------- | --------------------------------------------------------------------- |
| `timestamp_gas`         | True     | string | _'Last update gas meter'_ | Timestamp of the last gas meter data published.                       |
| `gas_consumption_total` | True     | string | _'Gas total'_             | The total amount of m3 gas delivered since installation of the meter. |
| `gas_consumption_hour`  | True     | string | _'Gas consumption'_       | The current consumption of gas in m3/hour.                            |

The unit of measurement the used icon, MQTT device_class and value template file can be customized by updating the file `data_fields.json`.
Make a copy of the original file and configure the path under the `data_config` key in the general setting.

### PVoutput plugin settings in the section `output.pvoutput` of `apps.yaml` or `config.yaml`

Register a free acount and API key at https://pvoutput.org/register.jsp

| key                        | optional | type   | default  | description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -------------------------- | -------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sys_id`                   | True     | string | _(none)_ | Your unique system id, generated when creating an account at pvoutput.org. Enable publishing combined inverter data to this system id. You can also set `sys_id` in plant specific section to publish separate inverters.                                                                                                                                                                                                                                                                                                                                                        |
| `api_key`                  | False    | string | _(none)_ | Unique API access key generated at pvoutput.org                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `use_temperature`          | True     | bool   | `false`  | When set to true and `use_inverter_temperature` is not set, the temperature is obtained from OpenWeatherMap is submitted to pvoutput.org when logging the data.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `use_inverter_temperature` | True     | bool   | `false`  | When set to true and `use_temperature` is set, the inverter temperature is submitted to pvoutput.org when logging the data. Only the clients `tcpclient` and `localproxy` are supported.                                                                                                                                                                                                                                                                                                                                                                                         |
| `publish_voltage`          | True     | string | _(none)_ | The _fieldname_ key of the voltage property to use for pvoutput 'addstatus' publishing. When set to `'voltage_ac_max'`, the maximal inverter AC voltage over all fases is submitted to pvoutput.org when logging the data. Only the clients `tcpclient` and `localproxy` are supported. Supported values are `voltage_ac1`, `voltage_ac2`, `voltage_ac3` or `voltage_ac_max` or one ofe the DSMR voltage fields (INSTANTANEOUS_VOLTAGE_L1 / \_L2, \_L3 or net_voltage_max) if DSMR is available. The field `net_voltage_max` holds the highest voltage over all available fases. |
| `net_voltage_fallback `    | True     | string | _(none)_ | The _fieldname_ key of the voltage property to use for pvoutput 'addstatus' publishing in case no solar data is available during sun down. When set to `'net_voltage_max'`, the maximal net voltage over all fases is submitted as alternative to pvoutput.org. This key only makes sens when using the DSMR integration.                                                                                                                                                                                                                                                        |

### CSVoutput plugin settings in the section `output.csvoutput` in of `apps.yaml` or `config.yaml`

| key               | optional | type   | default  | description                                                                                                                               |
| ----------------- | -------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `csvfile`         | True     | string | _(none)_ | Used by the client `csvoutput`. The file and path to append or create for csv logging.                                                    |
| `separator`       | True     | string | _;_      | Used by the client `csvoutput`. The separator/delimiter to use between headers and fields. Use '\t' to use a tab as separator.            |
| `no_headers`      | True     | bool   | _False_  | Used by the client `csvoutput`. If `csvoutput` will not write headers to the `csvfile`.                                                   |
| `fields`          | True     | list   | _[*]_    | Used by the client `csvoutput`. A list of fields to log. The fields `date` and `time` are specials fields to log the local date and time. |
| `use_temperature` | True     | bool   | _False_  | When set to true the `temperature` field is set in the data set which can be logged. The value is obtained from OpenWeatherMap.           |

#### Default fields and additional fields

Default fields assignment [*]:

- `date`
- `time`
- `current_power`
- `today_energy`
- `total_energy`

The following additional fields are available if DSMR data can be matched with the aggregated solar data:

- `energy_direct_use`
- `energy_used_net`
- `power_direct_use`
- `power_consumption`
- `last_update_calc`

### InfluxDB plugin settings in the section `output.influxdb` in of `apps.yaml` or `config.yaml`

| key               | optional | type    | default           | description                                                                  |
| ----------------- | -------- | ------- | ----------------- | ---------------------------------------------------------------------------- |
| `host`            | True     | string  | `localhost`       | Hostname or fqdn of the InfluxDB server for logging.                         |
| `port`            | True     | integer | `8086`            | InfluxDB port to be used.                                                    |
| `ssl`             | True     | bool    | `false`           | Use SSL. Set to `true` if the URL starts with `https://`                     |
| `verify_ssl`      | True     | bool    | `true`            | By default a certificate is validated. Set to `false` to disable validation. |
| `ssl_ca_cert`     | True     | string  | _(none)_          | Set an alternative CA cert. (InfluxDB 2.x client only)                       |
| `org`             | True     | string  | _(none)_          | The InfluxDB2 organisation (InfluxDB 2.x only)                               |
| `bucket`          | True     | string  | _(none)_          | The InfluxDB2 bucket to write to (InfluxDB 2.x only)                         |
| `token`           | True     | string  | _(none)_          | The InfluxDB2 authentication token (InfluxDB 2.x only)                       |
| `use_temperature` | True     | bool    | `false`           | When set to true the temperature is obtained from OpenWeatherMap and logged. |
| `database`        | True     | string  | _omnikdatalogger_ | The InfluxDB database (InfluxDB 1.8x only)                                   |
| `username`        | True     | string  | _(none)_          | The InfluxDB username used for Basic authentication (InfluxDB 1.8x only)     |
| `password`        | True     | string  | _(none)_          | The InfluxDB password used for Basic authentication (InfluxDB 1.8x only)     |
| `jwt_token`       | True     | string  | _(none)_          | The InfluxDB webtoken for JSON Web Token authentication (InfluxDB 1.8x only) |

Logging to InfluxDB is supported with configuration settings from `data_fields.json` The file allows to customize measurement header and allows setting additional tags.
When using InfluxDB2, authentication is mandantory. Configure `org`, `bucket` and `token` to enable the InfluxDB v2 client.

#### OpenWeatherMap settings in the section `openweathermap` of `apps.yaml` or `config.yaml`

_(used by *PVoutput* plugin if *use_temperature* is true and you did not specify `use__inverter_temperature`)_

Visit https://openweathermap.org/price to obtain a (free) api key. The weather data is cached with een TTL of 300 seconds.

| key        | optional | type   | default                  | description                                                            |
| ---------- | -------- | ------ | ------------------------ | ---------------------------------------------------------------------- |
| `api_key`  | False    | string | _(none)_                 | Unique access key generated at openweathermap.org                      |
| `endpoint` | True     | string | `api.openweathermap.org` | FQDN of the API endpoint.                                              |
| `lon`      | False    | float  | _(none)_                 | Longitude for the weather location                                     |
| `lat`      | False    | float  | _(none)_                 | Latitude for the weather location                                      |
| `units`    | True     | string | `metric`                 | Can be _metric_ (for deg. Celsius) or _imperial_ (for deg. Fahrenheit) |

### Device attribute settings and relation with `data_fields.json`

Over MQTT the MQTT output advertizes the data of inverter, DSMR data, DSMR gas data and combined data. These groups bound to device attributes that wil be associated withe entities that are being published.
In Home Assistant throug MQTT auto discovery this will show as seperate devices for 'Omnik' entities, 'DSMR' entities, 'DSMR gas' entities and 'DSMR_omnik' (combined) entities.
All fields are configured with the pre installed `data_fields.json` file. This file holds an `asset` property for each field which corresponds with the asset class.
Each asset class must have one field with `"dev_cla": "timestamp"` which is the timestamp field for that class.
If you want to omit field in your output you can personalize `data_fields.json`. Do NOT customize the shared version of `data_fields.json` but make a copy and configure the aternative path
using the [`data_config` key in get general section](https://github.com/jbouwh/omnikdatalogger#general-settings-of-appsyaml-or-configini).
The `attributes` section allows to customize some asset class settings.

| key                        | optional | type   | default                                                           | description                                                                                                                                                                                                                           |
| -------------------------- | -------- | ------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `asset_classes`            | True     | list   | _omnik, omnik_dsmr, dsmr, dsmr_gas_                               | Access classes for device payload and grouping of entities.                                                                                                                                                                           |
| `asset.{asset_class}`      | True     | string | _see below_                                                       | Customize attribute payload for an asset class                                                                                                                                                                                        |
| `asset.omnik`              | True     | string | _inverter, plant_id, last_update_                                 | Standard attributes for published Omnik inverter data                                                                                                                                                                                 |
| `asset.omnik_dsmr`         | True     | string | _inverter, plant_id, EQUIPMENT_IDENTIFIER, terminal, last_update_ | Standard attributes for published combined DSMR and Omnik inverter data                                                                                                                                                               |
| `asset.dsmr                | True     | string | _EQUIPMENT_IDENTIFIER, terminal, timestamp_                       | Standard attributes for published DSMR data                                                                                                                                                                                           |
| `asset.dsmr_gas`           | True     | string | _EQUIPMENT_IDENTIFIER_GAS, terminal, timestamp_gas_               | Standard attributes for published DSMR gas data                                                                                                                                                                                       |
| `model.{asset_class}`      | True     | string | _see below_                                                       | Customize the model property of the device payload for an asset class                                                                                                                                                                 |
| `model.omnik`              | True     | string | _Omniksol_                                                        | Customize the model property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                           |
| `model.omnik_dsmr`         | True     | string | _Omnik data logger_                                               | Customize the model property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                      |
| `model.dsmr`               | True     | string | _DSRM electricity meter_                                          | Customize the model property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                                 |
| `model.dsmr_gas`           | True     | string | _DSRM gas meter_                                                  | Customize the model property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                     |
| `mf.{asset_class}`         | True     | string | _see below_                                                       | Customize the manufacturer property of the device payload for an asset class                                                                                                                                                          |
| `mf.omnik`                 | True     | string | _Omnik_                                                           | Customize the manufacturer property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                    |
| `mf.omnik_dsmr`            | True     | string | _JBsoft_                                                          | Customize the manufacturer property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                               |
| `mf.dsmr`                  | True     | string | _Netbeheer Nederland_                                             | Customize the manufacturer property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                          |
| `mf.dsmr_gas`              | True     | string | _Netbeheer Nederland_                                             | Customize mthe anufacturer property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                              |
| `identifier.{asset_class}` | True     | string | _see below_                                                       | Customize the identifier property of the device payload for an asset class. This property should be unique when using a configuration with more DSMR meters or plants The identifier will have the format {asset*class}*{identifier}. |
| `identifier.omnik`         | True     | string | _plant_id_                                                        | Customize the identifier property of the device payload for the asset class `omnik` (Solar data)                                                                                                                                      |
| `identifier.omnik_dsmr`    | True     | string | _plant_id_                                                        | Customize the identifier property of the device payload for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                 |
| `identifier.dsmr`          | True     | string | _EQUIPMENT_IDENTIFIER_                                            | Customize the identifier property of the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                            |
| `identifier.dsmr_gas`      | True     | string | _EQUIPMENT_IDENTIFIER_GAS_                                        | Customize the property of the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                           |
| `devicename.{asset_class}` | True     | string | _see below_                                                       | Customize the device name for an asset class. This attribute replaces the previous decrepated `device_name` setting in the `output.mqtt` section.                                                                                     |
| `devicename.omnik`         | True     | string | _Inverter_                                                        | Customize the device name for the asset class `omnik` (Solar data)                                                                                                                                                                    |
| `devicename.omnik_dsmr`    | True     | string | _Omnik_data_logger_                                               | Customize the device name for the asset class `omnik_dsmr` (DSMR + Solar combined data)                                                                                                                                               |
| `devicename.dsmr`          | True     | string | _DSMR_electicity_meter_                                           | Customize the device name the device payload for the asset class `dsmr` (DSMR electricity data)                                                                                                                                       |
| `devicename.dsmr_gas`      | True     | string | _DSMR_gasmeter_                                                   | Customize the device name the device payload for the asset class `dsmr_gas` (DSMR gas data)                                                                                                                                           |

## Configuration using config.ini

Using a `config.ini` config file is no longer supported! Move your config a .yaml file in stead.

## Scheduled Run (commandline or using systemd)

You've got your default options to schedule this logger, but I included a `systemd` service file to run this as a service on Linux.

> **PS**: I'm using `Ubuntu 18.04 LTS` but Debian buster should also work.

First, install this thing (~ using Python 3.7+ !!!)

> If you don't have `Python3.7+` installed, do that first (~ don't forget to install `python3-pip` as well)

```
#### Create a to download the scripts
$ git clone https://github.com/jbouwh/omnikdatalogger
> onmiklogger.py can be found in the `./apps` folder
# check if properly installed
$ omniklogger.py -h
usage: omniklogger.py [-h] [--settings FILE] [--interval n] [-l]

optional arguments:
  -h, --help     show this help message and exit
  --settings FILE  Path to yaml configuration file
  --interval n   Execute every n seconds
  -l {DEBUG,INFO,WARNING,ERROR}, --loglevel {DEBUG,INFO,WARNING,ERROR} Loglevel
```

An example systemd script is available from `scripts/omnikdatalogger.service`. Copy it so you can customize it to your use.

Check the folowing line in this file in the script.

```
ExecStart=/usr/bin/python3 /usr/local/bin/omniklogger.py --settings /etc/omnik/config.yaml --interval 360
```

Make sure the interval is as desired and that the path of omniklogger.py is correct

Then copy the modified script path to `/lib/systemd/system/omnik-data-logger.service`

Next, enable and start service:

```
$ systemd enable omnikdatalogger
Created symlink /etc/systemd/system/multi-user.target.wants/omnikdatalogger.service → /lib/systemd/system/omnikdatalogger.service.
$ systemd start omnikdatalogger
```

Check if `omnikdatalogger.service` is running correctly:

```
$ systemd status omnikdatalogger
● omnikdatalogger.service - Omnik Data Logger service
   Loaded: loaded (/lib/systemd/system/omnikdatalogger.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-06-18 06:55:08 UTC; 4min 36s ago
 Main PID: 2445 (python3)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/omnikdatalogger.service
           └─2445 /usr/bin/python3 /usr/local/bin/omniklogger.py --settings /etc/omnik/config.yaml --interval 300
```


%prep
%autosetup -n omnikdatalogger-1.13.0

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-omnikdatalogger -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 1.13.0-1
- Package Spec generated