rnovacek / homeassistant_cz_energy_spot_prices

Home Assistant integration that provides current Czech electricity spot prices based on OTE.
Apache License 2.0
75 stars 17 forks source link

Gas sensor #8

Closed hipik634 closed 1 year ago

hipik634 commented 1 year ago

Hi, could you implement also gas data https://www.ote-cr.cz/en/short-term-markets/gas/intra-day-market?date=2023-01-01 ? díky

rnovacek commented 1 year ago

It's on my todo list, should be quite easy. But I want to improve the electricity-related sensors first.

ogajduse commented 1 year ago

I have dug into it and discovered that the OTE API does not provide the InEur boolean that allows switching prices between CZK and EUR.

from zeep import Client
client = Client("https://www.ote-cr.cz/services/PublicDataService/wsdl")
print(client.service.GetImPriceG(StartDate='2023-01-22', EndDate='2023-01-23'))

Output:

[{
     'Date': datetime.date(2023, 1, 22),
     'Price': Decimal('69.32'),
     'Volume': Decimal('5740.9'),
     'MinPrice': Decimal('67.50'),
     'MaxPrice': Decimal('71.49'),
     'IndexOte': None
 },
 {
     'Date': datetime.date(2023, 1, 23),
     'Price': Decimal('0.00'),
     'Volume': Decimal('0.0'),
     'MinPrice': Decimal('0.00'),
     'MaxPrice': Decimal('0.00'),
     'IndexOte': None
 }]

At first, I thought: As the integration has the setting for the currency, it would be good to come up with some way to convert the currency. But technically, we would need to fetch the EUR/CZK rate from $SOMEWHERE. That suggests some API. I have also looked at that area and can say that most of the public currency rate APIs are limited by requests per day/month and require authentication using a token. I believe

But I have changed my mind. I would say that the integration should only fetch the data from OTE API and publish values as HA sensors as it does now.

@rnovacek The integration would need to perform two separate queries in order to get the electricity and gas data. I have checked the code structure, but I was unable to quickly see what the best and not messy patch would be. I will try to give it a second shot and maybe I will come up with something smart. Do you have any thoughts or ideas about this topic to share? What is your opinion on currency conversion?

Feel free to switch to Czech. I just wanted to keep this thread in English to not be the first one to change the language. :smile:

ogajduse commented 1 year ago

@rnovacek I would be happy to hear your thoughts.

rnovacek commented 1 year ago

I had a currency conversion code in first versions of this integration - before I found out that the API can convert the prices automatically. I can dig it up. It was using ČNB API.

I'm still quite short on time, but would love to do it at some point.

rnovacek commented 1 year ago

I think you're right, the correct API call is GetImPriceG as described here https://www.ote-cr.cz/cs/dokumentace/dokumentace-elektrina/files_dokumentace/uzivatelsky_manual_webove_sluzby_ote.pdf

What sensors would you like to see? Just PriceToday and PriceTomorrow? Or are the MinPrice and MaxPrice important as well?

Do you know how the data works? When are data for next day published?

Any additional sensors ideas? Something that might be useful?

rnovacek commented 1 year ago

Could someone explain how the gas spot prices work? There are Price, MinPrice and MaxPrice. I tried to use just the Price as I assumed it's the same for whole day, but apparently it varies during a day (not by much):

image

Is it ok to have that in a sensor? Do we also need the min/max? And the tomorrow price is know for a whole day before?

ogajduse commented 1 year ago

@rnovacek Thank you for the time and effort you put into it! Having only PriceToday and PriceTomorrow is fine for me, I am interested in PriceToday the most.

Do you know how the data works? When are data for next day published?

I do not. I am also short on time these days, unfortunately.

Any additional sensors ideas? Something that might be useful?

The ČNB API looks stupidly simple it may be a way to convert the prices. I have also seen some python libraries that simplifies access to the data.

I have no other ideas about sensors or useful information. Feel free to poke me anytime. I am always available to at least test any changes.

rnovacek commented 1 year ago

I have added the gas sensor (pretty basic for now, tell me what you need) - it's released as experimental version 0.4.0b0. Please give me some feedback as I don't use gas personally.

ogajduse commented 1 year ago

@rnovacek thank you for taking the time and implementing it. I like the way you did the patch. :+1:

I have had the beta version installed for two days and discovered that if OTE does not provide the gas price, the integration sets the price to zero. image I would expect the price not to change in such a situation and keep the last value instead - do not update the sensor.

Screenshot of sensor.spot_gas_has_tomorrow_data from the same time window. image

rnovacek commented 1 year ago

@ogajduse This should be fixed in the latest version. If not, please reopen this ticket.

ogajduse commented 1 year ago

@rnovacek Thanks for your time spent on this. Really appreciated.