Page 1 of 1

Time in minutes or hours

Posted: Wednesday 16 June 2021 22:39
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
}


Re: Time in minutes or hours

Posted: Friday 18 June 2021 20:02
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.

Re: Time in minutes or hours

Posted: Friday 18 June 2021 20:49
by Tarzan737
Thank u very much!