jpulakka / nordpool_diff

Transforms electricity spot price into thermostat control signal. Home Assistant custom component.
MIT License
63 stars 7 forks source link

ENTSO-E support #21

Closed jpulakka closed 1 year ago

jpulakka commented 1 year ago

Using Nord Pool API is a grey area. Technically it's public and appears to work so far without any tokens, but Nord Pool API documentation states If you are a Nord Pool customer, using our trading APIs is for free. All others must become a customer to use our APIs. which apparently means that almost nobody should be using it.

Also https://github.com/custom-components/nordpool seems somewhat unmaintained and https://github.com/custom-components/nordpool/issues/125 remains unfixed and is hitting at least me regularly.

ENTSO-E would be the correct place to fetch the prices from, and now (10/2022) there's also a HASS integration for that: https://github.com/JaccoR/hass-entso-e

Add support. Then maybe we also need to consider "nordpool_diff" name. Should that be entsoe_diff?

jpulakka commented 1 year ago

Currently entso-e API is crapping out. Request https://web-api.tp.entsoe.eu/api?securityToken=XXX&documentType=A44&in_Domain=10YFI-1--------U&out_Domain=10YFI-1--------U&periodStart=202210250600&periodEnd=202210260600 returns

<?xml version="1.0" encoding="UTF-8"?>
<Acknowledgement_MarketDocument
    xmlns="urn:iec62325.351:tc57wg16:451-1:acknowledgementdocument:7:0">
    <mRID>0bab0cf3-8c3a-4</mRID>
    <createdDateTime>2022-10-25T06:13:50Z</createdDateTime>

    <sender_MarketParticipant.mRID codingScheme="A01">10X1001A1001A450</sender_MarketParticipant.mRID>
    <sender_MarketParticipant.marketRole.type>A32</sender_MarketParticipant.marketRole.type>

    <receiver_MarketParticipant.mRID codingScheme="A01">10X1001A1001A450</receiver_MarketParticipant.mRID>
    <receiver_MarketParticipant.marketRole.type>A39</receiver_MarketParticipant.marketRole.type>

    <received_MarketDocument.createdDateTime>2022-10-25T06:13:50Z</received_MarketDocument.createdDateTime>

    <Reason>
        <code>999</code>
        <text>No matching data found for Data item Day-ahead Prices [12.1.D] (10YFI-1--------U, 10YFI-1--------U) and interval 2022-10-25T06:00:00.000Z/2022-10-26T06:00:00.000Z.</text>
    </Reason>

</Acknowledgement_MarketDocument>

(Initially pasted my security token above, renewed...)

Using "Developer Tools" in hass, https://github.com/JaccoR/hass-entso-e

{{ state_attr("sensor.current_electricity_market_price", "prices") }}

gives

[{'time': '2022-10-25 00:00:00+03:00', 'price': 0.17211}]

Apparently it's the last price fetched at some point yesterday. It's doing the best it can. But we don't know the price now.

Later on, the above returns just

None

Also see https://github.com/JaccoR/hass-entso-e/issues/40


This brings an idea that robustness of nordpool_diff could be improved by using both entso-e and nordpool!

  1. By default, get prices from hass-entso-e.
  2. If the data is not good, then also get prices from nordpool to see if that works better (right now it does although sometimes it does not).
jpulakka commented 1 year ago

Implementation notes:

Parsing the prices list:

Getting "next_n_hours":

There's quite some processing, maybe would be nice to add some caching to avoid parsing the whole list once per second (or whatever the hass polling frequency is).

jpulakka commented 1 year ago

Working in https://github.com/jpulakka/nordpool_diff/tree/entsoe_support

jpulakka commented 1 year ago

I think https://github.com/jpulakka/nordpool_diff/tree/entsoe_support c6b8acf620b01e9ea7be1cb239a84eb3cf1aa9b7 works now. Todo before merging:

jpulakka commented 1 year ago

https://github.com/jpulakka/nordpool_diff/tree/entsoe_support now = RC1, just testing a bit before merging. Then let's do v0.2.0 release right away.

jpulakka commented 1 year ago

Adapted a bit to support hass-entso-e new default entity name.

MrOzzOnline commented 1 year ago

It's great you've implemented this. Thanks for the work!

jpulakka commented 1 year ago

Merged in https://github.com/jpulakka/nordpool_diff/pull/22

jpulakka commented 1 year ago

https://github.com/jpulakka/nordpool_diff/releases/tag/v0.2.0