Parent/Child device not actioning on/off

What is the actual DNI of your child devices? Is it possible that you have another "e" before e1 suffix?

Edit: in fact now that I think about it, using a single character like "e" to create the suffix is begging for issues because a lot of parent devices would have an e in their dni's.

1 Like

You may be right here, I've seen "ep" used in others, yet this one (for ST) just used "e".

I think I'll try all again, using "ep" and update all in the examples I've seen.
This is how they are currently.

Looking at your dni's... using ep shouldn't matter.
Hmmm...I'll have really look at the code. Skimming on my phone isn't working.

1 Like

Yeah you're right, no change with "ep".

In the other examples, the only thing I see, is that the drivers are all inclusive. No Parent and no Child, just one driver.

That and adding the Channel before (node) (Or (dni)).

**Mine**
def switchOn(Integer node) {
	log.debug "<FONT COLOR=RED>Turning on Powerstrip - ${device.deviceNetworkId} node ${node}, On$node</FONT>"
	def cmds = []
	cmds << new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), (node))), hubitat.device.Protocol.ZWAVE)
	cmds << new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), (node))), hubitat.device.Protocol.ZWAVE)
	cmds
}

**Other Example**
def childOff(String dni) {
	log.debug "childOff($dni)"
	def cmds = []
	cmds << new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0x00), channelNumber(dni))), hubitat.device.Protocol.ZWAVE)
	cmds << new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), channelNumber(dni))), hubitat.device.Protocol.ZWAVE)
	cmds
}

This example has channelNumber(dni), rather than just (node).
Its the only thing I can see, difference wise.

node and channelNumber() all seem to just be variables that contain a numeric value. I am thinking that when the parameter is being passed from the child to parent, it's being converted to something other than an Integer. You may need to manually reconvert to an Integer in the parent code. Headed home soon so I'll have a suggestion or 2 when I can review from my desktop.

1 Like

When you turn on the switches from the parent device....are you using the on1 or off1 buttons?
If not, try them and let me kn ow if they work.

Also, your swtchOn should probably be like below. Wrapping the node variable in brackets will likely cause issues.

def switchOn(Integer node) {

	def cmds = []
	cmds << new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), node)), hubitat.device.Protocol.ZWAVE)
	cmds << new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), node)), hubitat.device.Protocol.ZWAVE)
	cmds
}
1 Like

I am yes, all 5 work fine.

The code originally was this:

def switchOn(node) {
  log.debug "<FONT COLOR=RED>Turning on Powerstrip - ${device.deviceNetworkId} node ${node}, On$node</FONT>"
	def cmds = []
	cmds << new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), node)))
	cmds << new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), node)))
	sendHubCommand(cmds)
}

Which is close to being correct, we do not support sending a List of HubActions from sendHubCommand, you must use HubMultiAction if you want to send a list of actions and you must send a hub command from a parent device. In the code you posted above you are returning the commands to the child device and the child device is returning them to system.

your parent device:

def switchOn(Integer node) {
	log.debug "<FONT COLOR=RED>Turning on Powerstrip - ${device.deviceNetworkId} node ${node}, ${device.deviceNetworkId-ep}</FONT>"
	def cmds = []
	cmds << new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), node)), hubitat.device.Protocol.ZWAVE)
	cmds << new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), node)), hubitat.device.Protocol.ZWAVE)
	cmds
}

which is the same as this (with the explicit return):

def switchOn(Integer node) {
	log.debug "<FONT COLOR=RED>Turning on Powerstrip - ${device.deviceNetworkId} node ${node}, ${device.deviceNetworkId-ep}</FONT>"
	def cmds = []
	cmds << new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), node)), hubitat.device.Protocol.ZWAVE)
	cmds << new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), node)), hubitat.device.Protocol.ZWAVE)
	return cmds
}

Then in your child device you have this:

def on() {
	log.debug "Switching on $device.label, $device.deviceNetworkId"
	parent.switchOn(splitChannel(device.deviceNetworkId))
}

which is the same as this:

def on() {
	log.debug "Switching on $device.label, $device.deviceNetworkId"
	return parent.switchOn(splitChannel(device.deviceNetworkId))
}

So in order to fix this, there are a bunch of different ways (Note that the "def" was changed to "void" since your method is not returning anything)

this:

void switchOn(Integer node) {
	log.debug "<FONT COLOR=RED>Turning on Powerstrip - ${device.deviceNetworkId} node ${node}, ${device.deviceNetworkId-ep}</FONT>"
	sendHubCommand(new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), node)), hubitat.device.Protocol.ZWAVE))
	sendHubCommand(new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), node)), hubitat.device.Protocol.ZWAVE))
}

or do this:

void switchOn(Integer node) {
	log.debug "<FONT COLOR=RED>Turning on Powerstrip - ${device.deviceNetworkId} node ${node}, ${device.deviceNetworkId-ep}</FONT>"
	def cmds = new hubitat.device.HubMultiAction()
	cmds.add(new hubitat.device.HubAction(command(encap(zwave.basicV1.basicSet(value: 0xFF), node)), hubitat.device.Protocol.ZWAVE))
	cmds.add(new hubitat.device.HubAction(command(encap(zwave.switchBinaryV1.switchBinaryGet(), node)), hubitat.device.Protocol.ZWAVE))
	sendHubCommand(cmds)
}

or this:

void switchOn(Integer node) {
	log.debug "<FONT COLOR=RED>Turning on Powerstrip - ${device.deviceNetworkId} node ${node}, ${device.deviceNetworkId-ep}</FONT>"
	def cmds = []
	cmds << command(encap(zwave.basicV1.basicSet(value: 0xFF), node))
	cmds << command(encap(zwave.switchBinaryV1.switchBinaryGet(), node))
	sendHubCommand(new hubitat.device.HubMultiAction(cmds, hubitat.device.Protocol.ZWAVE))
}
2 Likes

I can confirm, this has resolved this issue, and I'm able toi switch on/off via the Child device.

Brilliant!! Many thanks @chuck.schwer for the help. And obviously the guys here, @stephack, @rob and @cybrmage :+1:

Roy

@chuck.schwer: Very educational. Much better that the few other example I had found before. Thank you!!

1 Like