Page 1 of 1

Enever: managed Counter kWh -> 1..24 scale for price index?

Posted: Saturday 14 December 2024 22:30
by renerene
Has anybody written a script that can destilate kWh position scale 1-24 out of a manager counter device??

Let's say i want to charge my car on the 6 cheapest hours of the day. It would be handy for that use case to have a device that holds the position of current hourly price: 1 for the cheapest, 24 for the most expensiven kWh hour. Than it would be easy to program with kWh scale described above:

if kWhPosition<7 then chargeEV=ON else chargeEV=OFF

I'm struggling reading history values of my 'Daily Electricity Price' managed counter, that's why i'm asking.

Here's my old script, as inspiration:

Code: Select all

function getKwhOrderPosition(hour)
            if hour < 0 or hour > 23 then
                dz.log('Invalid hour value: '..hour, dz.LOG_ERROR)
                return nil
            end

            local kwhOrder = {}

            for i = 0, 23 do
                if kwh[i] then
                    local order = 1
                    dz.log("nr, value=" .. i..':'..kwh[i], dz.LOG_INFO)
                    for j = 0, 23 do
                        if kwh[j] and kwh[j] < kwh[i] then
                            order = order + 1
                        end
                    end
                    kwhOrder[i] = order
                    dz.log("position=" .. order, dz.LOG_INFO)
                else
                    kwhOrder[i] = 0
                end
            end

            return kwhOrder[hour]
        end

            local currentHourPosition = getKwhOrderPosition(dz.time.hour)
            dz.log("currentHourPosition=" .. currentHourPosition, dz.LOG_INFO)

Re: Enever: managed Counter kWh -> 1..24 scale for price index?

Posted: Monday 23 December 2024 19:41
by Jeakes
I made a script that calculates over 24 hours which hours are the cheapest.
You need to adjust these parameters:
local switchIdx = 478 -- IDX of your switch
local managedCounterIdx = 470 -- IDX of the managed counter ever
local percentage_goedkoop = 0.72 -- percentage of hours (0.8 is 80%) is the cheapest

I managed it with great difficulty and chatgpt with my buddy.

Succes

Re: Enever: managed Counter kWh -> 1..24 scale for price index?

Posted: Tuesday 24 December 2024 12:39
by gizmocuz
For a general rule that does not involve any calculations

Winter: between 01.00am-06.00am
Summer: between 11.00am-17.00pm

For battery charging there must be done quite a lot more (price difference, multiple charge/discharge slots in a day etc)

But trust me on the above, these timeslots are perfect for your car.

Sometimes the price/kWh is so high that you don't want to charge it (but sometimes you have to), this could be a simple check (if price > xx then don't charge)

On my personal github project page I have scripts (nodeJS) that does a good calculation for battery charge hours (but this is based on a price difference)

Re: Enever: managed Counter kWh -> 1..24 scale for price index?

Posted: Tuesday 24 December 2024 16:14
by Kedi
Put hour and price in an array.
Loop over the array and find the lowest price.
Take 2 or more hours before the lowest price and than 2 or more hours after the lowest price.
This should give you a timespan of 4 or more hours in which prices are relative low.

@Jeakes Why run it every minute?

Re: Enever: managed Counter kWh -> 1..24 scale for price index?

Posted: Friday 27 December 2024 14:07
by Jeakes
For test every minute, after that every hour

Re: Enever: managed Counter kWh -> 1..24 scale for price index?

Posted: Friday 27 December 2024 21:10
by renerene
Ah, you are using a JSON call to fetch log history data

Code: Select all

        local function fetchHourlyData(idx)
            local url = dz.settings['Domoticz url'] .. 
                        "/json.htm?type=graph&sensor=counter&idx=" .. idx .. 
                        "&range=day"
            dz.openURL({
                url = url,
                method = "GET",
                callback = "hourlyPriceData"
            })
        end
That makes it relative complex, the dzVent script needs to be splitted in two sections: make the call and examine the results.
For me, this is not worth it for the moment to re-program for Enever. I'm using my old script that defines the 1..24 price index value per hour based on general Entsoe prices. And use the Enever plugin for exact price.

Wish there would be an easier way to access log data with dzVents. I can see some great functionality here, also in other use cases.
something like device.getHistory (IDX, date) would be great.
But trust me on the above, these timeslots are perfect for your car.
Trust me, when you're a nerd this will not do.
Sometime price is different in weekends. Sometimes it is between winter and summer (spring). Sometimes tI want my car to charge a little bit, using three hours of the cheapest hours. Sometimes I need full power setting my "charge hours" variable to 24.

Re: Enever: managed Counter kWh -> 1..24 scale for price index?

Posted: Saturday 28 December 2024 15:27
by gizmocuz
I guess it depends on the type of battery in your car.

There are two types:
- one that needs to be discharged to 20% and charge to 80% (or similar percentages)
- one that needs to be topped all the time. So put it on the charger and charge whenever possible

You need to know the type of your car, because threading the battery wrong, will decrease its life!

Mine (and probably most batteries today) have the first type.

So, I try to plugin when I reach about 20% (or when I have a long tripped planned the next day), so I need to charge,
and then you should use the above timeslots.

NMC:
https://www.youtube.com/watch?v=w4lvDGtfI9U

LFP:
https://www.youtube.com/watch?v=w1zKfIQUQ-s

And really, the difference between the price of a 3 hour slot and a 5/6 hour slot is cents!

Keep it simple, i'm a nerd as well but have other things to worry about ;-)