Composite Devices (Parent-Child Devices)

Absolutely! This is great news. I am working on the next major release of the PE653 DTH, converting it into a Composite Device. This eliminates the need for the deprecated Multi-Chanel SmartApp. Early testing looks good.

3 Likes

does the specifying the driver for the child work? If so how? I have been trying to port a UBS driver from ST but as I'm not a developer, I have just been bumbling through. It used you specify a route to the ST stock drivers but don't know what the HE version would be. Any help would be appreciated.

def createChildDevices(){
	log.debug "Adding Child Devices if not already added"
    for (i in 1..2) {
    	try {
        	log.debug "Trying to create child switch if it doesn't already exist ${i}"
            def currentchild = getChildDevices()?.find { it.deviceNetworkId == "${device.deviceNetworkId}-ep${i}"}
            if (currentchild == null) {
            	log.debug "Creating child for ep${i}"
				addChildDevice("Hubitat", "Virtual Contact Sensor", "${device.deviceNetworkId}-ep${i}", device.hub.id,
                	[completedSetup: true, name: "${device.displayName} (Contact${i})", isComponent: false]) //, label: "${device.displayName} (Contact${i})"
                /*addChildDevice(deviceHandlerName, "${device.deviceNetworkId}-${deviceName}${deviceNumber}", null,
         			[completedSetup: true, label: "${device.displayName} (${deviceName}${deviceNumber})", 
                	isComponent: false, componentName: "${deviceName}${deviceNumber}", componentLabel: "${deviceName} ${deviceNumber}"])*/

and

def createChildTempDevices() {
    log.debug "Creating Temperature children"
    for (i in 1..4) {
    	try {
        	//If we have a temperature reading from this sensor (1 to 4) then try to create a child for it
        	if (device.currentValue("temperature${i}") != null) {
            	log.debug "Have received temperature readings for termperature${i} so creating a child for it if not already there"
                def currentchild = getChildDevices()?.find { it.deviceNetworkId == "${device.deviceNetworkId}-temperature${i}"}
                if (currentchild == null) {
                    addChildDevice("smartthings", "Temperature Sensor", "${device.deviceNetworkId}-temperature${i}", device.hub.id,
                        [completedSetup: true, name: "${device.displayName} (Temp${i})", isComponent: false]) //, label: "${device.displayName} (Temp${i})"
                }

Not sure if this is possible so you may have to wait for an official response.

In the meantime, your createChildTempDevices() is still referencing smartthings. Also, as an alternative to using the built in virtual, you could create your own. In ST create a new driver and use the Virtual Contact Sensor as a template. Copy the code into HE and change the namespace to your own. Now you can update your component devices to point to your "custom" driver.

Yes, you are able to do this, however you have some problems with your code, you need to read the method signatures more closely to see what has changed when you are programming in our system. Also, the namespace of most of our drivers is hubitat. So for you example addChildDevice method, it should be coded like this:

addChildDevice("hubitat", "Virtual Contact Sensor", "${device.deviceNetworkId}-ep${i}", [name: "${device.displayName} (Contact${i})", isComponent: false])
1 Like

how would I point it to one of my drivers? what would i change hubitat too? They have a virtual contact sensor just not a temperature.

@chuck.schwer is there plans to have a virtual temperature driver? Thanks for your help with the code its working great now :smile:

Ideally for child devices the driver should be view only, that way they can only be forced out of or in sync though the parent device.

I have a Fibaro dual relay and use the Fibaro FGS-222 Double Relay Switch driver.
WHERE do I input your code to create the child device for the switch 2?
If I do it right, will I end up with another device in my list to use with RM?

Maybe this might help:

Sorry, but I am just learning Hubitat so bear with me.
1st I create this driver. Then I use it on my dual relay device and it will create my child devices (switch 1 and switch 2).

After doing above, do I go back and use my original driver on my relay, or do I just leave your driver in place?

This driver is for the Monoprice dual relays but it may work for your relays too. Be sure to install both drivers then on your device select just the parent driver. Then click the recreate child devices and it should create the two child switches under the parent and it will automatically use the child device driver. You can then rename the two child switches to whatever you want. Don’t change the driver of either the parent device or children.
Good luck!

Very nice! It seems to be working for my Fibaro dual relay.

Thank you

I thought this was working for my fibaro, but alas it's throwing a lot of errors.

So how do I remove these child devices so I can load a different driver for this device?

You wrote that you use FGS-222 Double Relay Switch driver.
Does it work without any modifications?

Can't get my FGS-222 to work with this driver. On/Off button doesn't trigger any actions.

Anyone knows how to set the parent device's status to ACTIVE in DTH? Is there a specific event I can return from parse() that does nothing but sets the status to active (NOP event)?

All the events from parent device's parse() are sent to child devices, therefore the parent device remains INACTIVE, even though the parent device is the one that does the heavylifting :slight_smile:

2 Likes

7 posts were split to a new topic: Help porting alarm system bridge

A post was split to a new topic: Help with temp sensor code

A post was merged into an existing topic: Help with temp sensor code

there any way to access parent Settings or attributes from a child device?
something like
getParent().settings.ip
the specific need is im trying to do a asynchttpGet from a child device but the ip,port,api key is store on tha parent device.
I could pass the information on creation to the child device and store it to use but it will be storing duplicate information.

a child can call
parent.method()

in the parent method() can return values.

Depending on frequency, this can be a lot of overhead.

Better is the parent to call child.methodA(), and the child store it.

If all children share the same settings, you can use @Field static .... in the child to define a shared variable that all children (if using the same source file) share. This both avoids state variables (DB accesses), and lot of children calling the parent, etc...

2 Likes

Just something to consider when designing a Composite Device...

Typically, the child devices are very lightweight, simple devices (similar to a virtual device). They will usually call a method of the Parent device to handle any real communications with the real world. This keeps all of the 'real code' local to the parent device, which already has access to all of the data needed to perform the necessary Zigbee, Z-Wave, or LAN/WAN communications.

2 Likes

I decide pass the responsibility to the parent device and leave the child as light as possible thanks for the fast response @ogiewon @nh.schottfam

1 Like