Time in minutes or hours

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

Moderator: leecollings

Post Reply
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Time in minutes or hours

Post by Tarzan737 »

hello! i copied this code from an earlier post and it works fine, but i want it in minutes or hours instead for my heater if possible?

Code: Select all

return
{
    on =
    {
        devices =
        {
            1324, -- device for which you want to record the On time.
        },
    },
    data =
    {
        lastOn = { initial = 0 },
    },
    logging = {
        level = domoticz.LOG_DEBUG,
        marker = 'timeKeeper',
    },

    execute = function(dz, item)
        local secondsActive = 0
        local iCounter = dz.devices('timeKeeper') -- define as virtual incremental counter

        if item.active then
            if dz.data.lastOn == 0 then dz.data.lastOn = os.time() end
            return
        else
            if dz.data.lastOn == 0 then
                secondsActive = os.time() - item.lastUpdate.dDate
            else
                secondsActive = os.time() - dz.data.lastOn
                 dz.data.lastOn = 0
            end
            iCounter.updateCounter(secondsActive)
        end
    end
}

RedEarth
Posts: 23
Joined: Monday 31 October 2016 11:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Time in minutes or hours

Post by RedEarth »

I wanted this to show minutes as well, so I just changed the line at the end that calls updateCounter:

Code: Select all

iCounter.updateCounter(secondsActive / (60))
then change the 'Value Units' on the incremental counter virtual device to 'min'.

It won't change historical values stored in the log though, so you might want to delete your virtual counter device and create a new one.
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Time in minutes or hours

Post by Tarzan737 »

Thank u very much!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest