JaccoR / hass-entso-e

Integration for Home Assistant to fetch day ahead energy prices from European countries via ENTSO-e Transparency Platform
159 stars 25 forks source link

Optimizing electricity use with hourly prices #61

Closed whulshof closed 1 year ago

whulshof commented 1 year ago

Hi, you have built a great integration. Thanks for that. I have an electric car and heat pumps as heating solution. No gas anymore. On colder days in winter the heat pumps (2) regularly use some 150 kWh per day and let's say the Tesla on average will need some 40 kWh after it has been used. And apart from that I use some 50 kWh per day on lights, pumps, cooking, washing etc. So I'll really want to optimise electricity use to the hours with lowest price as published by entsoe to profit from the heat pump and EV investment. Now I was thinking at 15.00 the prices of next day become available and say at 15.01 hass could run an optimisation program to calculate the best hours to use electricity for the coming 33 hours, taking into account the necessary forecasted kWh and the typical use per device. Ofcourse the next day at 15.00 hours the first 9 hours will be replanned together with the prices of the day ahead prices of the day after that. The prices could go up so the 9 hours of the running day could become more interesting. My problem is that I don't have much use for the sensors, that are available now, since they are not stating the time and averages do not bring me much. I would rather have an ordered list of hour-prices, so that I can just take the beginning of the list to plan my use up and until the forecasted kWh's are reached and then the actual order of the hours will be kicking in again. I'm assuming I can buffer heat as much as necessary within a day and the car does not have to be fully charged every morning. This assumption will not be always valid, but as a working assumption it's ok. How can I get at the ordered list for the next 33 hours at or around 15.00 hrs the easiest do you think? If I have my optimiser I will make a PR for the interested or a separate integration/automation if that should be better.

JaccoR commented 1 year ago

Currently this integrations will not do this. This integration will provide the prices. My believe is that a seperate integration should take the prices (and things like PV forecasts) as an input and outputs a sensor with which you can automate your devices. I am currently working on a project like this. I can start a new repository for this, so people interested in this can work on this together. See also #15 .

Other than that, I am currently running an automation that turns off my heatpump when prices are above 50% of the max price of the day. The sensors in this integration are still pretty useful for those things.

whulshof commented 1 year ago

Thanks for your quick answer. Could you point me in the right direction for getting the ordered list of hours/prices? I know the prices are in an attribute in the current sensors. I even believe in all of them. But how do I get them out? How is it possible for me to miss the #15 issue! Shame on me. So I'm not the only one. But the question remains how to get the prices out of the attribute in an ordered list? Not to make a EMS from this repo, but to get the info needed to time shift .

whulshof commented 1 year ago

Other than that, I am currently running an automation that turns off my heatpump when prices are above 50% of the max price of the day. The sensors in this integration are still pretty useful for those things.

But that is terribly non-principle. With an ordered list you would do much better, because you know you need the heat pump every day or maybe every two days. So if you can't wait anymore to switch it on within 24 hours the 50% condition is not leading to a warm house if the difference between expensive and cheap hours is not a factor 2 or more.

JaccoR commented 1 year ago

But that is terribly non-principle. With an ordered list you would do much better, because you know you need the heat pump every day or maybe every two days. So if you can't wait anymore to switch it on within 24 hours the 50% condition is not leading to a warm house if the difference between expensive and cheap hours is not a factor 2 or more.

I know it is not optimal, but it does its job: Turning off the heat pump when prices are high. It took some calibrating to find the right threshold %, but after that I still have a warm house with the heat pump off at high prices.

But the question remains how to get the prices out of the attribute in an ordered list?

Sorry, missed the question a bit. Here is an example which gets the cheapest hours between 18:00 and 6:00. As you can see, the template uses state_attr('sensor.average_electricity_market_price', 'prices')[18:30]|sort(attribute='price') to sort the prices.

platform: template
sensors:
cheapest_hours_between_18_and_06:
value_template: >-
{% set l=state_attr('sensor.average_electricity_market_price', 'prices')[18:30]|sort(attribute='price') %}
{{ (now() >= as_datetime(l[0].time) and now() <= as_datetime(l[0].time) + timedelta(hours = 1))
or (now() >= as_datetime(l[1].time) and now() <= as_datetime(l[1].time) + timedelta(hours = 1))
or (now() >= as_datetime(l[2].time) and now() <= as_datetime(l[2].time) + timedelta(hours = 1))
or (now() >= as_datetime(l[3].time) and now() <= as_datetime(l[3].time) + timedelta(hours = 1))
or (now() >= as_datetime(l[4].time) and now() <= as_datetime(l[4].time) + timedelta(hours = 1))
or (now() >= as_datetime(l[5].time) and now() <= as_datetime(l[5].time) + timedelta(hours = 1)) }}
whulshof commented 1 year ago

Great! Thanks a lot!

whulshof commented 1 year ago

And now I also understand how it is done. Your example is for the 6 cheapest hours, isn't it?

JaccoR commented 1 year ago

Yes!