SwiidInter Cord Switch Custom Device Type


(Chris Petzny) #1

So I finally got one of the SwiidInter cord switches ( http://www.vesternet.com/z-wave-swiidinter-cord-switch ) and it kind of works in ST as a generic “Z-Wave Switch”. However, it does not report its current status by default. So if you switch it on using ST, then switch it off manually, ST still thinks it’s on. In order for the switch to report its status, it has to be set to Association Group 2. And in order to do that, I believe I need a custom device type.

I’m not much of a coder, so I would love it if someone here could have a go at writing a custom device type. I’d even be happy to sponsor the effort by supplying a switch to anyone willing to take it on.

There is some basic information on the manufacturer website.
The user manual: http://www.swiid.com/medias/documents/ZCS-User-s-manual-vBAT2-02.12.2014.pdf
Advanced settings: http://www.swiid.com/medias/documents/advanced-swiidinter.pdf

I have a bunch of table lamps that I would love to use these with, so it would really make my day if someone could help with this.

I’ve put this request in this group, since the switch seems to be UK/Europe only.

Cheers,
Chris.


(Robin) #2

I had the same problem with the Swiid cord switch, you need to associate with group 2.

Try the following custom device handler which is my first ever attempt at Groovy, press the configure button when connected and status updates should come through without the Lutron patented tech.

I still want to figure out responding to the long press trigger but haven’t managed that yet… thinking along the lines of rule machine custom command but I’m stuck on getting long press through a switch instead of a button.

metadata {
	definition (name: "swiidinter Cord Switch with Association", namespace: "smartthings", author: "SmartThings") {
		capability "Actuator"
		capability "Switch"
		capability "Polling"
		capability "Refresh"
		capability "Sensor"
        capability "Configuration"

command "configure"
		fingerprint inClusters: "0x25"
	}

	// simulator metadata
	simulator {
		status "on":  "command: 2003, payload: FF"
		status "off": "command: 2003, payload: 00"

		// reply messages
		reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
		reply "200100,delay 100,2502": "command: 2503, payload: 00"
	}

	// tile definitions
	tiles(scale: 2) {
		multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
			tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
				attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
				attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
			}
		}
		standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
			state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
		}
standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "configure", label:'', action:"configure", icon:"st.secondary.configure"
}
		main "switch"
		details(["switch","refresh","configure"])
	}
}

def parse(String description) {
	def result = null
	def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
	if (cmd) {
		result = createEvent(zwaveEvent(cmd))
	}
	if (result?.name == 'hail' && hubFirmwareLessThan("000.011.00602")) {
		result = [result, response(zwave.basicV1.basicGet())]
		log.debug "Was hailed: requesting state update"
	} else {
		log.debug "Parse returned ${result?.descriptionText}"
	}
	return result
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
	[name: "switch", value: cmd.value ? "on" : "off", type: "physical"]
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
	[name: "switch", value: cmd.value ? "on" : "off", type: "physical"]
}

def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
	[name: "switch", value: cmd.value ? "on" : "off", type: "digital"]
}

def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
	def value = "when off"
	if (cmd.configurationValue[0] == 1) {value = "when on"}
	if (cmd.configurationValue[0] == 2) {value = "never"}
	[name: "indicatorStatus", value: value, display: false]
}

def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
	[name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false]
}

def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
	if (state.manufacturer != cmd.manufacturerName) {
		updateDataValue("manufacturer", cmd.manufacturerName)
	}
}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
	// Handles all Z-Wave commands we aren't interested in
	[:]
}

def on() {
	delayBetween([
		zwave.basicV1.basicSet(value: 0xFF).format(),
		zwave.switchBinaryV1.switchBinaryGet().format()
	])
}

def off() {
	delayBetween([
		zwave.basicV1.basicSet(value: 0x00).format(),
		zwave.switchBinaryV1.switchBinaryGet().format()
	])
}

def poll() {
	delayBetween([
		zwave.switchBinaryV1.switchBinaryGet().format(),
		zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
	])
}

def refresh() {
	delayBetween([
		zwave.switchBinaryV1.switchBinaryGet().format(),
		zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
	])
}


def invertSwitch(invert=true) {
	if (invert) {
		zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()
	}
	else {
		zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()
	}
}

def configure() {
        delayBetween([
              

                // Can use the zwaveHubNodeId variable to add the hub to the
                // device's associations:
                zwave.associationV2.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format(), 
        ])
}

#3

If you post your code and questions in the following forum section someone will probably be able to help. :sunglasses:

https://community.smartthings.com/c/developers/writing-device-types