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)