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

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
renerene
Posts: 347
Joined: Wednesday 03 August 2016 11:36
Target OS: -
Domoticz version:
Contact:

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

Post 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)
Jeakes
Posts: 3
Joined: Friday 16 February 2018 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

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

Post 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
Attachments
script.txt
(6.65 KiB) Downloaded 10 times
User avatar
gizmocuz
Posts: 2394
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

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

Post 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)
Quality outlives Quantity!
Kedi
Posts: 563
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

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

Post 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?
Logic will get you from A to B. Imagination will take you everywhere.
Jeakes
Posts: 3
Joined: Friday 16 February 2018 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

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

Post by Jeakes »

For test every minute, after that every hour
renerene
Posts: 347
Joined: Wednesday 03 August 2016 11:36
Target OS: -
Domoticz version:
Contact:

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

Post 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.
User avatar
gizmocuz
Posts: 2394
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

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

Post 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 ;-)
Quality outlives Quantity!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest