Securifi Flood Sensor Device Type


#1

I recently came to ST from Almond+. As a result I had some Securifi device types lying around. I saw the conversation on some of thier devices. I did not see the flood sensor (Securifi SZ-WTD01). Thanks and credit to Serge Sozonoff who wrote the device type for Securifi motion sensors. I modified relatively little, but it works great!

Enough blabbing. Here is the code:

>    //Credit to Serge Sozonoff whom I based this code on.
metadata {
	definition (name: "Securifi Moisture Sensor", namespace: "tchoward", author: "tchoward") {
		capability "Water Sensor"
		capability "Sensor"
        capability "Configuration"

        attribute "tamperSwitch","ENUM",["open","closed"]

        command "enrollResponse"

		fingerprint endpointId: '08', profileId: '0104', inClusters: "0000,0003,0500", outClusters: "0003"
	}

	// simulator metadata
	simulator {
		status "active": "zone report :: type: 19 value: 0031"
		status "inactive": "zone report :: type: 19 value: 0030"
	}

	// UI tile definitions
	tiles {
    	tiles(scale: 2) {
			multiAttributeTile(name:"moisture", type: "generic", width: 6, height: 4){
				tileAttribute ("device.moisture", key: "PRIMARY_CONTROL") {
					attributeState "dry", label: "Dry", icon:"st.alarm.water.dry", backgroundColor:"#ffffff"
					attributeState "flood", label: "Wet", icon:"st.alarm.water.wet", backgroundColor:"#53a7c0"
				}
			}
        }

        standardTile("tamperSwitch", "device.tamperSwitch", width: 2, height: 2) {
			state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
			state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
		}        
		main (["moisture"])
		details(["moisture","tamperSwitch"])
	}
}
> >
def configure() {
	log.debug("** PIR02 ** configure called for device with network ID ${device.deviceNetworkId}")
> >
	String zigbeeId = swapEndianHex(device.hub.zigbeeId)
	log.debug "Configuring Reporting, IAS CIE, and Bindings."
	def configCmds = [
    	"zcl global write 0x500 0x10 0xf0 {${zigbeeId}}", "delay 200",
		"send 0x${device.deviceNetworkId} 1 1", "delay 1500",

        "zcl global send-me-a-report 1 0x20 0x20 0x3600 0x3600 {01}", "delay 200",
        "send 0x${device.deviceNetworkId} 1 1", "delay 1500",

		"zdo bind 0x${device.deviceNetworkId} 1 1 0x001 {${device.zigbeeId}} {}", "delay 1500",

        "raw 0x500 {01 23 00 00 00}", "delay 200",
        "send 0x${device.deviceNetworkId} 1 1", "delay 1500",
	]
    return configCmds // send refresh cmds as part of config
}
def enrollResponse() {
	log.debug "Sending enroll response"
    [	

	"raw 0x500 {01 23 00 00 00}", "delay 200",
    "send 0x${device.deviceNetworkId} 1 1"

    ]
}

// Parse incoming device messages to generate events
def parse(String description) {
	log.debug("** PIR02 parse received ** ${description}")
    def result = []        
	Map map = [:]

    if (description?.startsWith('zone status')) {
	    map = parseIasMessage(description)
    }

	log.debug "Parse returned $map"
    map.each { k, v ->
    	log.debug("sending event ${v}")
        sendEvent(v)
    }

//	def result = map ? createEvent(map) : null

    if (description?.startsWith('enroll request')) {
    	List cmds = enrollResponse()
        log.debug "enroll response: ${cmds}"
        result = cmds?.collect { new physicalgraph.device.HubAction(it) }
    }
    return result
}

private Map parseIasMessage(String description) {
    List parsedMsg = description.split(' ')
    String msgCode = parsedMsg[2]

    Map resultMap = [:]
    switch(msgCode) {
        case '0x0038': // Dry
            log.debug 'Detected Dry'
            resultMap["moisture"] = [name: "moisture", value: "dry"]
            resultMap["tamperSwitch"] = getContactResult("closed")            
            break

        case '0x0039': // Wet
            log.debug 'Detected Moisture'
            resultMap["moisture"] = [name: "moisture", value: "flood"]
            resultMap["tamperSwitch"] = getContactResult("closed")            
            break

        case '0x0032': // Tamper Alarm
        	log.debug 'Detected Tamper'
            resultMap["moisture"] = [name: "moisture", value: "active"]
            resultMap["tamperSwitch"] = getContactResult("open")            
            break

        case '0x0034': // Supervision Report
        	log.debug 'No flood with tamper alarm'
            resultMap["moisture"] = [name: "moisture", value: "inactive"]
            resultMap["tamperSwitch"] = getContactResult("open")            
            break

        case '0x0035': // Restore Report
        	log.debug 'Moisture with tamper alarm'
            resultMap["moisture"] = [name: "moisture", value: "active"]
            resultMap["tamperSwitch"] = getContactResult("open") 
            break

        case '0x0036': // Trouble/Failure
        	log.debug 'msgCode 36 not handled yet'
            break
    }
    return resultMap
}

private Map getContactResult(value) {
	log.debug "Tamper Switch Status ${value}"
	def linkText = getLinkText(device)
	def descriptionText = "${linkText} was ${value == 'open' ? 'opened' : 'closed'}"
	return [
		name: 'tamperSwitch',
		value: value,
		descriptionText: descriptionText
	]
}


private hex(value) {
	new BigInteger(Math.round(value).toString()).toString(16)
}

private String swapEndianHex(String hex) {
    reverseArray(hex.decodeHex()).encodeHex()
}

private byte[] reverseArray(byte[] array) {
    int i = 0;
    int j = array.length - 1;
    byte tmp;
    while (j > i) {
        tmp = array[j];
        array[j] = array[i];
        array[i] = tmp;
        j--;
        i++;
    }
    return array
}

(Chris Morrissey) #2

I get this reply when I try and enter the code. Not sure what I may be doing wrong. Thanks! Org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: script1447186256423646477655.groovy: 39: unexpected token: > @ line 39, column 1. > > ^ 1 error


(sidjohn1) #3

i don’t think the “> >” are valid lines of code.


(Chris Morrissey) #4

That was it. Thanks!!


(James) #5

Do these plug into the wall or do they run on batteries?


(Andreas Welch) #6

2 CR2032 batteries, no power plug option.


(James) #7

Thanks! it was vey unclear from the Amazon listing.


(Andrew Seward) #8

I got the device type installed and connected. But does not seem to actually sense changes.


(Nathan Revo) #9

If anyone is interested, I was able to get this to work by changing the Dry and Wet values in the case statement to 30 & 31 as demonstrated below. Once I made this change the app would show wet/dry changes.

case '0x0030': // Dry
        log.debug 'Detected Dry'
        resultMap["moisture"] = [name: "moisture", value: "dry"]
        resultMap["tamperSwitch"] = getContactResult("closed")            
        break

case '0x0031': // Wet
        log.debug 'Detected Moisture'
        resultMap["moisture"] = [name: "moisture", value: "flood"]
        resultMap["tamperSwitch"] = getContactResult("closed")            
        break

quoting the original values:


#10

For those of you coming back later :slight_smile:
The codes my sensor required to work were 20 and 21. I tried to see in the logs if we get other codes as well but there seemed to be only 2 statuses provided. I guess this sensor is pretty basic broken connection which gets connected by water for a status change.


(Frederixx) #11

Device is detected but with an unknown name and status stays at Please wait. Any idea?

Thanks


(Frederixx) #12

I edited the device and changed the type to water sensor. Now it’s status is at dry. I can’t get it to detect water though.

I tried the changing the code for case ‘0x0030’ and 31, but no go.

Any ideas?


(sam) #13

for the Securifi SZ-WTD01 I couldn’t get the custom DH to work from this post but just changed it to the “Z-Wave Water Sensor” already in the default list and it works great, give that a try for the SZ-WTD02N and see if that works…


(Frederixx) #14

Tried it with no luck.

Unless it’s broken, it stays at dry all the time (with code posted or other water sensors) and status in my devices is at inactive.

Thanks


(sam) #15

I misspoke, I used the smartsense moisture sensor DH and it worked, I just tried to add a SZ-WTD02N and also got no joy using any of the default water sensors nor the one for the SZ-WTD01, I did get it to pair just couldn’t find anything to handle it…I’ll be sending it back…


(Frederixx) #16

My ST hub detects it as a thing, but whatever configuration i use, it stays at “dry” and can’t get it to detect water. Guess i tried everything i could, i’ll just return it as well.


SZ-WTD02N Securifi water leak sensor
(Wes Gurney) #17

Support for Securifi SZ-WTD02N models here:

It also works with the Smart Home Monitor section of the Smarthings App for water leaks.