Page 1 of 1

Check last seen?

Posted: Saturday 21 January 2017 15:44
by Calzor Suzay
Does anyone have a script written that would check a list of given devices for their 'Last seen' status of say more than 5 days then report it somehow?
I'm trying to capture devices such as PIR, door sensors etc. where potentially the battery has died :o

Re: Check last seen?

Posted: Saturday 21 January 2017 16:30
by Siewert308SW
Calzor Suzay wrote:Does anyone have a script written that would check a list of given devices for their 'Last seen' status of say more than 5 days then report it somehow?
I'm trying to capture devices such as PIR, door sensors etc. where potentially the battery has died :o
Wiki has a few ;-)

Re: Check last seen?

Posted: Saturday 21 January 2017 19:27
by Calzor Suzay
I couldn't find a Wiki for dzVents only the Github and the examples there seem to be about 'pinging' devices to see if they are alive.
Unless I missed something?

Re: Check last seen?

Posted: Sunday 22 January 2017 1:12
by Siewert308SW
Calzor Suzay wrote:I couldn't find a Wiki for dzVents only the Github and the examples there seem to be about 'pinging' devices to see if they are alive.
Unless I missed something?
You didn't mention you want info for Dz, then ask there.
As for Lua, you could amend this one:
https://www.domoticz.com/wiki/Get_Sensors_Status

Re: Check last seen?

Posted: Sunday 22 January 2017 3:29
by elmortero
I think what are looking for is in the dzvents examples.
https://github.com/dannybloe/dzVents/tr ... s/examples
Look for check dead devices.lua
That script checks for device that have not been updated for x minutes

Re: Check last seen?

Posted: Sunday 22 January 2017 13:19
by Calzor Suzay
Siewert308SW wrote:You didn't mention you want info for Dz, then ask there.
As for Lua, you could amend this one:
This post is in the specific dzVents Lua Framework sub forum so one could assume I'm asking about that :roll:

Re: Check last seen?

Posted: Sunday 22 January 2017 13:27
by Siewert308SW
Calzor Suzay wrote:
Siewert308SW wrote:You didn't mention you want info for Dz, then ask there.
As for Lua, you could amend this one:
This post is in the specific dzVents Lua Framework sub forum so one could assume I'm asking about that :roll:
My mistake, didn't notice that.
But nevermind hope someone with dzvent knowledge can help.

Re: Check last seen?

Posted: Sunday 29 January 2017 21:48
by Calzor Suzay
Think I got this working by taking the sample and swopping my devices and timing etc. :)

Re: Check last seen?

Posted: Friday 20 March 2020 9:46
by MikeF
elmortero wrote: Sunday 22 January 2017 3:29 I think what are looking for is in the dzvents examples.
https://github.com/dannybloe/dzVents/tr ... s/examples
Look for check dead devices.lua
That script checks for device that have not been updated for x minutes
This is exactly what I am looking for, as I have a couple of devices which stop sending from time to time - except that, as it stands, this script will keep sending every 5 minutes. Is there a way of changing this, so that it only sends once?

Re: Check last seen?

Posted: Friday 20 March 2020 18:35
by waaren
MikeF wrote: Friday 20 March 2020 9:46 This is exactly what I am looking for, as I have a couple of devices which stop sending from time to time - except that, as it stands, this script will keep sending every 5 minutes. Is there a way of changing this, so that it only sends once?
This should send the notification once every 12 hours (adjustable)

Code: Select all

 --[[
        Check dead device using their description
--]]

local repeatNotificationHours = 12

return
{
    on =
    {
        timer =
        {
            'every 5 minutes during daytime',
        },
    },

    data =
    {
        notifications =
        {
            initial = {},
        },
    },
   
    execute = function(dz, item)

        local function notify(device)
            local message = 'Device ' .. device.name .. ' seems to be dead. No update for ' .. device.lastUpdate.minutesAgo .. ' minutes'
            dz.log(message)

            if dz.data.notifications[device.name] and dz.data.notifications[device.name] > dz.time.dDate then
                dz.log('No notification needed now')
            else
                dz.notify('Dead devices', message, dz.PRIORITY_HIGH)
                dz.data.notifications[device.name] = dz.time.dDate + repeatNotificationHours * 3600
            end
        end

        local maxIdleTime
        dz.devices().forEach(function(device)
            if (device.description or ''):match('CDA:%s*%d+') then
                maxIdleTime =  (device.description):gsub('CDA:',''):gsub(' ','')
                maxIdleTime = tonumber(maxIdleTime)
                if device.lastUpdate.minutesAgo > maxIdleTime then
                    notify(device)
                end
            end
        end)
    end
}

Re: Check last seen?  [Solved]

Posted: Friday 20 March 2020 23:43
by MikeF
Many thanks, @waaren - this is a very neat solution, and works nicely! :D

I had tried extending the check dead devices.lua script to update an alert sensor but only trigger an email if this had been set to red in less than 24 hours. However, this is much neater, as I don't need to edit the script to insert the names of the devices I want to check - instead, I can use the device description in the Domoticz GUI for the devices I want to monitor.