Page 1 of 1

Dead zwave devices

Posted: Tuesday 27 September 2016 13:37
by Docc
Is there a way to find if a device is dead or alive in a LUA device script and will a device script be triggered if a device goes dead or alive?
So can I do something like this in a device script for 'MyDeviceName':

if (devicechanged['MyDeviceName'] == 'Dead' ) then
...
or
if (devicechanged['MyDeviceName'] == 'Alive' ) then
...

Re: Dead zwave devices

Posted: Tuesday 27 September 2016 13:43
by emme
I think it could be done by evaluating the time difference between the actua time and the last update value
...the script could be a Time script instead of a Device script and you could use a user variable with the value (in minutes or hours or days or whatever) to trigger the events

ciao
M

Re: Dead zwave devices

Posted: Tuesday 27 September 2016 14:28
by Docc
Yes, I suppose, but I would like it to be more instant or at least within a few seconds of the device change.

Re: Dead zwave devices

Posted: Tuesday 27 September 2016 17:43
by Egregius
Query your devices using the JSON API.
It's in the reply if a device is marked as 'HasTimeout'.
And how are you expecting a dead device to update it's status? Normally they don't, otherwise they aren't dead right?

Re: Dead zwave devices

Posted: Wednesday 28 September 2016 9:01
by Docc
I followed emme's suggestion and wrote the script below.
This is to let Domoticz know when my Verisure alarm is activated.
I use a variable in the script but might change that to a dummy switch since variable events doesn't seem to work properly.

This script sets a variable to indicate the state of my Verisure alarm and sets a scene to off
For this to work you need a Verisure mains plug set to activate when the alarm is armed and a zwave plug in series.
The zwave plug will go dead when the alarm is disarmed and the script checks for that timeout.
It also makes sure that the zwave plug is On when the alarm is armed, to light up a night lamp to show that the alarm is armed.

Code: Select all

function timedifference(s)
   year = string.sub(s, 1, 4)
   month = string.sub(s, 6, 7)
   day = string.sub(s, 9, 10)
   hour = string.sub(s, 12, 13)
   minutes = string.sub(s, 15, 16)
   seconds = string.sub(s, 18, 19)
   t1 = os.time()
   t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
   difference = os.difftime (t1, t2)
   return difference
end

commandArray = {}



		difference = timedifference(otherdevices_lastupdate['Verisure-Status-Voltage'])
		print('difference = ' .. difference)
		
        if difference > 30 then
			
			commandArray['Variable:securityState'] = 'Disarmed'
			print('#Security = Disarmed')
		else
			
			if uservariables['securityState'] == 'Disarmed'	then
				commandArray['Scene:NightMode']='Off'	
				print('Setting Night mode')
			end
			
			commandArray['Variable:securityState'] = 'Armed Home'
			
			print('#Security = Armed Home')
		end

		if (otherdevices['Verisure-Status'] == 'Off') then
			commandArray['Verisure-Status'] = 'On'	
		end
	print('Verisure-Status = ' .. otherdevices['Verisure-Status'])
	print('Variable:securityState = ' .. uservariables['securityState'])	

return commandArray

Re: Dead zwave devices

Posted: Wednesday 28 September 2016 9:26
by emme
mmmmh... just a question as I'm not so skilled in LUA....
doees the time difference function works?
I mean... it would return an array with s.year, s.month etc etc....
is it correct to check it simply as s > 30 ?!
it's just a newbe question... I'll give it a try as soon as I can :P

Re: Dead zwave devices

Posted: Wednesday 28 September 2016 9:31
by Docc
Yes it works, I've copied that function from the wiki :-)

Re: Dead zwave devices

Posted: Wednesday 28 September 2016 9:42
by emme
thanks