jonasbkarlsson / ev_smart_charging

Electric vehicle smart charging for Home Assistant.
MIT License
139 stars 18 forks source link

Waiting for new prices issue or request #251

Open tyfoon opened 3 months ago

tyfoon commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago

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

BrainDra1n commented 2 weeks ago

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.