Notification for Dead nodes?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Notification for Dead nodes?

Post by emme »

Ciao,
The more I implement script and automate stuff, the less I look at the interface on a standard WebPage...

But sometimes it happends that I lost connection on several devices (zWave and 433) due to any kind of problems (that are not the main object of this post :P)

The last issue cames Saturday when the RBPI lost connection on the 433 devices....

Is there a way to notify if the server has lost connection to a device? or do I have to code a time events that check the _lastupdate of each device and evaluate if it has to be communicate that connection has lost ?

ciao
M
The most dangerous phrase in any language is:
"We always done this way"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Notification for Dead nodes?

Post by Egregius »

http://127.0.0.1:8084/json.htm?type=ope ... odes&idx=3 returns the status off all zwave nodes (idx is from the hardware controller).
In the response you'll see if a node is marked as dead.

Besides that you could setup something to check the last update time. Be aware that you should use a different timeout for each sensor type to avoid false positives.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Notification for Dead nodes?

Post by emme »

...good to know! thank you!!!

what about other non-zwave device?
will the _lastupdate check be the correct path to follow?
can it be included somehow in the future versions of Domoticz?

(I'll share my script as soon as I finalize it :P)
The most dangerous phrase in any language is:
"We always done this way"
JohnBoy32
Posts: 16
Joined: Friday 04 March 2016 9:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Notification for Dead nodes?

Post by JohnBoy32 »

I have been working on this one. Thanks to the people above!
But....

I am trying to get through the Domoticz-API and within LUA the information about dead notes.
LUA is what I prefer to use: all my logic is in LUA and the logic is part of Domoticz standard backup.

My problem is that the call of JSON is not delivering any result, or I have to wat till the script is running 10 seconds and automatically stopped.

Example 1 is giving me the result I want, but is hanging Domoticz for 10 seconds (not acceptable of course).

Code: Select all

n = os.tmpname ()
os.execute('curl -v "http://127.0.0.1:8080/json.htm?type=openzwavenodes&idx=4" --stderr - | grep Dead > ' ..n)
for line in io.lines (n) do
        print (line)
end
os.remove (n)
result:
2018-03-31 08:33:15.042 User: Admin initiated a switch command (350/Test/On)
2018-03-31 08:33:25.333 Error: EventSystem: Warning!, lua script script_device_Test.lua has been running for more than 10 seconds
2018-03-31 08:33:25.409 (Virtuele Schakelaars) Lighting 1 (Test)
2018-03-31 08:33:25.492 dzVents: "State" : "Dead",


Example 2 is with a timeout (in this case long so nobody will claim it is not enough for the command) not giving me the result in the file.

Code: Select all

n = os.tmpname ()
os.execute('timeout 9 curl -v "http://127.0.0.1:8080/json.htm?type=openzwavenodes&idx=4" --stderr - | grep Dead > ' ..n)
for line in io.lines (n) do
      print (line)
end
os.remove (n)
result:
2018-03-31 08:35:05.524 User: Admin initiated a switch command (350/Test/On)
2018-03-31 08:35:14.808 (Virtuele Schakelaars) Lighting 1 (Test)


Example 3 is without using curl and json and giving me the right result.

Code: Select all

n = os.tmpname ()
os.execute('ls -l | grep History > ' ..n)
for line in io.lines (n) do
        print (line)
end
os.remove (n)
result:
2018-03-31 08:47:29.888 User: Admin initiated a switch command (350/Test/On)
2018-03-31 08:47:30.123 dzVents: -rw-r--r-- 1 pi pi 84449 Jul 30 2017 History.txt
2018-03-31 08:47:30.165 (Virtuele Schakelaars) Lighting 1 (Test)


My set:
Raspbian GNU/Linux 8 (jessie)
Domoticz: Version: 3.8153
Build Hash: 494fff7
Compile Date: 2017-07-30 12:19:41

All commands used are running fine on commandline (SSH); also the second one!
Using “wget” or “io.popen“ is giving me the same not-wanted results.

I have to admit I cannot solve it and my guesses: :?: :?:
- It is not possible to call the Domoticz-api from LUA in domoticz itself?
- The is something triggy/buggy in the json combi with LUA/Curl?
- I am making a mistakes……?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification for Dead nodes?

Post by waaren »

I am using the script below for more than a year now. Just give the max. allowed time a device is not updated after the string "CDA:" (short for Check Device update timeout Allowed) in the description field of a device and execute the dzVents script

Code: Select all

 --[[ 
 CheckDeadDevicesByDesc.lua 
 ]]-- 
 
return {
    on = {
            timer = { 'at 09:00-22:00 at *:13' }   -- every 13 minutes after the hour at hours I want to be notified
    },
    
    execute = function(domoticz, _)
        local message=""

        domoticz.devices().forEach(function(device)
            if (device.description ~= nil) then
		_, _, threshold = string.find(device.description,"CDA:(%d+)")   -- get the minutes after CDA if any
		if (threshold ~= nil) then
			local name = device.name
			local minutes = domoticz.devices(name).lastUpdate.minutesAgo
			if ( minutes > tonumber(threshold)) then
				message = message .. 'Device ' .. name .. ' seems to be dead. No heartbeat for at least ' .. minutes .. ' minutes.\r'
			end
		end
            end
        end)

        if (message ~= "") then
                domoticz.notify('Dead devices', message, domoticz.PRIORITY_NORMAL)
                print ("Dead devices found: " .. message)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
heggink
Posts: 979
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Notification for Dead nodes?

Post by heggink »

@waaren: great script BUT, I have a bunch of zwave door sensors that have a 12h wakeup. Unfortunately, lastupdate does not reflect the wakeup but the door state. When querying domoticz, I see both dates but your script (i.e. dzventz) only reports the update state.

Ideally, I would want to monitor all battery devices. Whilst I already monitor battery states, these sometimes drop too fast in order to be correctly reported on :-(.

Here's the device response from domoticz. If we could get the first lastupdate from dzvents then would that be the device wakeup timer?

Code: Select all

      {
         "Description" : "BeNext Door Sensor",
         "HaveUserCodes" : false,
         "HomeID" : 3663738776,
         "IsPlus" : false,
         "LastUpdate" : "2018-03-31 12:33:14",
         "Manufacturer_id" : "0x008a",
         "Manufacturer_name" : "BeNext",
         "Name" : "Zijdeur Sensor",
         "NodeID" : 33,
         "PollEnabled" : "false",
         "Product_id" : "0x0101",
         "Product_name" : "Door Sensor",
         "Product_type" : "0x0004",
         "State" : "Sleeping",
         "Version" : 4,
         "config" : [
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "Set all configuration values to default values (factory settings).",
               "index" : 1,
               "label" : "Set to Default",
               "type" : "byte",
               "units" : "",
               "value" : "255"
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "Configure what the external contact sends when triggered. (Default: 0)",
               "index" : 2,
               "label" : "External Contact",
               "list_items" : 2,
               "listitem" : [
                  "Send a alarm report with type 2.",
                  "Send a Basic set frame to all nodes in association group 2."
               ],
               "type" : "list",
               "units" : "",
               "value" : "Send a alarm report with type 2."
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "Is not used but can still be set and requested.",
               "index" : 3,
               "label" : "Not used",
               "type" : "byte",
               "units" : "",
               "value" : "0"
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "Is not used but can still be set and requested.",
               "index" : 4,
               "label" : "Not used",
               "type" : "byte",
               "units" : "",
               "value" : "0"
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "To configure the operating mode. (Default: 1)",
               "index" : 5,
               "label" : "The Mode",
               "type" : "byte",
               "units" : "",
               "value" : "1"
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "A signed integer to determine the offset of the temperature. (Default: 0)",
               "index" : 6,
               "label" : "Temperature offset",
               "type" : "int",
               "units" : "",
               "value" : "0"
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "Debounce time when the external contact is opened. (Default: 0)",
               "index" : 7,
               "label" : "Extern Contact Debounce ON",
               "type" : "byte",
               "units" : "",
               "value" : "0"
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "Debounce time when the external contact is opened. (Default 0)",
               "index" : 8,
               "label" : "Extern Contact Debounce OFF",
               "type" : "byte",
               "units" : "",
               "value" : "0"
            },
            {
               "LastUpdate" : "2018-03-29 21:27:17",
               "help" : "A delay from the wake up time to give the external contact a chance to change his status. (Default 0, value * 100 ms, 0 - 25,5 seconds)",
               "index" : 9,
               "label" : "Wake up delay",
               "type" : "byte",
               "units" : "",
               "value" : "0"
            },
            {
               "LastUpdate" : "2018-03-29 21:35:08",
               "help" : "",
               "index" : 2000,
               "label" : "Wake-up Interval",
               "type" : "int",
               "units" : "Seconds",
               "value" : "7200"
            }
         ],
         "idx" : "18"
      },
  
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification for Dead nodes?

Post by waaren »

@heggink, I am not sure I completely follow.

When I do a http://192.168.nnn.nnn:pppp/json.htm?type=devices&rid=689 my return is

Code: Select all

{
"ActTime": 1522495314,
"AstrTwilightEnd": "22:12",
"AstrTwilightStart": "05:20",
"CivTwilightEnd": "20:47",
"CivTwilightStart": "06:45",
"DayLength": "12:54",
"NautTwilightEnd": "21:28",
"NautTwilightStart": "06:04",
"ServerTime": "2018-03-31 13:21:54",
"SunAtSouth": "13:05",
"Sunrise": "07:19",
"Sunset": "20:13",
"result": [
{
"AddjMulti": 1,
"AddjMulti2": 1,
"AddjValue": 0,
"AddjValue2": 0,
"BatteryLevel": 100,
"CustomImage": 0,
"Data": "Closed",
"Description": "",
"Favorite": 0,
"HardwareID": 4,
"HardwareName": "Aeotec  Zwave stick",
"HardwareType": "OpenZWave USB",
"HardwareTypeVal": 21,
"HaveDimmer": true,
"HaveGroupCmd": true,
"HaveTimeout": false,
"ID": "00000B00",
"Image": "Light",
"IsSubDevice": false,
"LastUpdate": "2018-03-31 08:10:51",
"Level": 0,
"LevelInt": 0,
"MaxDimLevel": 100,
"Name": "Slaapkamer raam",
"Notifications": "false",
"PlanID": "0",
"PlanIDs": [
0
],
"Protected": false,
"ShowNotifications": true,
"SignalLevel": "-",
"Status": "Closed",
"StrParam1": "",
"StrParam2": "",
"SubType": "Switch",
"SwitchType": "Contact",
"SwitchTypeVal": 2,
"Timers": "false",
"Type": "Light/Switch",
"TypeImg": "contact",
"Unit": 1,
"Used": 1,
"UsedByCamera": false,
"XOffset": "0",
"YOffset": "0",
"idx": "689"
}
],
"status": "OK",
"title": "Devices"
} 
What json do you send to domoticz to get your result ?

[Edit] I see now that your result is from querying /json.htm?type=openzwavenodes&idx=4
I am not aware that it is possible in dzVents to use this directly.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Notification for Dead nodes?

Post by Geitje »

Thanks for this script @waaren. It works fine for my zigbee devices (Zigate). However it does not seem to work for my Zwave devices. I use OpenZwave. My Zwave devices have offline times of 40000+, whilst they work (tested water leakage sensor), so they are not dead. I know this is not caused by the plugin, but is there any way to get notified of dead Zwave devices?
waaren wrote: Saturday 31 March 2018 9:35 I am using the script below for more than a year now. Just give the max. allowed time a device is not updated after the string "CDA:" (short for...
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification for Dead nodes?

Post by waaren »

Geitje wrote: Tuesday 04 May 2021 14:31 Is there any way to get notified of dead Zwave devices?
Yes but it requires a different approach then for the other devices. The script should query the zWave nodes and must contain a table with the mapping of ZWave NodeID against the domoticz device idx (the same table could then also be used for setting the max idle time)

Could look like below

Code: Select all

local hardwareID = 4  -- change to your Zwave controller Hardware ID
local scriptVar = 'getZwaveNodes'

return
{
    on =
    {
        timer =
        {
            'every 2 hours', -- set to your liking
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when all OK
        marker = scriptVar,
    },

    execute = function(dz, item)

        mapping =
        {
            -- [nodeID] = { dzIDX, maxIdleTime in minutes },
            [3] = { 20, 60 },
            [6] = {2745, 120 },
            [8] = {79, 180 },
            [16] = { 1183, 150},
            [12] = { 591, 4},
        }

        if not item.isHTTPResponse then
            dz.openURL(
                {
                    url = dz.settings['Domoticz url'] .. '/json.htm?type=openzwavenodes&idx=' .. hardwareID,
                    callback = scriptVar,
                })
            return
        end

        if item.ok and item.isJSON then
            rt = item.json.result

            for _, device in ipairs(rt) do
                message =   'Device ' .. ( device.Name or '?' ) ..
                            ', node: ' .. ( device.NodeID or '-')..
                            ', ID in domoticz: ' .. ( ( mapping[device.NodeID] and mapping[device.NodeID][1] ) or '-' ) ..
                            ' ==>> state: ' .. ( device.State or 'Not set')..
                            ', last updated: ' .. ( device.LastUpdate or '-' )

                dz.log( message, dz.LOG_DEBUG)

                if mapping[device.NodeID] then
                    local pTime = dz.time.addMinutes(- mapping[device.NodeID][2]).rawDateTime
                    if pTime < device.LastUpdate then
                        dz.notify("DEAD device", message .. ' seems to be dead. Check it out ', dz.PRIORITY_HIGH, nil, nil, dz.NSS_PUSHOVER)
                    end
                end
            end

        else
            dz.log('There was a problem handling the request: ' .. item.statusText , dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end

    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Notification for Dead nodes?

Post by Geitje »

Thanks @Waaren. Works fine. First I got a dead notification of every node. I had to change < to > in line 58, am I right?
At least this works for me :) :

Code: Select all

                    if pTime > device.LastUpdate then 
Also I changed line 59 to:

Code: Select all

                        dz.notify("DEAD device", message .. ' seems to be dead. Check it out ', dz.PRIORITY_NORMAL) 
to get notified on every channel (Telegram, Domoticz app etc.).
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification for Dead nodes?

Post by waaren »

Geitje wrote: Saturday 08 May 2021 23:12 First I got a dead notification of every node. I had to change < to > in line 58, am I right?
Yes you are. My mistake :oops:
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Notification for Dead nodes?

Post by Geitje »

This may be a trivial question but I can't find the answer so far:
Is this normal?:
I have some Popp & Co smoke detectors/sirens, and their wake up interval is really long. Last wake up now is 1/5/21 (I think that is when I rebooted my Pi). I do not see the setting to customize the interval in #/Hardware/[Zwave IDx] -> NodeID page. For some other devices this can be set.

When its normal, the problem is I will only be able to discover a dead node after 2 weeks or so. I think I will use an alarm for almost empty battery instead. However a otherwise defect node (wil not happen often) will be discovered with quite some delay....
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest