HubAction/Protocol.DELAY

Curious what the correct syntax is for sending a HubAction using Protocol.DELAY. Building a HubMultiAction object and attempting to insert a delay between commands. I tried inserting the delay in the Zigbee command string the way I was used to elsewhere (ie: "he cmd .... {}, delay 1500"), but the hub seems to be ignoring the delay. Wireshark shows the commands coming in milliseconds apart regardless of what I use for a delay value. The physical device seems to be having an issue acting on the commands when sent so close together (it did receive them though. sending another command seems to cause it to act on the one that's maybe stuck in a buffer(?)).

Are you specifying one delay to use between each of them by delayBetween?

No. Initially I was using the syntax used in Hubitat's own example drivers:

"he cmd 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0300 0x06 {${hexHue} ${hexSat} 0x0100}", "delay 200",
"he cmd 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0006 1 {}","delay 200",
"he rattr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0006 0 {}","delay 200",
"he rattr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0300 0x0000 {}", "delay 200",
"he rattr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0300 0x0001 {}", "delay 200",
"he rattr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0300 0x0008 {}"

I ran into issues sending commands in this format when the parent methods were called from the child driver, so I wrapped them in HubAction/HubMultiAction and sent via sendHubCommand() which did the trick. I'll have to try delayBetween() and see if that works for adding delays.

This should help...
Too lazy to edit, but you'll get the point...

 List<String> cmds = []

Integer minReportTime = (levelReportInterval ? levelReportInterval.toInteger() : levelReportIntervalDefault)
Integer maxReportTime = (minReportTime == 0) ? 0xFFFF : 0xFFFE

if (getDataValue("isMultiEP") == "false") {
    cmds.addAll(
            "zdo bind 0x${device.deviceNetworkId} 0x${device.endpointId} 0x01 0x0006 {${device.zigbeeId}} {}",
            "zdo bind 0x${device.deviceNetworkId} 0x${device.endpointId} 0x01 0x0008 {${device.zigbeeId}} {}",
            "he cr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0006 0x0000 0x10 0 0xFFFE {}",
            "he cr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0008 0x0000 0x20 ${minReportTime} ${maxReportTime} {01}"
    )

} else {
    String ep = ""
    childDevices.each {
        ep = it.deviceNetworkId.split("-")[1]
        cmds.addAll(
                "zdo bind 0x${device.deviceNetworkId} 0x${ep} 0x01 0x0006 {${device.zigbeeId}} {}",
                "zdo bind 0x${device.deviceNetworkId} 0x${ep} 0x01 0x0008 {${device.zigbeeId}} {}",
                "he cr 0x${device.deviceNetworkId} 0x${ep} 0x0006 0x0000 0x10 0 0xFFFE {}",
                "he cr 0x${device.deviceNetworkId} 0x${ep} 0x0008 0x0000 0x20 ${minReportTime} ${maxReportTime} {01}"
        )
    }
}
sendHubCommand(new HubMultiAction(delayBetween(cmds,200), Protocol.ZIGBEE))
1 Like

Thanks. I think I figured out my issue: ["he cmd...{}, delay 200"] vs ["he cmd...{}","delay 200"] :man_facepalming:

Still, curious about the HubAction syntax. The documentation says that one of the Protocol options is DELAY. If I was going to add a single delay HubAction would it look like:
new HubAction('delay 1000', Protocol.DELAY) ?

The delays in your example get wrapped in a HubMultiAction with Protocol.ZIGBEE. Is there any functional difference? Is there any reason I would want to do this (and is it even correct?):

myHubMultiAction.add(new HubAction('delay 1000', Protocol.DELAY))

Just looking to figure out what's more Technically Correct.

yeah, that's what it looks like, I don't know why anyone would go through the trouble of calling it that way when there's much cleaner ways of delaying between commands.
I would never use that call anyway.

I'm not sure the distinction matters.

multiple zwave and zigbee commands are all built the same way and end up looking like this:
["command","delay in ms","command"]
These can be returned directly using return or via HubMultiAction if needed

I always build them now starting with

List<String> cmds = []

It just doesn't make any sense to me to add a delay using the Protocol.DELAY option since it's only applicable to HubActions...

1 Like

Thanks. Good to know.