Drivers that dynamically create child devices

I've been thinking of combining my GE/Jasco component and non-component drivers into a single driver that simply has an option to make the children - or not - with a preference.

Are there any drivers that do something like that? Would be nice to have a go-by example, as I only have limited experience working with child devices.

If I understand correctly, the in-built stock "zooz power strip" driver does this.

1 Like

Ok, I should have said -

are there any USER drivers (that I can see the code of), that do this. :slight_smile: :slight_smile:

(but I will take a peek at the Zooz one too, to see how they did the UI / option naming)

My bad, not enough coffee yet. Pretty obvious thats what you were implying.

No, that's still helpful! I'll look at that one too, as I try to make my options named similarly to in-box ones whenever possible!

Fibaro Wall Plug driver is another one


I mean, it looks easy enough, so not sure I "need" a go-by, but thought I would ask anyway.

The Inovelli drivers have an option for the creation of child devices.

1 Like

I was thinking about this while mowing the lawn.

I think the reason I didn't do this before is that I don't know of any way to (if there even is) to turn capabilities (or commands either) on/off with a variable.

EDIT: Based on some searching it looks like that isn't possible, as I guessed.

Because when the parent is in "child on" mode there shouldn't be an on/off/set level on the parent. But when in "child off" mode those commands need to be on the parent.

Best I can tell, I would have to have all the capabilities and custom commands in the parent alll the time, and just make them do nothing when it is in "child on" mode - or pass them through to the child.

Not the end of the world, just ugly and it will make the parent show up in device pick lists it shouldn't (like switch, dimmer, etc) when in "child on" mode.

Not sure if this may help, but I know @djgutheinz does some fancy stuff with variables in the tp-link energy monitoring plug driver. There might be something in that for you, or at least some ideas.

In a base driver, you can not turn capabilities / commands on/off with a active variable (i.e., one that can be accessed in preferences). You can do this is a driver-code variable (I do this to reduce my number of code files.) See below example from

The def type() allows me to control several the availability of commands and capabilities within the drivers.

  • Dimming Switch adds capabilities
    • Switch Level
    • Level Preset
  • If Type contains "EM" the EM capabilities and attributes are added).

Nothing special here. However, this ONLY works on these static type calls. It does not work on getDataValue or anything else. It is all changes made to the driver file itself.

That being said, you could do a preference that creates / deletes children to add specific functions dependent on Scenario. For example, there is an RGBW light controller that could control a RGBW strip, a RGB strip + a Mono Strip, Two CT Strips, A CT Strip and two Mono Strips, or 4 Mono Strips. A preference would allow the creation of the correct children (if it could not be determined from the data from the device) (I actually ran into this example). There is so much else you can do, just develop a use case and the the logic flow. GOOD LUCK.

def driverVer() { return "6.3.2" }
def type() { return "Plug Switch" }
//def type() { return "Dimming Switch" }
//def type() { return "EM Plug" }
def file() {
	def filename = type().replaceAll(" ", "-")
	if (type() == "Dimming Switch") {
		filename = "DimmingSwitch"
	return filename
import groovy.json.JsonSlurper

metadata {
	definition (name: "Kasa ${type()}",
				namespace: "davegut",
				author: "Dave Gutheinz",
				importUrl: "${file()}.groovy"
			   ) {
		capability "Switch"
		if (type() == "Dimming Switch") {
			capability "Switch Level"
			capability "Level Preset"
		capability "Actuator"
		capability "Refresh"
		command "setPollInterval", [[
			name: "Poll Interval in seconds",
			constraints: ["default", "5 seconds", "10 seconds", "15 seconds",
						  "30 seconds", "1 minute", "5 minutes",  "10 minutes",
						  "30 minutes"],
			type: "ENUM"]]
		if (type().contains("EM")) {
			capability "Power Meter"
			capability "Energy Meter"
			attribute "currMonthTotal", "number"
			attribute "currMonthAvg", "number"
			attribute "lastMonthTotal", "number"
			attribute "lastMonthAvg", "number"
		command "ledOn"
		command "ledOff"
		attribute "led", "string"
		attribute "connection", "string"
		attribute "commsError", "string"

Well, now that's pretty interesting! I'll read over that and think on it. Hadn't really thought about doing it like that before.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.