Coernel82 / smartCharge4evcc

A smart charging solution addon for evcc for electric vehicles that optimizes charging schedules based on solar forecasts, weather, electricity prices, and home energy consumption.
MIT License
7 stars 0 forks source link

improvement tariff #3

Open mbuhansen opened 1 day ago

mbuhansen commented 1 day ago

Hi.

this project looks good, i am looking for a system like this to control charging of my car, heatpump and home battery. will it be possible to import tariff from energinet in denmark. (tibber dont support denmark yet.)

Can this only run at debian..?? i run now EVCC as Home assistant add-on.

Coernel82 commented 1 day ago

Hi, yes it will be possible. I intend to add the option for other energy sources. You are welcome to help on this as this is rather simple: Instead of electricity_prices = utils.get_electricity_prices(TIBBER_API_URL, TIBBER_HEADERS) you need to implement the function for energinet.

What you can do: supply me with the api-information of energinet.

You do not need to run it on debian. All you need is a python environment. I programmed and tested it on windows first.

mbuhansen commented 1 day ago

Great. to be hornest i can't make programming, but i now EVCC has energinet api-information, in the software. https://github.com/evcc-io/evcc/blob/master/tariff/energinet/types.go https://github.com/evcc-io/evcc/blob/master/tariff/energinet.go

A better solution will be if is possible to read forcast tariff from home assistant. I denmark we have different tax on different times of day, this tax energinet dont supply. But https://github.com/MTrab/energidataservice has made a integration that calculate the correct energy price with all tax. I have try to use this to EVCC, EVCC can read json with forecast, have try to make it in node red but my evcc is not happy, cant write it correct. energidata service

mbuhansen commented 1 day ago

in node-red i have a function node that poll price from energidataservice sensor in Home assistant, this function node make a json with all price. maybe this can be used to something. code is made by help of chatgpt.

// Få priserne fra Home Assistant entity-attributterne const todayPrices = msg.data.attributes.today; // Antag at attributten hedder 'today' const tomorrowPrices = msg.data.attributes.tomorrow; // Antag at attributten hedder 'tomorrow'

// Tjek at der er 24 priser i hver attribut if (todayPrices.length !== 24 || tomorrowPrices.length !== 24) { node.error("Each price attribute should contain exactly 24 values"); return null; }

// Funktion til at formatere dato til ISO 8601 uden millisekunder og med 'Z' for at angive UTC tid const formatDate = (date) => date.toISOString().split('.')[0] + "Z";

// Få den aktuelle dato og indstil tidspunktet til midnat const now = new Date(); const start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);

// Opret JSON data for 48 timer med en times interval const intervals = []; for (let i = 0; i < 48; i++) { const intervalStart = new Date(start.getTime() + i 60 60 1000); const intervalEnd = new Date(intervalStart.getTime() + 60 60 * 1000);

// Brug priser fra today for de første 24 timer, og priser fra tomorrow for de næste 24 timer
const price = i < 24 ? todayPrices[i] : tomorrowPrices[i - 24];

intervals.push({ "start": formatDate(intervalStart), "end": formatDate(intervalEnd), "price": price });
}

msg.payload = intervals; return msg;

nodered api call

Coernel82 commented 23 hours ago

Hi, this looks very good already. This is the target json-format:

 "timestamp": "2024-11-30T13:38:30.673695+01:00",
    "prices": [
        {
            "total": 0.2729,
            "startsAt": "2024-11-30T00:00:00+01:00"
        },
        {
            "total": 0.2648,
            "startsAt": "2024-11-30T01:00:00+01:00"
        },
        {
            "total": 0.262,
            "startsAt": "2024-11-30T02:00:00+01:00"
        },
        {
            "total": 0.2587,
            "startsAt": "2024-11-30T03:00:00+01:00"
        },
        {
            "total": 0.2602,
            "startsAt": "2024-11-30T04:00:00+01:00"
        },
...

So for your case I suggest the following - without knowing node red

  1. copy your node-red flow
  2. in the copy: change start to startsAt, change price to total, optional: delete end - my program will ignore it anyways
  3. wrap everything into prices
  4. and add one entry "timestamp" then make sure that this ends up in the cache directory of my program and that the timestamp gets updated regularly. As my program will look for the cache before accessing tibber you can leave the tibber credentials as is as they never will be needed.