Page 1 of 1

Domoticz uptime

Posted: Tuesday 21 April 2020 16:52
by manjh
I am running Domoticz in more than one location, and would like to collect the uptime on a central server.
Is it possible to take the uptime value in LUA, in order to send it through MQTT?

Re: Domoticz uptime

Posted: Tuesday 21 April 2020 17:00
by manjh
never mind, I found a solution already in the forum... :D

Re: Domoticz uptime

Posted: Saturday 25 April 2020 22:58
by Geitje
Great 8-) . Would be even greater if you briefly share where or found the solution, so others searching the forum can find it more easily. [And consider editing the title].

Re: Domoticz uptime

Posted: Monday 27 April 2020 14:31
by manjh
I don't remember exactly where I found it, but a simple google search brought me there.
Here's the code I am using now:

Code: Select all

return { 
    on = {   timer  =   {"every 5 minutes"}},  
                
    execute = function(dz)
        local uptimeTextDevice = dz.devices("Utrecht Domoticz uptime")
        
        local minutes = dz.startTime.minutesAgo%60
        local days    = dz.startTime.daysAgo
        local hours   = dz.startTime.hoursAgo%24
        
        if days == 1 then
            DagText = " dag"
        else
            DagText = " dagen"
        end
        
        uptimeTextDevice.updateText(days ..DagText..", " .. hours .. " uur en " .. minutes .. " minuten"  )
    end
}
As for editing the title of this thread: why? It covers exactly what I was looking for!

Re: Domoticz uptime

Posted: Monday 27 April 2020 14:48
by manjh
Since I was getting the code for display here, I thought it might be good to add Raspberry Pi uptime as well.
Here's the modified code:

Code: Select all

return { 
    on = {   timer  =   {"every 5 minutes"}},  
                
    execute = function(dz)
        -- set names of text devices
        local DomoticzUptimeTextDevice = dz.devices("Utrecht Domoticz uptime")
        local RaspberryUptimeTextDevice = dz.devices("Utrecht R-Pi uptime") 
        
        -- prepare and store Domoticz uptime
        local minutes = dz.startTime.minutesAgo%60
        local days    = dz.startTime.daysAgo
        local hours   = dz.startTime.hoursAgo%24
                if days == 1 then
            DagText = " dag"
        else
            DagText = " dagen"
        end
        DomoticzUptimeTextDevice.updateText(days ..DagText..", " .. hours .. " uur en " .. minutes .. " minuten"  )
        
        -- prepare and store R-Pi uptime
        local f = assert(io.popen('uptime', 'r'))
        local uptime = assert(f:read('*a'))
        f:close()
        RaspberryUptimeTextDevice.updateText(uptime)
        
    end
}

Re: Domoticz uptime

Posted: Tuesday 28 April 2020 23:26
by Geitje
Thanks, nice to have the code. About the topic title: I ment something like adding "solved" to title. But know I'm whining... ;). And it's not needed...
manjh wrote: Monday 27 April 2020 14:31 As for editing the title of this thread: why? It covers exactly what I was looking for!