Page 1 of 1

System-alive-checker, final setup

Posted: Friday 21 February 2020 1:29
by HvdW
Hi,
I have setup 2 system-alive devices CV-17 and Luftdaten to check 2 ESP8266 units like explained in the Domoticz WiKi.
Notification is set for switch-off using pushbullet.
They're working as expected.
Setting Pushbullet to Enabled (in Settings->Notifications) it will send a pushmessage for these devices as well for all the other devices in my Domoticz setup.
That is where this script originating from @Dannybloe comes in.
I want notifications for just these 2 devices, not alarming at first notice but after a while and after double-checking.

Code: Select all

-- this script can be used in conjunction with the System-alive checker plug-in.
-- the plugin pings a list of devices and creates switches for these devices
-- the reason for this script is to not treat devices as dead immediately after they
-- do not respond. More often than not, the second ping atempt does work. So only
-- if the device has been not responding for a while AFTER it is been presumed dead
-- then this script will notify you
-- put the names of these switches in the devicesToCheck list
-- you may have to tweak the THRESHOLD depending on the check interval

local THRESHOLD = 10 -- minutes
local devicesToCheck = {'CV-17', 'Luftdaten'}

return {
	active = true,
	on = {
		devices = devicesToCheck,
		timer = 'every 5 minutes'
	},
	data = {
		notified = { initial = {} }
	},
	execute = function(domoticz, device, triggerInfo)

		if (triggerInfo.type == domoticz.EVENT_TYPE_TIMER) then

			-- check all devices that are off and have not been updated in the past 5 minutes and have not been notified for
			for index, deviceName in pairs(devicesToCheck) do

				local device = domoticz.devices[deviceName]

				if (device.state == 'Off' and
						device.lastUpdate.minutesAgo >= THRESHOLD and
						domoticz.data.notified[deviceName] == false) then

					domoticz.notify(deviceName .. ' is not responding anymore.',' ',domoticz.PRIORITY_HIGH)

					-- make sure we only notify once for this device in this case
					domoticz.data.notified[deviceName] = true
				end
			end


		else
			domoticz.data.notified[device.name] = false

		end

	end
}
What I expected it to do is send a Pushbullet message.
It doesn't.
I must have overseen something.
Help is appreciated.

Re: System-alive-checker, final setup  [Solved]

Posted: Friday 21 February 2020 1:40
by waaren
HvdW wrote: Friday 21 February 2020 1:29 I must have overseen something.
Help is appreciated.
besides false and true a value can also be nil

Can you try and change

Code: Select all

domoticz.data.notified[deviceName] == false
to

Code: Select all

domoticz.data.notified[deviceName] ~= true

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 0:07
by HvdW
@waaren
I've been testing the if statement and it's definitly the

Code: Select all

domoticz.data.notified[deviceName] ~= true
that does not respond.
same goes for

Code: Select all

domoticz.data.notified[deviceName] == false

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 1:16
by waaren
HvdW wrote: Saturday 04 April 2020 0:07 I've been testing the if statement and it's definitly the

Code: Select all

domoticz.data.notified[deviceName] ~= true
that does not respond.
same goes for

Code: Select all

domoticz.data.notified[deviceName] == false
Please always include log when reporting script issues on the forum. It will make it so much easier to help you... Thx

Can you try this. The example you used is from the early days of dzVents. A lot have changed since then..

Code: Select all

-- this script can be used in conjunction with the System-alive checker plug-in.
-- the plugin pings a list of devices and creates switches for these devices
-- the reason for this script is to not treat devices as dead immediately after they
-- do not respond. More often than not, the second ping atempt does work. So only
-- if the device has been not responding for a while AFTER it is been presumed dead
-- then this script will notify you
-- put the names of these switches in the devicesToCheck list
-- you may have to tweak the THRESHOLD depending on the check interval

local THRESHOLD = 10 -- minutes
local devicesToCheck = 
        {
            'CV-17', 
            'Luftdaten',
        }

return 
{
    on = 
    {
        devices = devicesToCheck,

        timer = 
        { 
            'every 5 minutes',
        },
    },

    data = 
    {
        notified = { initial = {} }
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when script executes without problems
        marker = 'notify',
    },

    execute = function(dz, item)
        if item.isTimer then
            for index, deviceName in ipairs(devicesToCheck) do
                dz.log('device ' .. deviceName, dz.LOG_DEBUG)        
                local device = dz.devices(deviceName) 
                if device.state == 'Off' and device.lastUpdate.minutesAgo >= THRESHOLD and dz.data.notified[deviceName] ~= true  then
                    dz.log('Idle device ' .. deviceName, dz.LOG_DEBUG)        
                    dz.notify('notifyer', deviceName .. ' is not responding anymore.',dz.PRIORITY_HIGH)
                    dz.data.notified[deviceName] = true
                end
            end
        else
            dz.data.notified[item.name] = false
        end
    end
}

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 21:47
by HvdW
I had already replaced it with the example from the 2020.1 version.
I have setup your dzvents script and it is running with a threshold of 2 minutes and a every minute check.
If won't enter the if loop.

Here's the log output.

Code: Select all

 2020-04-04 21:43:00.275 Status: dzVents: Info: notify: ------ Start internal script: System-alive-check:, trigger: "every minute"
2020-04-04 21:43:00.275 Status: dzVents: Debug: notify: device CV-ping
2020-04-04 21:43:00.290 Status: dzVents: Debug: notify: Processing device-adapter for CV-ping: Switch device adapter
2020-04-04 21:43:00.290 Status: dzVents: Debug: notify: device Luftdaten PM10
2020-04-04 21:43:00.291 Status: dzVents: Debug: notify: Processing device-adapter for Luftdaten PM10: Custom sensor device adapter
2020-04-04 21:43:00.292 Status: dzVents: Info: notify: ------ Finished System-alive-check 

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 22:07
by waaren
HvdW wrote: Saturday 04 April 2020 21:47
I have setup your dzvents script and it is running with a threshold of 2 minutes and a every minute check.
It won't enter the if loop.
I added some log statements to help you identify what is happening.

To prevent conflicts when using dzVents scripts with a data section you have to remove the data file before saving a new version.
The data file is <domoticz dir>/scripts/dzVents/data/__data_<scriptname>.lua>

Code: Select all

-- this script can be used in conjunction with the System-alive checker plug-in.
-- the plugin pings a list of devices and creates switches for these devices
-- the reason for this script is to not treat devices as dead immediately after they
-- do not respond. More often than not, the second ping atempt does work. So only
-- if the device has been not responding for a while AFTER it is been presumed dead
-- then this script will notify you
-- put the names of these switches in the devicesToCheck list
-- you may have to tweak the THRESHOLD depending on the check interval

local THRESHOLD = 10 -- minutes
local devicesToCheck = 
        {
            'CV-17', 
            'Luftdaten',
        }

return 
{
    on = 
    {
        devices = devicesToCheck,

        timer = 
        { 
            'every 5 minutes',
        },
    },

    data = 
    {
        notified = { initial = {} },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when script executes without problems
        marker = 'notify',
    },

    execute = function(dz, item)
        if item.isTimer then
            for index, deviceName in ipairs(devicesToCheck) do
                local device = dz.devices(deviceName) 
                
                dz.log('device name  ' .. device.name, dz.LOG_DEBUG) 
                dz.log('device state ' .. device.state, dz.LOG_DEBUG)        
                dz.log('device lastUpdate ' .. device.lastUpdate.minutesAgo, dz.LOG_DEBUG)        
                dz.log('device notified ' .. tostring(dz.data.notified[deviceName]), dz.LOG_DEBUG)        
                                
                if device.state == 'Off' and device.lastUpdate.minutesAgo >= THRESHOLD and dz.data.notified[deviceName] ~= true  then
                    dz.log('Idle device ' .. deviceName, dz.LOG_DEBUG)        
                    dz.notify('notifyer', deviceName .. ' is not responding anymore.',dz.PRIORITY_HIGH)
                    dz.data.notified[deviceName] = true
                end
            end
        else
            dz.data.notified[item.name] = false
        end
    end
}

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 22:50
by HvdW
Hi @waaren
Here is the result when both are responding:

Code: Select all

  2020-04-04 23:06:00.227 Status: dzVents: Info: notify: ------ Start internal script: System-alive-check:, trigger: "every minute"
2020-04-04 23:06:00.243 Status: dzVents: Debug: notify: Processing device-adapter for CV-ping: Switch device adapter
2020-04-04 23:06:00.243 Status: dzVents: Debug: notify: device name CV-ping
2020-04-04 23:06:00.243 Status: dzVents: Debug: notify: device state On
2020-04-04 23:06:00.243 Status: dzVents: Debug: notify: device lastUpdate 1332
2020-04-04 23:06:00.243 Status: dzVents: Debug: notify: device notified nil
2020-04-04 23:06:00.244 Status: dzVents: Debug: notify: Processing device-adapter for Luftdaten PM10: Custom sensor device adapter
2020-04-04 23:06:00.244 Status: dzVents: Debug: notify: device name Luftdaten PM10
2020-04-04 23:06:00.244 Status: dzVents: Debug: notify: device state 10.43
2020-04-04 23:06:00.244 Status: dzVents: Debug: notify: device lastUpdate 2
2020-04-04 23:06:00.244 Status: dzVents: Debug: notify: device notified false
2020-04-04 23:06:00.245 Status: dzVents: Info: notify: ------ Finished System-alive-check  
Below when CV switch is unplugged:

Code: Select all

 2020-04-04 23:08:23.230 Status: dzVents: Info: Handling events for: "CV-ping", value: "Off"
2020-04-04 23:08:23.230 Status: dzVents: Info: notify: ------ Start internal script: System-alive-check: Device: "CV-ping (System Alive Checker)", Index: 59
2020-04-04 23:08:23.231 Status: dzVents: Info: notify: ------ Finished System-alive-check 
After round 1:

Code: Select all

 2020-04-04 23:09:00.280 Status: dzVents: Info: notify: ------ Start internal script: System-alive-check:, trigger: "every minute"
2020-04-04 23:09:00.295 Status: dzVents: Debug: notify: Processing device-adapter for CV-ping: Switch device adapter
2020-04-04 23:09:00.295 Status: dzVents: Debug: notify: device name CV-ping
2020-04-04 23:09:00.295 Status: dzVents: Debug: notify: device state Off
2020-04-04 23:09:00.295 Status: dzVents: Debug: notify: device lastUpdate 0
2020-04-04 23:09:00.295 Status: dzVents: Debug: notify: device notified false
2020-04-04 23:09:00.296 Status: dzVents: Debug: notify: Processing device-adapter for Luftdaten PM10: Custom sensor device adapter
2020-04-04 23:09:00.296 Status: dzVents: Debug: notify: device name Luftdaten PM10
2020-04-04 23:09:00.296 Status: dzVents: Debug: notify: device state 10.43
2020-04-04 23:09:00.297 Status: dzVents: Debug: notify: device lastUpdate 5
2020-04-04 23:09:00.297 Status: dzVents: Debug: notify: device notified false
2020-04-04 23:09:00.297 Status: dzVents: Info: notify: ------ Finished System-alive-check 
After round 2:

Code: Select all

 2020-04-04 23:11:00.309 Status: dzVents: Info: notify: ------ Start internal script: System-alive-check:, trigger: "every minute"
2020-04-04 23:11:00.325 Status: dzVents: Debug: notify: Processing device-adapter for CV-ping: Switch device adapter
2020-04-04 23:11:00.325 Status: dzVents: Debug: notify: device name CV-ping
2020-04-04 23:11:00.325 Status: dzVents: Debug: notify: device state Off
2020-04-04 23:11:00.325 Status: dzVents: Debug: notify: device lastUpdate 2
2020-04-04 23:11:00.325 Status: dzVents: Debug: notify: device notified false
2020-04-04 23:11:00.325 Status: dzVents: Debug: notify: Idle device CV-ping
2020-04-04 23:11:00.326 Status: dzVents: Debug: notify: Processing device-adapter for Luftdaten PM10: Custom sensor device adapter
2020-04-04 23:11:00.326 Status: dzVents: Debug: notify: device name Luftdaten PM10
2020-04-04 23:11:00.326 Status: dzVents: Debug: notify: device state 10.43
2020-04-04 23:11:00.326 Status: dzVents: Debug: notify: device lastUpdate 7
2020-04-04 23:11:00.326 Status: dzVents: Debug: notify: device notified false
2020-04-04 23:11:00.327 Status: dzVents: Info: notify: ------ Finished System-alive-check 

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 23:05
by waaren
HvdW wrote: Saturday 04 April 2020 22:50 Hi @waaren
Here is the result:

Code: Select all

2020-04-04 22:48:00.552 Status: dzVents: Debug: notify: device name CV-ping
2020-04-04 22:48:00.552 Status: dzVents: Debug: notify: device state On

2020-04-04 22:48:00.553 Status: dzVents: Debug: notify: device name Luftdaten PM10
2020-04-04 22:48:00.553 Status: dzVents: Debug: notify: device state 10.43
Seems to be correct. Both devices do not have state 'Off' so the script skips the if step. No need to send a notification.

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 23:45
by HvdW
Luftdaten off:

Code: Select all

 2020-04-04 23:29:00.503 Status: dzVents: Info: notify: ------ Start internal script: System-alive-check:, trigger: "every minute"
2020-04-04 23:29:00.519 Status: dzVents: Debug: notify: Processing device-adapter for CV-ping: Switch device adapter
2020-04-04 23:29:00.519 Status: dzVents: Debug: notify: device name CV-ping
2020-04-04 23:29:00.519 Status: dzVents: Debug: notify: device state On
2020-04-04 23:29:00.519 Status: dzVents: Debug: notify: device lastUpdate 13
2020-04-04 23:29:00.519 Status: dzVents: Debug: notify: device notified false
2020-04-04 23:29:00.520 Status: dzVents: Debug: notify: Processing device-adapter for Luftdaten: Switch device adapter
2020-04-04 23:29:00.520 Status: dzVents: Debug: notify: device name Luftdaten
2020-04-04 23:29:00.520 Status: dzVents: Debug: notify: device state Off
2020-04-04 23:29:00.520 Status: dzVents: Debug: notify: device lastUpdate 2
2020-04-04 23:29:00.520 Status: dzVents: Debug: notify: [b]device notified nil[/b]
2020-04-04 23:29:00.520 Status: dzVents: Debug: notify: Idle device Luftdaten
2020-04-04 23:29:00.521 Status: dzVents: Info: notify: ------ Finished System-alive-check
2020-04-04 23:29:00.522 Status: EventSystem: Script event triggered: /home/hein/domoticz/dzVents/runtime/dzVents.lua
2020-04-04 23:29:00.524 Status: Notification: notifyer
2020-04-04 23:29:00.525 Status: Notification: notifyer 

Code: Select all

 2020-04-04 23:31:00.464 Status: dzVents: Info: notify: ------ Start internal script: System-alive-check:, trigger: "every minute"
2020-04-04 23:31:00.479 Status: dzVents: Debug: notify: Processing device-adapter for CV-ping: Switch device adapter
2020-04-04 23:31:00.479 Status: dzVents: Debug: notify: device name CV-ping
2020-04-04 23:31:00.479 Status: dzVents: Debug: notify: device state On
2020-04-04 23:31:00.479 Status: dzVents: Debug: notify: device lastUpdate 15
2020-04-04 23:31:00.479 Status: dzVents: Debug: notify: device notified false
2020-04-04 23:31:00.480 Status: dzVents: Debug: notify: Processing device-adapter for Luftdaten: Switch device adapter
2020-04-04 23:31:00.480 Status: dzVents: Debug: notify: device name Luftdaten
2020-04-04 23:31:00.480 Status: dzVents: Debug: notify: device state Off
2020-04-04 23:31:00.480 Status: dzVents: Debug: notify: device lastUpdate 4
2020-04-04 23:31:00.480 Status: dzVents: Debug: notify: [b]device notified true[/b]
2020-04-04 23:31:00.481 Status: dzVents: Info: notify: ------ Finished System-alive-check
2020-04-04 23:31:00.620 Status: EventSystem: Script event triggered: /home/hein/domoticz/dzVents/runtime/dzVents.lua
2020-04-04 23:31:00.659 Status: Notification: notifyer
2020-04-04 23:31:00.659 Status: Notification: notifyer  
Device notified can be nil (in case device state On) or true (in case device state Off)

The script doesn't enter the if statement below:

Code: Select all

if device.state == 'Off' and device.lastUpdate.minutesAgo >= THRESHOLD and dz.data.notified[deviceName] ~= true
I tested with ==true as well.

Re: System-alive-checker, final setup

Posted: Saturday 04 April 2020 23:52
by waaren
HvdW wrote: Saturday 04 April 2020 23:45 The script doesn't enter the if statement below:

Code: Select all

if device.state == 'Off' and device.lastUpdate.minutesAgo >= THRESHOLD and dz.data.notified[deviceName] ~= true
Yes it does. That's why you see the line

Code: Select all

2020-04-04 23:29:00.520 Status: dzVents: Debug: notify: Idle device Luftdaten

Re: System-alive-checker, final setup

Posted: Sunday 05 April 2020 0:11
by HvdW
You're right it is working like it should.
Thanks a lot for helping.

Re: System-alive-checker, final setup

Posted: Sunday 05 April 2020 1:01
by waaren
HvdW wrote: Sunday 05 April 2020 0:11 Why aren't the lines

Code: Select all

dz.notify('notifyer', deviceName .. ' achter de tweede if.',dz.PRIORITY_HIGH)

Code: Select all

dz.notify('notifyer', deviceName .. ' is not responding anymore.',dz.PRIORITY_HIGH)
displayed?
dz.notify does not display. It notifies using the domoticz notification system.

see the wiki
notify(subject, message, priority, sound, extra, subsystem): Function. Send a notification (like Prowl). Priority can be like domoticz.PRIORITY_LOW, PRIORITY_MODERATE, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_EMERGENCY. For sound see the SOUND constants below. subsystem can be a table containing one or more notification subsystems. See domoticz.NSS_subsystem types.