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

Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Thursday 13 November 2025 14:36
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
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Thursday 13 November 2025 14:54
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¶m=graph&sensor=counter&idx=3102&range=day
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Thursday 13 November 2025 15:07
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.
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Thursday 13 November 2025 15:09
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.......
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Thursday 13 November 2025 21:44
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.
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Friday 14 November 2025 14:39
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
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Monday 17 November 2025 16:37
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 ....
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Monday 17 November 2025 23:01
by Henielma
How do the user variables look like? Is it something like this:

- Schermafbeelding 2025-11-17 225838.png (117.97 KiB) Viewed 115 times
Or is your StroomprijsMorgen empty?
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Monday 17 November 2025 23:47
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?
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Tuesday 18 November 2025 16:11
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
Re: Enever: managed Counter kWh -> 1..24 scale for price index?
Posted: Tuesday 18 November 2025 16:51
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)