@@ -26,38 +26,39 @@ Besides allowing the API to listen for requests, you will also need send your AP
26
26
The API key can be found on the same page as in the screenshot above.
27
27
The application generates one for you initially, but feel free to alter the API key when required.
28
28
29
- You should pass it in the header of every API call. The header should be defined as `` X-AUTHKEY `` with value `` <key> ``. See below for an example.
30
-
31
- Alternatively, since `` v2.1.0 ``, you can use `` Authorization `` with value ``Token <key> ``.
29
+ You should pass it in the header of every API call. See below for an example.
30
+ Since `` v2.1.0 ``, you should not longer use `` X-AUTHKEY ``.
31
+ Use `` Authorization `` with value ``Token <key> `` instead .
32
32
33
33
Examples
34
34
~~~~~~~~
35
35
36
36
Using ``cURL ``::
37
37
38
- curl http://YOUR-DSMR-URL/api/v1/datalogger/dsmrreading \
38
+ # Don't forget to replace 'YOUR-DSMR-URL' and 'YOUR-API-KEY' with your own values.
39
+ curl http://YOUR-DSMR-URL/api/v1/datalogger/dsmrreading \
39
40
-d 'telegram=xxxxx' \
40
- -H 'X-AUTHKEY: < YOUR-API-KEY> '
41
+ -H 'Authorization: Token YOUR-API-KEY'
41
42
42
- # Or use
43
+ # Or use
43
44
44
- curl http://YOUR-DSMR-URL/api/v1/datalogger/dsmrreading \
45
+ curl http://YOUR-DSMR-URL/api/v1/datalogger/dsmrreading \
45
46
-d 'telegram=xxxxx' \
46
- -H 'Authorization: Token < YOUR-API-KEY> '
47
+ -H 'Authorization: Token YOUR-API-KEY'
47
48
48
49
Using ``requests ``::
49
50
50
- requests.post(
51
+ requests.post(
51
52
'http://YOUR-DSMR-URL/api/v1/datalogger/dsmrreading',
52
- headers={'X-AUTHKEY ': '< YOUR-API-KEY> '},
53
+ headers={'Authorization ': 'Token YOUR-API-KEY'},
53
54
data={'telegram': 'xxxxx'},
54
- )
55
+ )
55
56
56
- # Or use
57
+ # Or use
57
58
58
- requests.post(
59
+ requests.post(
59
60
'http://YOUR-DSMR-URL/api/v1/datalogger/dsmrreading',
60
- headers={'Authorization': 'Token < YOUR-API-KEY> '},
61
+ headers={'Authorization': 'Token YOUR-API-KEY'},
61
62
data={'telegram': 'xxxxx'},
62
63
)
63
64
@@ -127,7 +128,7 @@ Example
127
128
# Register telegram by simply sending it to the application with a POST request.
128
129
response = requests.post(
129
130
'http://YOUR-DSMR-URL/api/v1/datalogger/dsmrreading',
130
- headers={'X-AUTHKEY ': 'YOUR-API-KEY'},
131
+ headers={'Authorization ': 'Token YOUR-API-KEY'},
131
132
data={'telegram': telegram_string},
132
133
)
133
134
@@ -229,10 +230,11 @@ Example
229
230
230
231
Using **cURL ** (commandline)::
231
232
233
+ # Don't forget to replace 'YOUR-DSMR-URL' and 'YOUR-API-KEY' with your own values.
232
234
# Please note that the plus symbol "+" has been replaced by "%2B" here, to make it work for cURL.
233
235
curl http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading \
234
236
-d 'timestamp=2017-04-15T00:00:00%2B02&electricity_currently_delivered=1.5&electricity_currently_returned=0.025&electricity_delivered_1=2000&electricity_delivered_2=3000&electricity_returned_1=0&electricity_returned_2=0' \
235
- -H 'X-AUTHKEY: YOUR-API-KEY' | python -m json.tool
237
+ -H 'Authorization: Token YOUR-API-KEY' | python -m json.tool
236
238
237
239
238
240
Using **requests ** (Python)::
@@ -242,7 +244,7 @@ Using **requests** (Python)::
242
244
243
245
response = requests.post(
244
246
'http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading',
245
- headers={'X-AUTHKEY ': 'YOUR-API-KEY'},
247
+ headers={'Authorization ': 'Token YOUR-API-KEY'},
246
248
data={
247
249
'electricity_currently_delivered': 1.500,
248
250
'electricity_currently_returned': 0.025,
@@ -321,8 +323,9 @@ This demonstrates how to fetch all readings stored, without using any of the par
321
323
322
324
Using **cURL ** (commandline)::
323
325
324
- curl 'http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading' \
325
- -H 'X-AUTHKEY: YOUR-API-KEY' | python -m json.tool
326
+ # Don't forget to replace 'YOUR-DSMR-URL' and 'YOUR-API-KEY' with your own values.
327
+ curl 'http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading' \
328
+ -H 'Authorization: Token YOUR-API-KEY' | python -m json.tool
326
329
327
330
328
331
Using **requests ** (Python)::
@@ -332,7 +335,7 @@ Using **requests** (Python)::
332
335
333
336
response = requests.get(
334
337
'http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading',
335
- headers={'X-AUTHKEY ': 'YOUR-API-KEY'},
338
+ headers={'Authorization ': 'Token YOUR-API-KEY'},
336
339
)
337
340
338
341
if response.status_code != 200:
@@ -380,8 +383,9 @@ This demonstrates how to fetch the latest reading stored. Therefor we request al
380
383
381
384
Using **cURL ** (commandline)::
382
385
386
+ # Don't forget to replace 'YOUR-DSMR-URL' and 'YOUR-API-KEY' with your own values.
383
387
curl 'http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading?ordering=-timestamp&limit=1' \
384
- -H 'X-AUTHKEY: YOUR-API-KEY' | python -m json.tool
388
+ -H 'Authorization: Token YOUR-API-KEY' | python -m json.tool
385
389
386
390
387
391
Using **requests ** (Python)::
@@ -391,7 +395,7 @@ Using **requests** (Python)::
391
395
392
396
response = requests.get(
393
397
'http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading?ordering=-timestamp&limit=1',
394
- headers={'X-AUTHKEY ': 'YOUR-API-KEY'},
398
+ headers={'Authorization ': 'Token YOUR-API-KEY'},
395
399
)
396
400
397
401
if response.status_code != 200:
@@ -437,9 +441,10 @@ This demonstrates how to fetch all readings within a month. We limit the search
437
441
438
442
Using **cURL ** (commandline)::
439
443
444
+ # Don't forget to replace 'YOUR-DSMR-URL' and 'YOUR-API-KEY' with your own values.
440
445
# Note that the whitespace in the timestamps has been converted to '%20' for cURL.
441
446
curl 'http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading?timestamp__gte=2017-02-01%2000:00:00×tamp__lte=2017-03-01%2000:00:00' \
442
- -H 'X-AUTHKEY: YOUR-API-KEY' | python -m json.tool
447
+ -H 'Authorization: Token YOUR-API-KEY' | python -m json.tool
443
448
444
449
445
450
Using **requests ** (Python)::
@@ -449,7 +454,7 @@ Using **requests** (Python)::
449
454
450
455
response = requests.get(
451
456
'http://YOUR-DSMR-URL/api/v2/statistics/day?timestamp__gte=2017-02-01 00:00:00×tamp__lte=2017-03-01 00:00:00',
452
- headers={'X-AUTHKEY ': 'YOUR-API-KEY'},
457
+ headers={'Authorization ': 'Token YOUR-API-KEY'},
453
458
)
454
459
455
460
if response.status_code != 200:
@@ -460,7 +465,7 @@ Using **requests** (Python)::
460
465
461
466
**Result **::
462
467
463
- # This should present you a set of all readings in the month we selected.
468
+ # This should present you a set of all readings in the month selected.
464
469
{
465
470
"count": 240968,
466
471
"next": "http://YOUR-DSMR-URL/api/v2/datalogger/dsmrreading?limit=25&offset=25×tamp__gte=2017-02-01+00%3A00%3A00×tamp__lte=2017-03-01+00%3A00%3A00",
@@ -495,7 +500,187 @@ Using **requests** (Python)::
495
500
496
501
497
502
----
498
-
503
+
504
+
505
+ ``GET `` - ``/datalogger/meter-statistics ``
506
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
507
+
508
+ Retrieve meter statistics.
509
+
510
+ .. note ::
511
+
512
+ This endpoint was added in DSMR-reader ``v3.1 ``
513
+
514
+
515
+ URI
516
+ ~~~
517
+ Full path: ``/api/v2/datalogger/meter-statistics ``
518
+
519
+
520
+ Parameters
521
+ ~~~~~~~~~~
522
+ None.
523
+
524
+
525
+ Response
526
+ ~~~~~~~~
527
+ ``HTTP 200 `` on success. Body contains the data in JSON format. Any other status code on failure.
528
+
529
+
530
+ Example
531
+ ~~~~~~~
532
+
533
+ Using **cURL ** (commandline)::
534
+
535
+ # Don't forget to replace 'YOUR-DSMR-URL' and 'YOUR-API-KEY' with your own values.
536
+ curl http://YOUR-DSMR-URL/api/v2/datalogger/meter-statistics \
537
+ -H 'Authorization: Token YOUR-API-KEY' | python -m json.tool
538
+
539
+
540
+ **Result **::
541
+
542
+ {
543
+ "id": 1,
544
+ "timestamp": "2020-01-15T20:13:40+01:00",
545
+ "dsmr_version": "40",
546
+ "electricity_tariff": 1,
547
+ "power_failure_count": 3,
548
+ "long_power_failure_count": 0,
549
+ "voltage_sag_count_l1": 1,
550
+ "voltage_sag_count_l2": 2,
551
+ "voltage_sag_count_l3": 3,
552
+ "voltage_swell_count_l1": 0,
553
+ "voltage_swell_count_l2": 0,
554
+ "voltage_swell_count_l3": 0,
555
+ "rejected_telegrams": 99,
556
+ "latest_telegram": "/XMX5LGBBFFB123456789\r\n\r\n1-3:0.2.8(40)\r\n0-0:1.0.0(200115201340W)\r\n0-0:96.1.1(12345678901234567890123456789000)\r\n1-0:1.8.1(007952.261*kWh)\r\n1-0:2.8.1(000000.000*kWh)\r\n1-0:1.8.2(004771.357*kWh)\r\n1-0:2.8.2(000000.000*kWh)\r\n0-0:96.14.0(0001)\r\n1-0:1.7.0(02.507*kW)\r\n1-0:2.7.0(00.000*kW)\r\n0-0:96.7.21(00003)\r\n0-0:96.7.9(00000)\r\n1-0:99.97.0(0)(0-0:96.7.19)\r\n1-0:32.32.0(00001)\r\n1-0:52.32.0(00002)\r\n1-0:72.32.0(00003)\r\n1-0:32.36.0(00000)\r\n1-0:52.36.0(00000)\r\n1-0:72.36.0(00000)\r\n0-0:96.13.1()\r\n0-0:96.13.0()\r\n1-0:32.7.0(225.0*V)\r\n1-0:52.7.0(232.1*V)\r\n1-0:72.7.0(233.2*V)\r\n1-0:31.7.0(000*A)\r\n1-0:51.7.0(000*A)\r\n1-0:71.7.0(001*A)\r\n1-0:21.7.0(01.407*kW)\r\n1-0:41.7.0(00.765*kW)\r\n1-0:61.7.0(00.334*kW)\r\n1-0:22.7.0(00.000*kW)\r\n1-0:42.7.0(00.000*kW)\r\n1-0:62.7.0(00.000*kW)\r\n!013B"
557
+ }
558
+
559
+
560
+ .. warning ::
561
+
562
+ Please note that all timestamps **returned ** are in **UTC (CET -1 / CEST -2) **. This is indicated as well by the timestamps ending with a 'Z' (Zulu timezone).
563
+
564
+
565
+ ----
566
+
567
+
568
+ ``PATCH `` - ``/datalogger/meter-statistics ``
569
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
570
+
571
+ Manually updates any meter statistics fields.
572
+
573
+ .. note ::
574
+
575
+ This endpoint was added in DSMR-reader ``v3.1 ``
576
+
577
+
578
+ .. warning ::
579
+
580
+ You should **not use this if you're using the v1 datalogger to push your telegrams **, as they will collide and overwrite each other's data!
581
+
582
+
583
+ URI
584
+ ~~~
585
+ Full path: ``/api/v2/datalogger/meter-statistics ``
586
+
587
+
588
+ Parameters
589
+ ~~~~~~~~~~
590
+ Since this is a ``PATCH `` operation, **all parameters are optional **.
591
+
592
+ - ``timestamp `` (*datetime *) - Timestamp indicating the last update. The builtin datalogger uses the timestamp of the telegram for this.
593
+ - ``dsmr_version `` (*string *) - DSMR protocol version string. Should be something like ``42 `` (4.2) or ``50 `` (5.0)
594
+ - ``power_failure_count `` (*int *) - Number of power failures in any phase
595
+ - ``long_power_failure_count `` (*int *) - Number of long power failures in any phase
596
+ - ``voltage_sag_count_l1 `` (*int *) - Number of voltage sags/dips in phase L1
597
+ - ``voltage_sag_count_l2 `` (*int *) - Number of voltage sags/dips in phase L2 (polyphase meters only)
598
+ - ``voltage_sag_count_l3 `` (*int *) - Number of voltage sags/dips in phase L3 (polyphase meters only)
599
+ - ``voltage_swell_count_l1 `` (*int *) - Number of voltage swells in phase L1
600
+ - ``voltage_swell_count_l2 `` (*int *) - Number of voltage swells in phase L2 (polyphase meters only)
601
+ - ``voltage_swell_count_l3 `` (*int *) - Number of voltage swells in phase L3 (polyphase meters only)
602
+ - ``rejected_telegrams `` (*int *) - Number of rejected telegrams due to invalid CRC checksum
603
+ - ``latest_telegram `` (*string *) - The latest telegram succesfully read
604
+
605
+ All parameters, except for ``timestamp `` and ``rejected_telegrams `` are **nullable **. Send an empty value to make them ``null ``.
606
+
607
+ .. note ::
608
+
609
+ **datetime format ** = ``YYYY-MM-DDThh:mm[:ss][+HH:MM|-HH:MM|Z] ``, i.e.: ``2017-01-01T12:00:00+01 `` (CET), ``2017-04-15T12:00:00+02 `` (CEST) or ``2017-04-15T100:00:00Z `` (UTC).
610
+
611
+
612
+ Response
613
+ ~~~~~~~~
614
+ ``HTTP 200 `` on success. Body contains the updated data in JSON format. Any other status code on failure.
615
+
616
+
617
+ Example
618
+ ~~~~~~~
619
+ **Data ** to update::
620
+
621
+ timestamp: 2020-01-15T12:34:56+01
622
+ dsmr_version: '50'
623
+ power_failure_count: 1
624
+ voltage_sag_count_l1: 5
625
+ voltage_swell_count_l1: 6
626
+ latest_telegram: null
627
+
628
+
629
+ Using **cURL ** (commandline)::
630
+
631
+ # Don't forget to replace 'YOUR-DSMR-URL' and 'YOUR-API-KEY' with your own values.
632
+ # Please note that the plus symbol "+" has been replaced by "%2B" here, to make it work for cURL.
633
+ curl --request PATCH http://YOUR-DSMR-URL/api/v2/datalogger/meter-statistics \
634
+ -d 'timestamp=2020-01-15T12:34:56%2B01&dsmr_version=50&power_failure_count=1&voltage_sag_count_l1=5&voltage_swell_count_l1=6&latest_telegram=' \
635
+ -H 'Authorization: Token YOUR-API-KEY' | python -m json.tool
636
+
637
+
638
+ Using **requests ** (Python)::
639
+
640
+ import requests
641
+ import json
642
+
643
+ response = requests.patch(
644
+ 'http://YOUR-DSMR-URL/api/v2/datalogger/meter-statistics',
645
+ headers={'Authorization': 'Token YOUR-API-KEY'},
646
+ data={
647
+ 'timestamp': '2020-01-15T12:34:56+01'
648
+ 'dsmr_version': '50'
649
+ 'power_failure_count': 1
650
+ 'voltage_sag_count_l1': 5
651
+ 'voltage_swell_count_l1': 6
652
+ 'latest_telegram': None
653
+ }
654
+ )
655
+
656
+ if response.status_code != 200:
657
+ print('Error: {}'.format(response.text))
658
+ else:
659
+ print('Updated: {}'.format(json.loads(response.text)))
660
+
661
+
662
+ **Result **::
663
+
664
+ {
665
+ "id": 1,
666
+ "timestamp": "2020-01-15T12:34:56+01:00",
667
+ "dsmr_version": "50",
668
+ "electricity_tariff": 1,
669
+ "power_failure_count": 1,
670
+ "long_power_failure_count": 0,
671
+ "voltage_sag_count_l1": 5,
672
+ "voltage_sag_count_l2": 2,
673
+ "voltage_sag_count_l3": 3,
674
+ "voltage_swell_count_l1": 6,
675
+ "voltage_swell_count_l2": 0,
676
+ "voltage_swell_count_l3": 0,
677
+ "rejected_telegrams": 99,
678
+ "latest_telegram": null
679
+ }
680
+
681
+
682
+ ----
683
+
499
684
500
685
``GET `` - ``consumption/electricity ``
501
686
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -916,4 +1101,3 @@ Example
916
1101
"days_since": 1
917
1102
}
918
1103
}
919
-
0 commit comments