carohauta / oma-helen-ha-integration

Home Assistant integration for Oma Helen data
MIT License
35 stars 6 forks source link

Electricity consumption with non-Helen contract #6

Closed Nezz closed 1 year ago

Nezz commented 1 year ago

I'd like to use this integration to feed my overall electricity consumption into the energy dashboard. However, I buy electricity from another company. Helen delivers the electricity though, so on Oma Helen I'm able to see my consumption. Would it be possible to add support for that?

The API request seems to be this:

https://api.omahelen.fi/v10/measurements/electricity-transfer?begin=2023-04-12T21:00:00.000Z&end=2023-05-13T20:59:59.999Z&resolution=day&delivery_site_id=123456&allow_transfer=true

Example response:

``` { "intervals":{ "electricity_transfer":[ { "start":"2023-04-12T21:00:00+00:00", "stop":"2023-05-13T20:59:59.999000+00:00", "resolution_s":86400, "resolution":"day", "unit":"kWh", "measurements":[ { "value":9.629999999999995, "status":"valid" }, { "value":7.140000000000001, "status":"valid" }, { "value":14.540000000000006, "status":"valid" }, { "value":10.709999999999994, "status":"valid" }, { "value":10.219999999999999, "status":"valid" }, { "value":6.110000000000014, "status":"valid" }, { "value":14.419999999999987, "status":"valid" }, { "value":13.699999999999989, "status":"valid" }, { "value":7.25, "status":"valid" }, { "value":13.660000000000025, "status":"valid" }, { "value":14.109999999999985, "status":"valid" }, { "value":10.909999999999997, "status":"valid" }, { "value":7.189999999999998, "status":"valid" }, { "value":12.659999999999997, "status":"valid" }, { "value":13.730000000000018, "status":"valid" }, { "value":9.730000000000018, "status":"valid" }, { "value":8.029999999999973, "status":"valid" }, { "value":21.94999999999999, "status":"valid" }, { "value":18.08000000000004, "status":"valid" }, { "value":13.369999999999948, "status":"valid" }, { "value":13.689999999999998, "status":"valid" }, { "value":12.650000000000034, "status":"valid" }, { "value":15.5, "status":"valid" }, { "value":14.480000000000018, "status":"valid" }, { "value":15.859999999999957, "status":"valid" }, { "value":10.759999999999991, "status":"valid" }, { "value":8.390000000000043, "status":"valid" }, { "value":10.359999999999957, "status":"valid" }, { "value":16.610000000000014, "status":"valid" }, { "value":0.0, "status":"invalid" }, { "value":0.0, "status":"invalid" } ] } ] } } ```

The delivery_site_id and transfer prices can be grabbed from this API:

https://api.omahelen.fi/v10/contract/list?include_transfer=true&update=true&include_products=true

Example response (heavily redacted):

``` { "contracts":[ { "delivery_site":{ "grid_company_name":"Helen Sähköverkko", "id":123456 }, "domain":"electricity-transfer", "end_date":null, "products":[ { "company":"HSV", "components":[ { "id":"2011P", "name":"Perusmaksu", "localized_name":{ "fi":"Perusmaksu", "sv":"Grundavgift", "en":"Basic charge" }, "price":5.51, "price_without_vat":4.44, "price_unit":"eur/kk", "localized_price_unit":{ "fi":"eur/kk", "sv":"eur/månad", "en":"eur/month" }, "is_base_price":true, "is_valid_price":true, "component_description":null }, { "id":"2011E", "name":"Siirtomaksu", "localized_name":{ "fi":"Siirtomaksu", "sv":"Överföringsavgift", "en":"Distribution tariff" }, "price":4.07, "price_without_vat":3.28, "price_unit":"c/kWh", "localized_price_unit":{ "fi":"c/kWh", "sv":"c/kWh", "en":"c/kWh" }, "is_base_price":false, "is_valid_price":true, "component_description":null }, { "id":"electricity_tax", "name":"Sähkövero", "localized_name":{ "fi":"Sähkövero", "sv":"Elskatt", "en":"Electricity tax" }, "price":2.79372, "price_without_vat":2.253, "price_unit":"c/kWh", "localized_price_unit":{ "fi":"c/kWh", "sv":"c/kWh", "en":"c/kWh" }, "is_base_price":false, "is_valid_price":true, "component_description":{ "fi":"Sähkövero peritään kaikesta jakeluverkon kautta asiakkaille jaetusta sähköenergiasta. Sähkön valmistevero ja huoltovarmuusmaksu sisältyvät sähköveromaksuun.", "sv":"Elskatt uppbärs på all elenergi som distribueras till kunderna via distributionsnätet. Elskatteavgiften består av elaccis och försörjningsberedskapsavgift.", "en":"Electricity tax is levied on all electric energy distributed to customers through the distribution network. The excise tax on electricity and strategic stockpile fee are included in the electricity tax charge." } } ], "id":"2011", "name":"Yleissiirto", "localized_name":{ "fi":"Yleissiirto", "sv":"Allmän överföring", "en":"General distribution" }, "price_list_id":"1", "is_temporary_product":false, "product_type":"transfer", "product_subtypes":[ ], "start_date":"2022-01-01T00:00:00", "end_date":null, "product_info_link":null, "product_description":null, "components_description":null } ], "start_date":"2022-01-01T00:00:00" } ] } ```
Nezz commented 1 year ago

I checked the oma-helen-cli and it only finds old contracts. It grabs the first contract's data by default, which is the oldest contract: https://github.com/carohauta/oma-helen-cli/blob/5471052e0308726e1b408728f8af088e4c36b3b1/helenservice/api_client.py#L232 Looks like newer contracts are only returned by newer API versions, but once the correct delivery_site_id is found, the older APIs work.

carohauta commented 1 year ago

Adding support for the HA Energy dashboard might need some looking into. If I remember correctly, it does require a certain fixed data format – compared to the current implementation which relies on custom template sensors.

The contract function in the oma-helen-cli seems to be the culprit for a number of issues users are facing with the HA integration. Instead of getting the first contract in the list, it should be able to recognize the active contract somehow. Of course some people might have multiple active contracts in multiple addresses.

The problem is that I only have one active contract with Helen so I really can't tell how the contract response looks for someone who has multiple contracts. But I will try to figure this out.

Nezz commented 1 year ago

Thanks @carohauta. You can find an example response with multiple contracts at the end of my original post by clicking on Details.

carohauta commented 1 year ago

I have now upgraded the integration to use a newer Helen API (v14). So far it now supports following the total energy transfer costs of the on-going month, but not yet the consumption from the /measurements/electricity-transfer endpoint.

I hope to implement that in the next release.

Nezz commented 1 year ago

I added supports for measurements here: https://github.com/carohauta/oma-helen-cli/pull/2

Nezz commented 1 year ago

I also added a sensor for monthly consumption for integration into the energy dashboard: https://github.com/carohauta/oma-helen-ha-integration/pull/10