kpoppel / homeassistant-novafos

Homeassistant wrapper around the Novafos KMD water metering data warehouse.
Apache License 2.0
10 stars 3 forks source link

Support for District Heating #12

Closed klgn closed 1 year ago

klgn commented 1 year ago

Hi,

My Energy Supplier Fors also uses the KMD data API. They also do provide my District Heating consumption, which I would like to see added to this plugin. I did some deep diving into the requests, and I can see that the ConsumptionTypeId is 5 for District Heating and then ConsumptionTypeName is Fjernvarme.

kpoppel commented 1 year ago

To do this I would need a few things:

This goes for all 'zoom levels' (year, month, day, hour).

I can see in my view that there is different options for 'source' (I only have water), so this might not be a large thing. The setup would also need to be updated to include the type of sensor to create, but that is also possible.

klgn commented 1 year ago

How should I provide that to you? Via files here or do you want access to my account?

kpoppel commented 1 year ago

If you are okay with using the developer tools in Chrome/Edge you can dump everything here. The important bits to get the network logs are these:

I expect they will look very much like the water metering data, but better get this verified. It is a lot of copy/paste I know.

If you are comfortable with letting me use your account for a bit you may also do this to make things easier. You can use this mail-address for this: kpoppel.at.github@gmail.com . I will of-course not do bad things with it.

klgn commented 1 year ago

Alright, here goes GET consumption Headers: General:

Request URL: https://minforsyningplugin2webapi.kmd.dk/api/zoomLevel/consumption
Request Method: GET
Status Code: 200 OK
Remote Address: 131.165.91.205:443
Referrer Policy: strict-origin-when-cross-orig

Response Headers:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://www.fors.dk
Access-Control-Expose-Headers: Request-Context
Content-Length: 143
Content-Type: application/json; charset=utf-8
Date: Thu, 27 Oct 2022 13:06:01 GMT
Request-Context: appId=cid-v1:9ec78e13-d40c-4bb7-b7e7-b7e6a0aff415
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET

Request Headers

t: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,da;q=0.8
Access-Control-Allow-Headers: Content-Type
Authorization: Den får du ikke...
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
Customer-Id: 16848678
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Host: minforsyningplugin2webapi.kmd.dk
Origin: https://www.fors.dk
Pragma: no-cache
Referer: https://www.fors.dk/
sec-ch-ua: "Chromium";v="106", "Not;A=Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Linux"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.3

Response [{"Name":"År","Type":0,"Order":0},{"Name":"Måned","Type":1,"Order":1},{"Name":"Dage","Type":2,"Order":2},{"Name":"Timer","Type":3,"Order":3}]

GET availableTimeSeriesPeriods Headers: General:

Request URL: https://minforsyningplugin2webapi.kmd.dk/api/consumption/availableTimeSeriesPeriods
Request Method: GET
Status Code: 200 OK
Remote Address: 131.165.91.205:443
Referrer Policy: strict-origin-when-cross-origin

Request headers:

