LUA: Fibaro smoke sensor tamper

Moderator: Telldus

Post Reply
dico
Posts: 40
Joined: Thu Jan 18, 2018 11:08 am

LUA: Fibaro smoke sensor tamper

Post by dico » Thu Jan 18, 2018 11:08 am

I want to check if someone "tampers" with a smokedetector (Fibaro FGSD-002).
I'm new to LUA, but after some testing I kinda got it working. But I'm not sure how to interpret the data and documentation.

So far I have found two values changing while triggering the tamper. I'm guessing the cmd is equal to the association?

My current script:

Code: Select all

-- File: SmokeSenor.lua
-- Define the names on your devices here:
local smokesensor = "SmokeSensorTest"


local deviceManager = require "telldus.DeviceManager"

function onZwaveMessageReceived(device, flags, cmdClass, cmd, data)
	if device:name() ~= smokesensor then
		return
	end

	if cmd == 5 then
	-- if cmdClass == 113 then

		local tamper1 = data[5]
		local tamper2 = data[6]

		print("Device: %s. Flags: %s. cmdClass: %s. cmd: %s. Data: %s", device, flags, cmdClass, cmd, data)

		if tamper1 == 0 then
			print("Smokedetector (tamper1) closed")
		elseif tamper1 == 3 then
			print("Smokedetector (tamper1) open")
		end

		if tamper2 == 1 then
			print("Smokedetector (tamper2) closed")
		elseif tamper2 == 0 then
			print("Smokedetector (tamper2) open")
		end
	end
end
Console output this:
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 256. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 3, 0]

Smokedetector (tamper1) open
Smokedetector (tamper2) open

Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 3, 0]

Smokedetector (tamper1) open
Smokedetector (tamper2) open

Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 256. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 0, 1, 3]

Smokedetector (tamper1) closed
Smokedetector (tamper2) closed

Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 0, 1, 3]

Smokedetector (tamper1) closed
Smokedetector (tamper2) closed
Can anyone help me interpret the values to any documentation? Any idea why it sends two commands for each?

Her is the full output, without checking for cmd 5:
OPEN
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 256. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 3, 0]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 86. cmd: 1. Data: [113, 5, 0, 0, 0, 255, 7, 3, 0, 52, 115]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 3, 0]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 8. cmdClass: 156. cmd: 2. Data: [11, 0, 255, 0, 0]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 156. cmd: 2. Data: [11, 0, 255, 0, 0]

CLOSE
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 256. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 0, 1, 3]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 86. cmd: 1. Data: [113, 5, 0, 0, 0, 255, 7, 0, 1, 3, 95, 213]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 0, 1, 3]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 8. cmdClass: 156. cmd: 2. Data: [11, 0, 0, 0, 0]
Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 156. cmd: 2. Data: [11, 0, 0, 0, 0]
Last edited by dico on Sat Jan 21, 2017 12:09 pm, edited 1 time in total.

micke.prag
Site Admin
Posts: 2242
Joined: Thu Jan 18, 2018 11:08 am
Location: Lund
Contact:

Re: LUA: Fibaro smoke sensor tamper

Post by micke.prag » Thu Jan 18, 2018 11:08 am

Code: Select all

	if cmd == 5 then
	-- if cmdClass == 113 then
Only checking the command is not recommended. More than the "alarm" command class may use command=5 and your code will produce a lot of false positives.

Code: Select all

local tamper1 = data[5]
local tamper2 = data[6]
Not checking the length first might lead to errors. You cannot be sure the Z-Wave message is intact. Sometimes a garbled message might arrive.
Can anyone help me interpret the values to any documentation?
Unfortunately we cannot disclose any documentation since this is under NDA from Sigma Designs. We can only help you pointing you in the right direction.

data[5] is the notification type
data[6] is the status.

Notification type 7 is "Home Security"
Status for notification type 7:
0: Event inactive
3: Tampering, Product covering removed

I hope this information helps you further.
Micke Prag
Software
Telldus Technologies

