Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting for new prices issue or request #251

Open
tyfoon opened this issue Mar 28, 2024 · 4 comments
Open

Waiting for new prices issue or request #251

tyfoon opened this issue Mar 28, 2024 · 4 comments

Comments

@tyfoon
Copy link

tyfoon commented Mar 28, 2024

Not sure if this is an issue or a feature request:

The integration looks at the time the car has to be charged at set SOC level (in my case 8:00am, 100%) and then finds the cheapest slot to charge. In many cases this works perfectly fine.

There are cases (like today) when I plug it in let's say 10:00am with a SOC of 50% and the integration say's "waiting for new prices". In a way this makes sense, as at this stage there are only prices until 0:00 and there might be prices that are upcoming that are lower between 0:00 and the time the car needs to be charged.

However this (waiting until prices are complete) will often result in missing the cheapest slot which is (in the Netherlands) in 80% mid day (roughly 12:00 - 15:00).

What is the best way (with current functionality) to make use of the 'best slot available with given price info" (instead of waiting for new prices)

Or if this is not possible easy; Is there interest to add this functionality?

@wormiedk
Copy link

I think it would be nice to have a toggle to not wait for prices or even to use the forecast from e.g. carnot as price

@jonasbkarlsson
Copy link
Owner

@tyfoon, with the current functionality, set the configuration Charge completion time to None. If None is selected, charging will be optimized using all hours with available price information, including before tomorrow's prices are available.

@BrainDra1n
Copy link

I have made the following tweak very applicable to The Netherlands.

Side note: the best weather prediction for the Netherlands is: "same weather tomorrow as we are having today"

This inspired me to do the following:
When tomorrow's prices are available, change nothing.
As long as tomorrow's prices are not available yet, use today's prices instead.

Which looks like this when tomorrow's prices are not available:
image
Note: that the curve is identical for today and tomorrow.

Because I use ENTSO-e as source for the prices, I have only implemented it for this source. But can be extended to the other sources as well.

For this I made a change in file helpers/price_adaptor.py and modified class PriceAdaptor member get_raw_tommorow_local() as follows.

class PriceAdaptor:
    """PriceAdaptor class"""

<snip>

    def get_raw_tomorrow_local(self, state) -> Raw:
        """Get the tomorrow's prices in local timezone"""

        if self._price_platform in (PLATFORM_NORDPOOL, PLATFORM_ENERGIDATASERVICE):
            return Raw(state.attributes["raw_tomorrow"], self._price_platform)

# start original code
#        if self._price_platform == PLATFORM_ENTSOE:
#            return Raw(state.attributes["prices_tomorrow"], self._price_platform)
# end original code, start alternative code
        if self._price_platform == PLATFORM_ENTSOE:
            if (not state.attributes["prices_tomorrow"] ):
                _LOGGER.debug("No tomorrow's prices available on ENSTO-e, thus use today's price as estimate for tomorrow")
                todays_prices = copy.deepcopy( state.attributes["prices_today"] )
                tomorrows_prices = []
                for hour in todays_prices:
                    hour_tomorrow = { }
                    hour_time = datetime.strptime( hour["time"], "%Y-%m-%d %H:%M:%S%z") + timedelta(days=1)
                    hour_timestring = hour_time.isoformat(' ')
                    hour_tomorrow["time"] = hour_timestring
                    hour_tomorrow["price"] = hour["price"]
                    tomorrows_prices.append(hour_tomorrow)
                return Raw(tomorrows_prices, self._price_platform)
            else:
                return Raw(state.attributes["prices_tomorrow"], self._price_platform)
# end alternative code

        return Raw([])


Note: Sorry I have used so many lines of code do something simple. But I do not 'speak' python. I expect this could be a single line of code.

The key is that todays prices are moved up 24h and used as tomorrows prices.

And after tomorrow's prices are available the graphs is normal again:
image

For me this works just fine. But I still have some problems with the update around 24:00 when tomorrow's prices become today's prices. For that I'm trying to tweak the timers that do the updates. They almost work fine. But not completely.

@ksga
Copy link

ksga commented Oct 30, 2024

I think it would be nice to have a toggle to not wait for prices or even to use the forecast from e.g. carnot as price

Got it working... Added a new template sensor reading the forecast from Carnot included in Energi Data Service integration.

template:
  - sensor:
    - name: "Tilpasset Energi Data"
      state: "{{ states('sensor.energi_data_service') }}"
      unit_of_measurement: DKK/kWh      
      attributes:
        prices_today: > #"{{ state_attr('sensor.energi_data_service', 'raw_today') }}"
                {%- set forecast_data = state_attr('sensor.energi_data_service', 'raw_today') %}
                {%- set time_key = 'hour' %}
                {%- set price_key = 'price' %}
                {%- set ns = namespace(data=[]) %}
                {%- for i in forecast_data | default([], true) if as_local(as_datetime(i[time_key])).date() == now().date() %}
                  {%- set ns.data = ns.data + [dict(time = as_local(as_datetime(i[time_key])).isoformat(), price = i[price_key])] %}
                {%- endfor %}
                {{ ns.data }}
        prices_tomorrow: >
            {% set tomorrow = state_attr('sensor.energi_data_service', 'tomorrow_valid') %}
            {% set tomorrow_copy = state_attr('sensor.energi_data_service', 'raw_tomorrow') %}
            {% if tomorrow == false %}
                {%- set forecast_data = state_attr('sensor.energi_data_service', 'forecast') %}
                {%- set time_key = 'hour' %}
                {%- set price_key = 'price' %}
                {%- set ns = namespace(data=[]) %}
                {%- for i in forecast_data | default([], true) if as_local(as_datetime(i[time_key])).date() == (now()+timedelta(days=1)).date() %}
                    {%- set ns.data = ns.data + [dict(time = as_local(as_datetime(i[time_key])).isoformat(), price = i[price_key])] %}
                {%- endfor %}
                {{ ns.data }}
            {% else %}
                {%- set forecast_data = state_attr('sensor.energi_data_service', 'raw_tomorrow') %}
                {%- set time_key = 'hour' %}
                {%- set price_key = 'price' %}
                {%- set ns = namespace(data=[]) %}
                {%- for i in forecast_data | default([], true) if as_local(as_datetime(i[time_key])).date() == (now()+timedelta(days=1)).date() %}
                    {%- set ns.data = ns.data + [dict(time = as_local(as_datetime(i[time_key])).isoformat(), price = i[price_key])] %}
                {%- endfor %}
                {{ ns.data }}
            {% endif %} 

Estimated prices for tomorrow are correctly shown and used:
image

Used the info/example found here:
https://github.com/jonasbkarlsson/ev_smart_charging/wiki/Price-sensor and here https://github.com/jonasbkarlsson/ev_smart_charging/wiki/EPEX-Spot-price-template-sensor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants