Hubitat might have a "friendly" way to do this, but using a "raw" Zigbee command will probably work. Maybe something like:
String toggle() {
if (enableDebug) log.debug "toggle()"
return "he cmd 0x${device.deviceNetworkId} 0x${device.endpointId} 0x006 0x02 {}"
}
(You could do def toggle()
too, and that's probably what you'll see it lots of code...I'm just into specific typing.
) I don't do much with Zigbee driver development, however, so someone might have to correct my command format if that's wrong...seems right based on what you provided, though.
Don't forget to add command "toggle"
to your definition
too if you want to use this as a device command (it's not part of any standard Hubitat capability, and I'm not sure there's much of an advantage to doing this over just sending an on()
or off()
based on the device's current state, assuming that gets accurately reported back, but it should work if that is right).
For adding a flash()
command, it sounds like you may have some idea of where to start. You could look at my Inovelli LZW30-SN (Red Series switch) driver to see how I did it: https://github.com/RMoRobert/Hubitat/blob/master/drivers/Inovelli/Red-Switch-LZW30SN-Advanced.groovy. One thing I'd change now is replace command "flash"
with capability "Flash"
in the definition
(this has been standardized into a capability now; it was not when I wrote that). The key parts to look at are the flash()
method that implements this required command, the flashOn()
and flashOff()
methods that help make this behavior happen (in conjunction with the preference for flash rate), and--just because it seems to be convention--the fact that calling an on()
or off()
will also stop the flash, the current state of which is tracked in state.flashing
(so running one of these commands sets that to false
, whereas running flash()
sets it to true
, besides starting the repeating on/off commands).
Of course, that's a Z-Wave driver, so the biggest difference is that you'll return Zigbee commands instead. You should be able to use whatever you're doing in on()
and off()
, like something like "he cmd 0x${device.deviceNetworkId} 0x${device.endpointId} 0x006 0x01 {}"
for on()
. (You might also need to do a rattr
with a slight delay after the cmd
to get the state back; the driver you're starting with might already be doing this, at least for on/off commands. You may or may not care to do it in between phases of a flash.)
EDIT: I suppose I should mention that the above, of course, is simulating the flash and not relying on the Zigbee identify cluster. That may work for some devices, and if you know the right Zigbee command to send (and the outlet responds), that could certainly be used instead. I just don't know what that would be, or know enough about Zigbee to give you a good guess.