Example of parent-child / component driver

Is there an example of a parent-child / component driver out there? Especially a zwave one, but would take whatever?

I've never made one of those, but have been thinking for a while that it may make sense to do this for the GE motion switch/dimmer devices as it is really 2 different things a switch/dimmer and a motion sensor.

As such I thought I would try to learn something new using a device I already know intimately well.

EDIT: Looks like there is something on the hubitat git. I'll start there...

I have some on my github

1 Like

Thanks I'll look there too.

I'm not even 100% sure this needs to be done at all for this device. But it seems like a good idea so I thought I would at least try it and see what it looks like.

1 Like

Sounds like you have a fun project on your hands

Any in particular? None of them are jumping out at me as a parent/child driver?

EDIT: RGBGenie.

1 Like

That was a fun one

1 Like

Yeah... I might need to find a simpler one to look at 1st. lol

1 Like

Thanks @mike.maxwell I just found that a bit ago.

Big help - poking away at it right now.

1 Like

OK, clearly I'm missing something simple. Any thoughts on what painfully obvious thing I am missing @mike.maxwell ?

If I do this off() function below from a command button in the parent driver it works fine.

However, when I do the off from the child dimmer device, I see the event making to to the componentOff(cd) function in the parent, and then to the off() function in the parent, but then nothing happens on the zwave device. Nada - no message, nothing in the log, nothing.

Do I need to move the zwave pieces into the child? I was just going to leave all the zwave stuff in the parent, but maybe that doesn't work that way. :slight_smile:

void componentOff(cd){
    if (logEnable) log.info "received off request from ${cd.displayName}"
    getChildDevice(cd.deviceNetworkId).parse([[name:"switch", value:"off", descriptionText:"${cd.displayName} was turned off"]])
    def test = off()
}

def off() {
	if (logEnable) log.debug "Turn device OFF"
	def cmds = []

    cmds << zwave.basicV1.basicSet(value: 0x00).format()
   	cmds << zwave.switchMultilevelV2.switchMultilevelGet().format()
    return delayBetween(cmds, 3000)
}

You need to return the zwave commands using

sendHubCommand(new hubitat.device.HubMultiAction(delayBetween(cmds, 3000), hubitat.device.Protocol.ZWAVE))
2 Likes

Holy mackerel. I would have never figured that one out.

:flushed:

Thanks!