dico
Posts: 40
Joined: Thu Jan 18, 2018 11:08 am

Re: LUA: Fibaro smoke sensor tamper

Post by dico » Thu Jan 18, 2018 11:08 am

Shouldn't the data types be one position lower? Like:
data[4] is the notification type
data[5] is the status.

Splitting up the data:
Tampering data
data_0 = data[0] -- is 0
data_1 = data[1] -- is 0
data_2 = data[2] -- is 0
data_3 = data[3] -- is 255
data_4 = data[4] -- is 7 <--
data_5 = data[5] -- is 3 <--
data_6 = data[6] -- is 0


Event inactive data
data_0 = data[0] -- is 0
data_1 = data[1] -- is 0
data_2 = data[2] -- is 0
data_3 = data[3] -- is 255
data_4 = data[4] -- is 7 <--
data_5 = data[5] -- is 0 <--
data_6 = data[6] -- is 1
data_7 = data[7] -- is 3
My current code:

Code: Select all

-- File: SmokeSensor.lua
-- Define the names on your devices here:
local smokesensor = "SmokeSensorTest"

local deviceManager = require "telldus.DeviceManager"

function onZwaveMessageReceived(device, flags, cmdClass, cmd, data)
	if device:name() ~= smokesensor then
		return
	end

	if (cmd == 5 and cmdClass == 113) then

		if list.len(data) < 6 then
			return
		end

		local notification_type = data[4]
		local status = data[5]

		print("Device: %s. Flags: %s. cmdClass: %s. cmd: %s. Data: %s", device, flags, cmdClass, cmd, data)
		print("Notification type: %s. Status: %s", notification_type, status)

		if (notification_type == 7) then
			if (status == 0) then
				print("Event inactive")
			elseif (status == 3) then
				print("Tampering, Product covering removed")
			end
		end
	end
end
Output:
Script SmokeSensor.lua loaded

Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 256. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 3, 0]
Notification type: 7. Status: 3
Tampering, Product covering removed

Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 3, 0]
Notification type: 7. Status: 3
Tampering, Product covering removed

Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 256. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 0, 1, 3]
Notification type: 7. Status: 0
Event inactive

Device: <zwave.telldus.DeviceNode.DeviceNode object at 0x1107480>. Flags: 0. cmdClass: 113. cmd: 5. Data: [0, 0, 0, 255, 7, 0, 1, 3]
Notification type: 7. Status: 0
Event inactive

micke.prag
Site Admin
Posts: 2242
Joined: Thu Jan 18, 2018 11:08 am
Location: Lund
Contact:

Re: LUA: Fibaro smoke sensor tamper

Post by micke.prag » Thu Jan 18, 2018 11:08 am

dico wrote:Shouldn't the data types be one position lower? Like:
data[4] is the notification type
data[5] is the status.
That might be correct. I didn't run the code just read your example.
Micke Prag
Software
Telldus Technologies

dico
Posts: 40
Joined: Thu Jan 18, 2018 11:08 am

Re: LUA: Fibaro smoke sensor tamper

Post by dico » Thu Jan 18, 2018 11:08 am

Thanks for the help.

Now I'm only missing a solution to notify me when a smoke-sensor has been tampered with. Any suggestions? The only way I can see right now is to turn on/off a dummy device and create an event to that dummy device? But this will require me to have one dummy-device and one event for each smoke-sensor.

erikjoens
Posts: 14
Joined: Thu Jan 18, 2018 11:08 am

Re: LUA: Fibaro smoke sensor tamper

Post by erikjoens » Thu Jan 18, 2018 11:08 am

@dico I think turning a device on/off is the only solution right now. If telldus adds support for http request or something similar we could work with that instead. However you could send a "message" to the device you turn on that way you can look in the device history to see which device was tampered, eg:

Code: Select all

tamperWarningDevice:command("turnon", nil, "your message here, eg device:name()")
This way when the event is triggered you could just check the device history to see what triggered it.

Post Reply