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: 356
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 38 times
User avatar
gizmocuz
Posts: 2708
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: 595
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: 356
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: 2708
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!
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by hjzwiers »

I have Enever running with the API key.

I installed a managed counter and a switchIdx accoriding to your instructions:
local switchIdx = 3103 -- IDX van je schakelaar
local managedCounterIdx = 3102 -- IDX van de managed counter
I also tried Enever's managed counter 2977, same error

I tried running your script, but i keep getting the following errors:

2025-11-13 14:32:00.156 Error: Error opening url: http://127.0.0.1:8080/json.htm?type=gra ... &range=day
2025-11-13 14:32:00.267 Error: dzVents: Cheap Hours Script: HTTP/1.1 response: 404 ==>> Not Found
2025-11-13 14:32:00.267 Error: dzVents: Cheap Hours Script: Fout bij ophalen van gegevens van Domoticz.

I wonder why it is so difficult to get a running script from domoticz ......I am running domoticz in a container managed by dockge
Last edited by hjzwiers on Thursday 13 November 2025 14:56, edited 1 time in total.
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

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

Post by waltervl »

API calls have changed since 2023: https://wiki.domoticz.com/Domoticz_API/ ... and_newer)

Code: Select all

http://127.0.0.1:8080/json.htm?type=graph&sensor=counter&idx=3102&range=day
should be

Code: Select all

http://127.0.0.1:8080/json.htm?type=command&param=graph&sensor=counter&idx=3102&range=day
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by hjzwiers »

Thanks for the quick answer! That was it. When will getting the data on a 15 minute basis be made available in Domoticz?

I had to use the managed counter of Enever.
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

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

Post by waltervl »

hjzwiers wrote: Thursday 13 November 2025 15:07 When will getting the data on a 15 minute basis be made available in Domoticz?
No idea, until someone feels the urge to use the quarterly updates and has development skills.......
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Henielma
Posts: 11
Joined: Friday 12 September 2025 12:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Contact:

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

Post by Henielma »

To collect the 15 min prices via Enever I made a DzVents script to place this info in a user variable. This information I use to control a home battery to charge at the cheapest 11 kwarters of a day and discharge at the most expensive kwarters a day.

The EneverGet DzVents script can be used by other as inspiration to collect the kwarter prices from Enever.
See the attached file for the script. Fill in your own token and create the user variable "StroomprijsMorgen" and it should work.
EneverGet.txt
(3.29 KiB) Downloaded 10 times
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by hjzwiers »

I just integrated the script of the hourly prices, and that script also locates the lowest prices ...... maybe later, need to get some experience with it first
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by hjzwiers »

I added StroomprijsMorgen as a uservariable and my token was added, but i still get the following error:

2025-11-17 16:36:00.193 Error: dzVents: Enever stroomprijs: Kon JSON niet parsen uit StroomprijzenMorgen

Ik heb StroomprijzenMorgen ook als user variable toegevoegd, maar dat was hem niet ....
Henielma
Posts: 11
Joined: Friday 12 September 2025 12:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Contact:

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

Post by Henielma »

How do the user variables look like? Is it something like this:
Schermafbeelding 2025-11-17 225838.png
Schermafbeelding 2025-11-17 225838.png (117.97 KiB) Viewed 131 times
Or is your StroomprijsMorgen empty?
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by hjzwiers »

I turned StroomprijzenMorgen into StroomprijsMorgen, but still the error.

I checked the https site and I receive the site with the data.

but i still get 2025-11-17 23:15:00.272 Error: dzVents: Enever stroomprijs: Kon JSON niet parsen uit StroomprijzenMorgen.

What else can it be?
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by hjzwiers »

I think I got it to work.

How do you readout a managed counter? I'm working on it, i see the values in the variable logging
Henielma
Posts: 11
Joined: Friday 12 September 2025 12:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Contact:

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

Post by Henielma »

I do not completely understand what you want to know but probably the following code part helps you:

Code: Select all

            local jsonString = domoticz.variables('StroomprijsVandaag').value
            
            if hourNow >= cyclus2Tot then -- gebruik vanaf 22 uur de StroomprijsMorgen informatie
                jsonString = domoticz.variables('StroomprijsMorgen').value
                hourNow = "00"
            end
            
            -- JSON decoderen
            local data = domoticz.utils.fromJSON(jsonString)
            
            if not data then
                domoticz.log("Kon JSON niet decoderen: " .. tostring(jsonString), domoticz.LOG_ERROR)
                return
            end

            local entries = {}      -- Plaats de json data tot 10 uur in de ochtend in een lua structuur
            local dataUur = cyclus1Vanaf
            for _, e in ipairs(data) do
                dataUur = string.sub(e.datum, 12, 14)  -- kopieer het uur van de dataregel in dataUur
                if (dataUur < cyclus1Tot and hourNow < cyclus1Tot) or (dataUur >= cyclus1Tot and dataUur < cyclus2Tot and hourNow >= cyclus1Tot) then -- domoticz.time.matchesRule('at 0:01-9:59') Afhankelijk van de huidige tijd de uren tot 10 uur gebruiken of die van 10 tot 22 uur
                    table.insert(entries, {d = e.datum, v = tonumber(e.prijsTI)})
                end
            end
    
            -- sorteren op prijs v
            table.sort(entries, function(a, b) return a.v < b.v end)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest