Check dead devices help

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

Moderator: leecollings

Post Reply
mikejclark
Posts: 23
Joined: Tuesday 03 September 2013 21:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Check dead devices help

Post by mikejclark »

Would really appreciate some help adapting the example check dead devices script.
https://github.com/dannybloe/dzVents/bl ... evices.lua

The script I have adapted for my sensors runs, and if one the sensors has not been seen for a while, as expected I receive an email with a list of dead devices... great!

The problem is, that if there are no dead devices, I still receive an email with something like the following:
----------------762475179556452285591111
Content-type: text/plain; charset=utf-8; format=flowed
Content-transfer-encoding: 7bit
Unfortunately I do not understand dzVents enough yet to know what's happening here. I would expect that you would only get an email if there is a dead device? At the moment I get an email every 5 minutes regardless.

Code: Select all

local devicesToCheck = {
	{ ['name'] = 'Lounge Temperature', ['threshold'] = 30 },
	{ ['name'] = 'Front Bedroom Temperature', ['threshold'] = 30 }
}

return {
	active = true,
	on = {
		['timer'] = {
			'every 5 minutes'
		}
	},
	execute = function(domoticz)

		local message = ""

		for i, deviceToCheck in pairs(devicesToCheck) do
			local name = deviceToCheck['name']
			local threshold = deviceToCheck['threshold']
			local minutes = domoticz.devices(name).lastUpdate.minutesAgo

			if ( minutes > threshold) then
				message = message .. 'Device ' ..
						name .. ' seems to be dead. No heartbeat for at least ' ..
						minutes .. ' minutes.\r'
			end
		end

		if (message) then
			domoticz.email('Dead devices', message, '[email protected]')
			domoticz.log('Dead devices found: ' .. message, domoticz.LOG_ERROR)
		end
	end
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Check dead devices help

Post by dannybloe »

I think you could try to change the last if-statement to:

Code: Select all

if (message ~= "") then
. I suspect Lua evaluates an empty string as true. The idea of the script above is that a message is constructed in the loop and that if there is something in the message it will be emailed.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
mikejclark
Posts: 23
Joined: Tuesday 03 September 2013 21:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check dead devices help

Post by mikejclark »

dannybloe wrote: Sunday 17 September 2017 12:00 I think you could try to change the last if-statement to:

Code: Select all

if (message ~= "") then
. I suspect Lua evaluates an empty string as true. The idea of the script above is that a message is constructed in the loop and that if there is something in the message it will be emailed.
Thank you so much, will give this a go
mikejclark
Posts: 23
Joined: Tuesday 03 September 2013 21:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check dead devices help

Post by mikejclark »

dannybloe wrote: Sunday 17 September 2017 12:00 I think you could try to change the last if-statement to:

Code: Select all

if (message ~= "") then
. I suspect Lua evaluates an empty string as true. The idea of the script above is that a message is constructed in the loop and that if there is something in the message it will be emailed.
So far so good... I think your adjustment has worked, thanks!
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: Check dead devices help

Post by pgas37 »

I have a simular problem with exact the same script. I adjusted the message section but before i receive a message an error occur:
Error: dzVents: Error: ...oticz/scripts/dzVents/generated_scripts/DeaddevicesV.lua:20: attempt to index field 'lastUpdate' (a nil value)

A nil value. What can i do about this problem?

thanks
Paul
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest