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: 316
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)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest