dzvents get hardware (not device) last update time  [Solved]

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

Moderator: leecollings

Post Reply
kispalsz
Posts: 31
Joined: Friday 13 October 2017 19:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

dzvents get hardware (not device) last update time

Post by kispalsz »

Please help me solve my problem!

With Dzvents, I want to read and interpret the last update time of a battery-powered hardware. I wrote hardware directly because the tool only updates on the hardware side during the wake up, not in the tools tab.
I would use this value to detect zombie, detached devices, but there is no way I can extract value with an arrow.
hardware_tab.png
hardware_tab.png (47.78 KiB) Viewed 3126 times
devices_tab.png
devices_tab.png (65.8 KiB) Viewed 3126 times
zwave_param_configuration.png
zwave_param_configuration.png (36.61 KiB) Viewed 3126 times
I read this: https://www.domoticz.com/forum/viewtopi ... 59&t=32730
but it didn't help because I don't see it as having lastupdate value


Thanks.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents get hardware (not device) last update time

Post by waaren »

kispalsz wrote: Tuesday 16 June 2020 12:04 With Dzvents, I want to read and interpret the last update time of a battery-powered hardware. I wrote hardware directly because the tool only updates on the hardware side during the wake up, not in the tools tab.
I would use this value to detect zombie, detached devices, but there is no way I can extract value with an arrow.
Can you try this

Code: Select all

local hardwareID = 4
local scriptVar = 'getZwaveNodes'

return 
{
	on = 
	{
		timer = 
		{
			'every minute'
		},
		
		httpResponses = 
		{
			scriptVar,
		},
	},
	
	logging =
	{
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },


	execute = function(dz, item)
        
		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 
			    dz.log('device ' .. device.Name .. ', last updated: ' .. device.LastUpdate, dz.LOG_DEBUG)
			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
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time

Post by sailmich »

Latest beta / Rpi3b /zstick/OZW1.6
I jumped in here, because I have a similar question or issue. I tried the code for a fibaro double relais who randomly become dead. My domoticz log
Spoiler: show
2020-07-22 11:20:01.744 Error: dzVents: Error: (3.0.11) getZwaveNodes: An error occurred when calling event handler Zombie
2020-07-22 11:20:01.744 Error: dzVents: Error: (3.0.11) getZwaveNodes: ...pi/domoticz/scripts/dzVents/generated_scripts/Zombie.lua:39: bad argument #1 to 'ipairs' (table expected, got nil)
This is the code I use.

Code: Select all

local hardwareID = 77
local scriptVar = 'getZwaveNodes'
return 
{
	on = 
	{
		timer = 
		{
			'every minute'
		},
		
		httpResponses = 
		{
			scriptVar,
		},
	},
	
	logging =
	{
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },


	execute = function(dz, item)
        
		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 
			    dz.log('device ' .. device.Name .. ', last updated: ' .. device.LastUpdate, dz.LOG_DEBUG)
			end
			
		else
		    dz.log('There was a problem handling the request: ' .. item.statusText , dz.LOG_ERROR)
			dz.log(item, dz.LOG_DEBUG)
		end

	end
}

Bildschirmfoto vom 2020-07-22 11-14-14.png
Bildschirmfoto vom 2020-07-22 11-14-14.png (80.38 KiB) Viewed 3065 times
I even don't know if last seen can work because as shown in my screenshot some devices are last seen a couple of days ago but still alive. How does Domoticz notice that a device is dead? Can this be use in dzvents?
I found that follow command should refresh node info. But I just get an error in my browser.
httpS://IP:port/json.htm?type=command&param=requestzwavenodeinfo&idx=X
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents get hardware (not device) last update time

Post by waaren »

sailmich wrote: Wednesday 22 July 2020 11:35 This is the code I use.
I you are sure the hardwareID of your openzwave hardware is 77 then please add

Code: Select all

dz.utils.dumpTable(rt)
as line 39 in your code and show the complete loglines created during execution of the script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time

Post by sailmich »

Bildschirmfoto vom 2020-07-22 16-31-02.png
Bildschirmfoto vom 2020-07-22 16-31-02.png (10.07 KiB) Viewed 3055 times
I don't know if that is what you mean but I already get a remark at line 39 expect 'in' near ','.
kispalsz
Posts: 31
Joined: Friday 13 October 2017 19:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzvents get hardware (not device) last update time

Post by kispalsz »

Replace the value of the first variable with the ID that appears on the hardware tab. It is important to have the AEON stick ID on the hardware tab. For me, this value is 2 because I have another hardware device as well. And not the Aeotec Zwave stick is the first hardware element.
IF you have no other hardware in Domoticz, this value is 1.

The first script works well. Thanks again.

local hardwareID = 77 -> local hardwareID = 1

Code: Select all

local hardwareID = 77
local scriptVar = 'getZwaveNodes'
return 
{
	on = 
	{

sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time

Post by sailmich »

Bildschirmfoto vom 2020-07-22 16-49-20.png
Bildschirmfoto vom 2020-07-22 16-49-20.png (8.36 KiB) Viewed 3051 times
Still the same error but in line 40.
Spoiler: show
2020-07-22 16:43:00.590 Status: dzVents: Info: getZwaveNodes: ------ Start internal script: Zombie:, trigger: "every minute"
2020-07-22 16:43:00.590 Status: dzVents: Debug: getZwaveNodes: OpenURL: url = http://127.0.0.1:xxxx/json.htm?type=openzwavenodes&idx=77
2020-07-22 16:43:00.590 Status: dzVents: Debug: getZwaveNodes: OpenURL: method = GET
2020-07-22 16:43:00.591 Status: dzVents: Debug: getZwaveNodes: OpenURL: post data = nil
2020-07-22 16:43:00.591 Status: dzVents: Debug: getZwaveNodes: OpenURL: headers = nil
2020-07-22 16:43:00.591 Status: dzVents: Debug: getZwaveNodes: OpenURL: callback = getZwaveNodes
2020-07-22 16:43:00.591 Status: dzVents: Info: getZwaveNodes: ------ Finished Zombie
2020-07-22 16:43:00.591 Status: dzVents: Debug: Commands sent to Domoticz:
2020-07-22 16:43:00.591 Status: dzVents: Debug: - OpenURL = {["method"]="GET", ["URL"]="http://127.0.0.1:xxxx/json.htm?type=openzwavenodes&idx=77", ["_trigger"]="getZwaveNodes"}
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time  [Solved]

Post by sailmich »

:o First hardware page my Z-Stick is #2 when I use this in waaren's script I got last update :D Thanks waaren and kispalsz. I will check next time when node 77 is shown as dead device if last update is good to detect it as dead.
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time

Post by sailmich »

I don't know if it would be better to open a new thread or still use this! Last update time doesn't make it (for me). Is there a way to get the node state or device.state if alive or dead? I tried my code inspired by that thread.
https://www.domoticz.com/forum/viewtopi ... de#p232538
Spoiler: show

Code: Select all

return {
	on = {
		devices = {
			'Z-Wave node status'
		}
	},
    	logging = {
        level = domoticz.LOG_DEBUG,
        marker = "Z-wave alive monitor"
    	},
	execute = function(domoticz, device)


		if domoticz.devices('DFhoch').state=='Dead' then --Fibaro double relay switch
		    domoticz.devices('RED').switchOn()        --Dummy switch 
        
	            domoticz.notify("ALARM", 'Een Z-Wave node has gone DEAD!', domoticz.PRIORITY_EMERGENCY)
        

	        end
		domoticz.log("I'm done, have a nice day!...", domoticz.LOG_INFO)
	end
}
domoticz.devices('DFhoch') is dead for sure because when direct switch I got an error in domoticz log. When using the script I get follow log.
Spoiler: show
2020-08-05 10:39:14.592 Status: dzVents: Debug: - Device: Z-Wave node status
2020-08-05 10:39:14.687 Status: dzVents: Info: Handling events for: "Z-Wave node status", value: "Off"
2020-08-05 10:39:14.687 Status: dzVents: Info: Z-wave alive monitor: ------ Start internal script: Script #1: Device: "Z-Wave node status (Dummys)", Index: 239
2020-08-05 10:39:14.687 Status: dzVents: Info: Z-wave alive monitor: Device Z-Wave node status was changed to Off
2020-08-05 10:39:14.689 Status: dzVents: Debug: Z-wave alive monitor: Processing device-adapter for DFhoch: Switch device adapter
2020-08-05 10:39:14.689 Status: dzVents: Info: Z-wave alive monitor: I'm done, have a nice day!...
2020-08-05 10:39:14.690 Status: dzVents: Info: Z-wave alive monitor: ------ Finished Script #1
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents get hardware (not device) last update time

Post by waaren »

sailmich wrote: Wednesday 05 August 2020 10:31 I don't know if it would be better to open a new thread or still use this! Last update time doesn't make it (for me). Is there a way to get the node state or device.state if alive or dead? I tried my code inspired by that thread.
The Zwave state is not directly copied to the device state on the domoticz level. So this will not work.

What do you see when you enter this in your browser?

Code: Select all

http://<domoticz ip: domoticz port>/json.htm?type=openzwavenodes&idx=<Zwave hardware ID>
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time

Post by sailmich »

Bildschirmfoto vom 2020-08-05 11-32-50.png
Bildschirmfoto vom 2020-08-05 11-32-50.png (28.2 KiB) Viewed 2851 times
The state is dead. I read deeper in the quoted thread and saw that I have to use also a bin/bash script. Can I avoid this?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents get hardware (not device) last update time

Post by waaren »

sailmich wrote: Wednesday 05 August 2020 11:36 Bildschirmfoto vom 2020-08-05 11-32-50.png
The state is dead. I read deeper in the quoted thread and saw that I have to use also a bin/bash script. Can I avoid this?
Yes give me some time to adjust the dzVents script. Can you please share the complete json output as plain text between code tags?
Use PM if you don't want to share it here.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time

Post by sailmich »

Too many characters for the whole json. Let me know when you need more information.
Spoiler: show

Code: Select all

28	
Battery	"-"
Description	"FIBARO System FGS222 Double Relay Switch 2x1.5kW"
Generic_type	"Binary Power Switch"
HaveUserCodes	false
HomeID	3938823181
IsPlus	false
LastUpdate	"2020-08-04 17:34:41"
Manufacturer_id	"0x010f"
Manufacturer_name	"FIBARO System"
Name	"Dachfenster"
NodeID	77
PollEnabled	"false"
Product_id	"0x1002"
Product_name	"FGS222 Double Relay Switch 2x1.5kW"
Product_type	"0x0202"
State	"Dead"
Version	4
config	
0	
LastUpdate	"2020-08-01 07:43:22"
help	"Enable/Disable ALL ON/OFF"
index	1
label	"Enable/Disable ALL ON/OFF"
list_items	4
listitem	
0	"ALL ON disabled/ ALL OFF disabled"
1	"ALL ON disabled/ ALL OFF active"
2	"ALL ON active / ALL OFF disabled"
3	"ALL ON active / ALL OFF active"
type	"list"
units	""
value	"ALL ON active / ALL OFF active"
1	
LastUpdate	"2020-08-01 07:43:22"
help	"Auto off relay after specified time, with the possibility of manual override - immediate Off after button push. Default value: 0 Manual override disabled"
index	3
label	"Auto off relay after specified time"
list_items	2
listitem	
0	"Manual override disabled"
1	"Manual override enabled"
type	"list"
units	""
value	"Manual override disabled"
2	
LastUpdate	"2020-08-01 07:43:22"
help	"Time period for auto off, in milliseconds (0,1 s to 6553,5 s) 0 - Auto off disabled Default value: 0"
index	4
label	"Auto off for relay 1"
type	"short"
units	""
value	"0"
3	
LastUpdate	"2020-08-01 07:43:22"
help	"Time period for auto off, in milliseconds (0,1 s to 6553,5 s) 0 - Auto off disabled Default value: 0"
index	5
label	"Auto off for relay 2"
type	"short"
units	""
value	"0"
4	
LastUpdate	"2020-08-01 07:43:22"
help	"Activate/Deactivate association sending for group 1 - Also see param #16"
index	6
label	"Separation of association sending (key 1)"
list_items	3
listitem	
0	"Map status to all devices in group 1 (default)"
1	"Map OFF status to all devices in group 1, Double click on key 1 will send ON to all devices in group 1, all dimmers set to prev.value"
2	"Map OFF status to all devices in group 1, Double click on key 1 will send ON to all devices in group 1, all dimmers set to 100%"
type	"list"
units	""
value	"Map status to all devices in group 1 (default)"
5	
LastUpdate	"2020-08-01 07:43:22"
help	"Key no.2 is not represented by any physical device except of devices on association list. This functionality prevents of lack of reaction on pressing key no.2 through polling devices from association list one by one and checking their actual statuses."
index	7
label	"Control key #2 behaviour"
list_items	2
listitem	
0	"Device status is not checked"
1	"Device status is checked"
type	"list"
units	""
value	"Device status is checked"
6	
LastUpdate	"2020-08-01 07:43:22"
help	"In case of bi-stable switches, define their behaviour (toggle or follow)"
index	13
label	"Inputs behaviour"
list_items	2
listitem	
0	"Toggle"
1	"Follow switch contact (closed=ON, open=OFF)"
type	"list"
units	""
value	"Toggle"
7	
LastUpdate	"2020-08-01 07:43:22"
help	"Binary inputs type configuration"
index	14
label	"Inputs Button/Switch configuration"
list_items	2
listitem	
0	"Mono-stable input (button)"
1	"Bi-stable input (switch)"
type	"list"
units	""
value	"Bi-stable input (switch)"
8	
LastUpdate	"2020-08-01 07:43:22"
help	"Enable/Disable operation of dimmer or roller shutter devices associated to group 1. Available only when using mono-stable inputs (buttons) - Hold button 1 or double-tap for operation"
index	15
label	"Dimmer/Roller shutter control"
list_items	2
listitem	
0	"Disable Dimmer/Roller shutter control"
1	"Enable Dimmer/Roller shutter control"
type	"list"
units	""
value	"Disable Dimmer/Roller shutter control"
9	
LastUpdate	"2020-08-01 07:43:22"
help	"Saving state before power failure"
index	16
label	"Saving state before power failure"
list_items	2
listitem	
0	"State NOT saved at power failure, all outputs are set to OFF upon power restore"
1	"State saved at power failure, all outputs are set to previous state upon power restore"
type	"list"
units	""
value	"State saved at power failure, all outputs are set to previous state upon power restore"
10	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	30
label	"Relay 1: Response to General Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
11	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	31
label	"Relay 1: Response to Water Flood Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"DEACTIVATION - no response to alarm frames"
12	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	32
label	"Relay 1: Response to Smoke, CO, CO2 Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"DEACTIVATION - no response to alarm frames"
13	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	33
label	"Relay 1: Response to Temperature Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"DEACTIVATION - no response to alarm frames"
14	
LastUpdate	"2020-08-01 07:43:22"
help	"Amount of time (ms) the device keeps on flashing after receipt of Alarm Frame"
index	39
label	"ALARM FLASHING alarm time"
type	"short"
units	""
value	"600"
15	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	40
label	"Relay 2: Response to General Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"DEACTIVATION - no response to alarm frames"
16	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	41
label	"Relay 2: Response to Water Flood Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"DEACTIVATION - no response to alarm frames"
17	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	42
label	"Relay 2: Response to Smoke, CO, CO2 Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"DEACTIVATION - no response to alarm frames"
18	
LastUpdate	"2020-08-01 07:43:22"
help	""
index	43
label	"Relay 2: Response to Temperature Alarm"
list_items	4
listitem	
0	"DEACTIVATION - no response to alarm frames"
1	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
2	"ALARM RELAY OFF - relay will turn OFF upon receipt of alarm frame"
3	"ALARM FLASHING - relay will turn ON and OFF periodically (see param.39)"
type	"list"
units	""
value	"ALARM RELAY ON - relay will turn ON upon receipt of alarm frame"
idx	"37"
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents get hardware (not device) last update time

Post by waaren »

sailmich wrote: Wednesday 05 August 2020 12:03 Too many characters for the whole json. Let me know when you need more information.
Could look like below

Code: Select all

local hardwareID = 2 -- change this to hardwareID of your zwave stick 
local scriptVar = 'getZwaveNodes'

return
{
    on =
    {
        timer =
        {
            'every minute', -- set to required frequency or remove
        },

        devices = {
            'Z-Wave node status',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

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

    execute = function(dz, item)

        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

            local deadNodes = {}
            local foundAtLeastOne
            local alarmString = 'One or more Z-Wave node(s) has gone DEAD! '

            for _, device in ipairs(rt) do
                dz.log( 'Checking device ' .. ( device.Name or '?' ) ..
                        ', node: ' .. ( device.NodeID or '-')..
                        ' ==>> state: ' .. ( device.State or 'Not set')..
                        ', last updated: ' .. ( device.LastUpdate or '-' ), dz.LOG_DEBUG)

                if string.upper(device.State or ''):match('DEAD') then
                    deadNodes[device.NodeID] = ( device.Name or 'Unknown' )
                    foundAtLeastOne = true
                end
            end

            if foundAtLeastOne then
                for node, name in pairs(deadNodes) do
                   alarmString = alarmString .. '[' .. node ..': ' .. name ..']'
                end
                -- dz.notify("ALARM", alarmString, dz.PRIORITY_EMERGENCY,nil,nil,dz.NSS_PUSHOVER) -- use this for notification to one defined notification subsystem
                dz.notify("ALARM", alarmString, dz.PRIORITY_EMERGENCY) -- use this for notification to ALL defined notification subsystems
                dz.devices('RED').switchOn()  --Dummy switch
            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
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: dzvents get hardware (not device) last update time

Post by sailmich »

waaren wrote: Wednesday 05 August 2020 12:57
sailmich wrote: Wednesday 05 August 2020 12:03 Too many characters for the whole json. Let me know when you need more information.
Could look like below

Code: Select all

local hardwareID = 2 -- change this to hardwareID of your zwave stick 
local scriptVar = 'getZwaveNodes'

return
{
    on =
    {
        timer =
        {
            'every minute', -- set to required frequency or remove
        },

        devices = {
            'Z-Wave node status',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

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

    execute = function(dz, item)

        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

            local deadNodes = {}
            local foundAtLeastOne
            local alarmString = 'One or more Z-Wave node(s) has gone DEAD! '

            for _, device in ipairs(rt) do
                dz.log( 'Checking device ' .. ( device.Name or '?' ) ..
                        ', node: ' .. ( device.NodeID or '-')..
                        ' ==>> state: ' .. ( device.State or 'Not set')..
                        ', last updated: ' .. ( device.LastUpdate or '-' ), dz.LOG_DEBUG)

                if string.upper(device.State or ''):match('DEAD') then
                    deadNodes[device.NodeID] = ( device.Name or 'Unknown' )
                    foundAtLeastOne = true
                end
            end

            if foundAtLeastOne then
                for node, name in pairs(deadNodes) do
                   alarmString = alarmString .. '[' .. node ..': ' .. name ..']'
                end
                -- dz.notify("ALARM", alarmString, dz.PRIORITY_EMERGENCY,nil,nil,dz.NSS_PUSHOVER) -- use this for notification to one defined notification subsystem
                dz.notify("ALARM", alarmString, dz.PRIORITY_EMERGENCY) -- use this for notification to ALL defined notification subsystems
                dz.devices('RED').switchOn()  --Dummy switch
            end
        else
            dz.log('There was a problem handling the request: ' .. item.statusText , dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end

    end
}
Once again a fantastic job from you! I will try to understand your code. Right now I use the dummy switch RED for a json command to reboot the system. I will try to add some code just to refresh node information for the dead node instead of reboot the system. THX again!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest