Best way to return zigbee.writeAttribute with mfgCode on parse()

I am trying to figure out the best way to return a zigbee writeAttribute command that includes a specific manufacturer code when a certain message is parsed.

One way I know of is to use wattr, like this:

def cmd = "he wattr 0x${device.deviceNetworkId} 0x01 0x0000 0xFF0D 0x20 {${attrValue}}"
// some more code
return cmd

But I have no idea where to add the manufacturer code.

Another method on Hubitat, as I understand it could be to skip returning the command on parse() and instead use sendHubCommand, like this:

sendHubCommand(new hubitat.device.HubAction("zigbee.writeAttribute(0x0000, 0xFF0D, 0x20, ${attrValue}, [mfgCode: 0x115F])"))

Neither of these seem to work, wattr probably because it's missing the manufacturer code (0x115F), and for sendHubCommand, I have no idea why.

Any ideas?

@mike.maxwell?

zigbee.writeAttribute(0xFC02, 0x0000, 0x20, 0x14, [mfgCode: "0x1241"]) 

We'll get to documenting these shortly, left to right
Cluster, attribute, data type, value
You shouldn't need to use send hub command, but it depends on the context.

Thanks @mike.maxwell

Seeing that the formatting of the passed parameters is different than with SmartThings (double-quotes around the value of mfgCode vs. no double-quotes) gives me the feeling that I shouldn't make any assumptions about the context that would require using sendHubCommand.

Here's an abridged oversimplified version of what I'm trying to do in a device driver:

def parse(String description) {
	Map descMap = zigbee.parseDescriptionAsMap(description)
	if (descMap?.clusterInt == 0x0000 & descMap.attrInt == 0x0005) {
		def newLevel = changeSensitivityLevel()
		zigbee.writeAttribute(0x0000, 0xFF0D, 0x20, newLevel, [mfgCode: "0x115F"])
	}
}

Basically, the write attribute command needs to happen right after a button is pushed which sends a message on cluster 0x0000 attribute 0x0005. Is this the right method in this context?

I don't get any error on zigbee.writeAttribute, but there's no response from the device. Unfortunately I'm not certain if it is even supposed to send a response, and because it's an Aqara sensor, it doesn't respond to zigbee.readAttribute(0x0000, 0xFF0D, [mfgCode: "0x115F"]) which would normally be the way to make sure the write attribute command worked.

Another thing I should ask about is the length of the hex value for the payload. On SmartThings, apparently there's a rule that:

The length of the payload must be two times the length of the data type. For example, if the datatype is 16-bit, then the payload should be 4 hex digits.

Does this rule also apply to zigbee.writeAttribute on Hubitat?

mfgCode just needs to be a string, doesn't matter if its double quotes or single.
what I do for commands I want to run from parse is the following, then you don't need sendHubCommand.
parse has a built in response wrapper, and if the last return is a command, it will execute it.

so this is the form i use
def cmds = [] //at the top of parse

then where ever I wish to fire a command
cmds.add(zigbee.whatever), if there's more than one you can do cmds.addAll()

then the very last line in parse
return cmds, or the like

So directly calling zigbee.writeAttribute in parse() is incorrect?

Based on what you've explained, I'm trying this:

def parse(String description) {
	def cmds = []
	Map descMap = zigbee.parseDescriptionAsMap(description)
	if (descMap?.clusterInt == 0x0000 & descMap.attrInt == 0x0005)
		cmds = changeSensitivity()
	return cmds
}

def changeSensitivity() {
	def cmds = []
	state.sensitivity = (state.sensitivity < 3) ? state.sensitivity + 1 : 1
	def attrValue = [0x00, 0x15, 0x0B, 0x01]
	cmds.add(zigbee.writeAttribute(0x0000, 0xFF0D, 0x20, attrValue[state.sensitivity], [mfgCode: "0x115F"]))
	cmds.add(zigbee.readAttribute(0x0000, 0xFF0D, [mfgCode: "0x115F"]))
	return cmds
}

This also results in no errors, but of course since there's no response to the read attribute command, I don't know if the write attribute worked.

I guess I need to invest in one of those "cheap" ZigBee sniffers!

Thanks for your help!

Start simple, add a test method, see if you can read the attribute first.

2 Likes

This is a must have for anyone doing driver development.

2 Likes