I have a working device handler for a multi-button scene controller. Basically, it has 5 boolean states for whether the buttons/lights on the device are off/on. I'm trying to convert this into a composite device, with 5 child devices that are very similar to virtual switches. That will vastly simplify building Rule Machine or other integrations, because I can just attach automations to the individual child switches.
Here's how far I've gotten:
- I've created a driver for the child devices that behaves just like a virtual switch
- I have a configure command on the parent device that will create the 5 child devices
- I can successfully send state from parent to child. For example, if I press a button on the physical device, a z-wave message comes to the parent, it gets parsed, and the parent calls on() or off() on the correct child. I can then see the virtual switches get updated to match what the lights on the physical device look like.
Here's my problem: I'm trying to do a two-way binding. If another automation turns one of the virtual switches on or off, I want that child device to tell the parent to send a z-wave message out to the physical device, so that it can update its indicators.
I have code in the parent that can do this, but it isn't working if triggered by the child. So, on the parent, I have a method like:
def IndicatorSet(index, onOrOff)
It does a little logic and then ends up calling:
delayBetween([
zwave.indicatorV1.indicatorSet(value: onOrOff).format(),
zwave.indicatorV1.indicatorGet().format(),
],300)
This works just fine if you call it from the device page of the parent.
However, in the child device, I have code like this (to try to send events back to the parent, so they can be sent to the physical device):
def on() {
log.debug "${device.displayName} on"
sendEvent(name: "switch", value: "on", isStateChange: true)def parent = getParent()
if (parent) {
def childsIndex = device.deviceNetworkId[device.deviceNetworkId.size() - 1] as Integer
parent.IndicatorSet(childsIndex, 1)
}
}
If I watch my logs, I can see that parent.IndicatorSet gets called, gets executed, and gets to the point of the delayBetween command. But then nothing happens. No z-wave messages get sent to the physical device.
Is it possible for a child to make a parent send out z-wave commands? When a child calls a method on a parent, is that executed in the "device context" of the parent or the child? Thanks for any help!