Request URL: https://minforsyningplugin2webapi.kmd.dk/api/consumption/availableTimeSeriesPeriods
Request Method: GET
Status Code: 200 OK
Remote Address: 131.165.91.205:443
Referrer Policy: strict-origin-when-cross-origin
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://www.fors.dk
Access-Control-Expose-Headers: Request-Context
Content-Length: 725
Content-Type: application/json; charset=utf-8
Date: Thu, 27 Oct 2022 13:06:01 GMT
Request-Context: appId=cid-v1:9ec78e13-d40c-4bb7-b7e7-b7e6a0aff415
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,da;q=0.8
Access-Control-Allow-Headers: Content-Type
Authorization: Den får du ikke...
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
Customer-Id: 16848678
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Host: minforsyningplugin2webapi.kmd.dk
Origin: https://www.fors.dk
Pragma: no-cache
Referer: https://www.fors.dk/
sec-ch-ua: "Chromium";v="106", "Not;A=Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Linux"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (X11;

Response Headers:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://www.fors.dk
Access-Control-Expose-Headers: Request-Context
Content-Length: 725
Content-Type: application/json; charset=utf-8
Date: Thu, 27 Oct 2022 13:06:01 GMT
Request-Context: appId=cid-v1:9ec78e13-d40c-4bb7-b7e7-b7e6a0aff415
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET

Response: [{"MeasurementPointId":220705,"UnitId":2110,"RangeType":0,"MinDate":"2019-10-11T00:00:00","MaxDate":"2022-10-25T00:00:00"},{"MeasurementPointId":220705,"UnitId":2116,"RangeType":0,"MinDate":"2019-10-11T00:00:00","MaxDate":"2022-10-25T00:00:00"},{"MeasurementPointId":220705,"UnitId":8047,"RangeType":0,"MinDate":"2019-10-11T00:00:00","MaxDate":"2022-10-25T00:00:00"},{"MeasurementPointId":220705,"UnitId":8048,"RangeType":0,"MinDate":"2019-10-11T00:00:00","MaxDate":"2022-10-25T00:00:00"},{"MeasurementPointId":237872,"UnitId":2119,"RangeType":0,"MinDate":"2019-10-11T00:00:00","MaxDate":"2022-10-25T00:00:00"},{"MeasurementPointId":0,"UnitId":0,"RangeType":1,"MinDate":"2018-01-01T00:00:00","MaxDate":"2022-12-31T00:00:00"}]

POST customerActiveMeters Headers: General:

Request URL: https://minforsyningplugin2webapi.kmd.dk/api/meter/customerActiveMeters
Request Method: POST
Status Code: 200 OK
Remote Address: 131.165.91.205:443
Referrer Policy: strict-origin-when-cross

Response Headers:

Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://www.fors.dk
Access-Control-Expose-Headers: Request-Context
Content-Length: 943
Content-Type: application/json; charset=utf-8
Date: Thu, 27 Oct 2022 13:06:02 GMT
Request-Context: appId=cid-v1:9ec78e13-d40c-4bb7-b7e7-b7e6a0aff415
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
X-Powered-By: ASP

Request Headers:

Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,da;q=0.8
Access-Control-Allow-Headers: Content-Type
Authorization: Den får du ikke...
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 21
Content-Type: application/json
Customer-Id: 16848678
Host: minforsyningplugin2webapi.kmd.dk
Origin: https://www.fors.dk
Pragma: no-cache
Referer: https://www.fors.dk/
sec-ch-ua: "Chromium";v="106", "Not;A=Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Linux"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 

Payload: {"IncludeUnits":true} Response: [{"InstallationPeriodId":16319685,"InstallationId":26638,"LocationId":100008,"Location":"Kælder","MeasurementPointId":237872,"MeasurementPointType":"","MeasurementPointNumber":"576666666600111890","MeterId":16325684,"ConsumptionTypeId":6,"ConsumptionTypeName":"Vand","IsRemoteRead":true,"IsActive":true,"MeterNumber":"74717715","MeterTypeId":16192931,"MeasurementPointTypeCodeText":"","Units":[{"Id":2119,"Name":"m³","Description":"Vand","Decimals":2,"Order":9}]},{"InstallationPeriodId":16319708,"InstallationId":26639,"LocationId":100008,"Location":"Kælder","MeasurementPointId":220705,"MeasurementPointType":"","MeasurementPointNumber":"575555555500066387","MeterId":16326699,"ConsumptionTypeId":5,"ConsumptionTypeName":"Fjernvarme","IsRemoteRead":true,"IsActive":true,"MeterNumber":"69982133","MeterTypeId":7927,"MeasurementPointTypeCodeText":"","Units":[{"Id":2110,"Name":"MWh","Description":"Megawatt timer","Decimals":3,"Order":8}]}]

POST consumptionTimeSeries Headers: General:

Request URL: https://minforsyningplugin2webapi.kmd.dk/api/consumption/consumptionTimeSeries
Request Method: POST
Status Code: 200 OK
Remote Address: 131.165.91.205:443
Referrer Policy: strict-origin-when-cross

Response:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://www.fors.dk
Access-Control-Expose-Headers: Request-Context
Content-Length: 1033
Content-Type: application/json; charset=utf-8
Date: Thu, 27 Oct 2022 13:06:03 GMT
Request-Context: appId=cid-v1:9ec78e13-d40c-4bb7-b7e7-b7e6a0aff415
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
X-Powered-By: ASP

Request:

Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,da;q=0.8
Access-Control-Allow-Headers: Content-Type
Authorization: Den får du ikke...
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 244
Content-Type: application/json
Customer-Id: 16848678
Host: minforsyningplugin2webapi.kmd.dk
Origin: https://www.fors.dk
Pragma: no-cache
Referer: https://www.fors.dk/
sec-ch-ua: "Chromium";v="106", "Not;A=Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Linux"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Payload: {"MeasurementPointId":220705,"InstallationId":26639,"ZoomLevel":0,"PriceData":false,"DateFrom":"2018-12-31T23:00:00.000Z","DateTo":"2022-12-30T23:00:00.000Z","Unit":{"Id":2110,"Name":"MWh","Description":"Megawatt timer","Decimals":3,"Order":8}} Response: {"SheetName":null,"Series":[{"Data":[{"DateFrom":"2019-01-01T00:00:00","DateTo":"2019-12-31T23:59:59","Value":4.889,"UnitName":"MWh","Label":"2019","IsComplete":true,"IsSettlement":false},{"DateFrom":"2020-01-01T00:00:00","DateTo":"2020-12-31T23:59:59","Value":14.469,"UnitName":"MWh","Label":"2020","IsComplete":true,"IsSettlement":false},{"DateFrom":"2021-01-01T00:00:00","DateTo":"2021-12-31T23:59:59","Value":18.107,"UnitName":"MWh","Label":"2021","IsComplete":true,"IsSettlement":false},{"DateFrom":"2022-01-01T00:00:00","DateTo":"2022-12-31T23:59:59","Value":10.26,"UnitName":"MWh","Label":"2022","IsComplete":false,"IsSettlement":false}],"Label":null}],"Total":{"Value":47.725,"DateFrom":"2019-01-01T00:00:00+01:00","DateTo":"2022-12-31T00:00:00+01:00"},"Average":{"Value":12.488,"DateFrom":"2019-01-01T00:00:00","DateTo":"2021-12-31T23:59:59"},"Maximum":{"Value":18.107,"DateFrom":"2021-01-01T00:00:00","DateTo":"2021-12-31T23:59:59"},"Minimum":{"Value":4.889,"DateFrom":"2019-01-01T00:00:00","DateTo":"2019-12-31T23:59:59"}}

I hope this satisfies your needs. Otherwise give me a shout

kpoppel commented 1 year ago

@klgn - have you had a chance to try the version 4.1.0? To the best of my (lack of proper) testing, this release should automatically pick up both water and regional heating data and create the needed sensors.

kpoppel commented 1 year ago

Closing as no further action taken.