Check last seen?  [Solved]

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

Moderator: leecollings

Post Reply
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Check last seen?

Post 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
User avatar
Siewert308SW
Posts: 294
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Check last seen?

Post 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 ;-)
Setup:
- DS923+ Docker
Domoticz Latest Stable
Mosquitto / ZwaveJSUI @ Aeotec Z-Stick Gen5+ / PiHole Unbound
P1 USB Gas/Power, HW watermeter
- A lot of Zwave switches, contacts, plugs, smoke/Co2 ect
- DiY 7.5kWh Solar Storage @ GitHuB
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Check last seen?

Post 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?
User avatar
Siewert308SW
Posts: 294
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Check last seen?

Post 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
Setup:
- DS923+ Docker
Domoticz Latest Stable
Mosquitto / ZwaveJSUI @ Aeotec Z-Stick Gen5+ / PiHole Unbound
P1 USB Gas/Power, HW watermeter
- A lot of Zwave switches, contacts, plugs, smoke/Co2 ect
- DiY 7.5kWh Solar Storage @ GitHuB
elmortero
Posts: 248
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Check last seen?

Post 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
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Check last seen?

Post 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:
User avatar
Siewert308SW
Posts: 294
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Check last seen?

Post 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.
Setup:
- DS923+ Docker
Domoticz Latest Stable
Mosquitto / ZwaveJSUI @ Aeotec Z-Stick Gen5+ / PiHole Unbound
P1 USB Gas/Power, HW watermeter
- A lot of Zwave switches, contacts, plugs, smoke/Co2 ect
- DiY 7.5kWh Solar Storage @ GitHuB
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Check last seen?

Post by Calzor Suzay »

Think I got this working by taking the sample and swopping my devices and timing etc. :)
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Check last seen?

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check last seen?

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Check last seen?  [Solved]

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest