Can’t make addChildDevice to work

Hello.
I want to create a new device when installing my smartApp.

The code is:

def initialize() {
....
addChildDevice("boardmedia46837", "Geiger Counter", getDeviceID(), null, [name: getDeviceID(), label: "test1", completedSetup: true, isComponent: false])
....
}

but when I try to install my smartapp I’m getting these errors:

SmartApp logs:

error groovy.lang.MissingMethodException: No signature of method: script_dth_e3141d889365cebbb290ec8de840f8277e2151b76d2a9e90c9f98842484fe56f.parse() is applicable for argument types: (java.lang.String) values: [updated]
Possible solutions: pages(), page(), pages(groovy.lang.Closure), page(java.util.Map), page(java.lang.String, java.lang.String), parseXml(java.lang.String) @line 56 (initialize)

Newly created device:

error groovy.lang.MissingMethodException: No signature of method: script_dth_e3141d889365cebbb290ec8de840f8277e2151b76d2a9e90c9f98842484fe56f.parse() is applicable for argument types: (java.lang.String) values: [updated]
Possible solutions: pages(), page(), pages(groovy.lang.Closure), page(java.util.Map), page(java.lang.String, java.lang.String), parseXml(java.lang.String) @line -1 (callCurrent)

Any suggestions please?
Thanks

Looks like your child device handers parse function is the problem, either it’s missing or doesn’t have the correct definition. Parse should ideally take a string parameter as an input.

def parse(description) {

}

sorry for my late response.

I get this error

groovy.lang.MissingMethodException: No signature of method: script_dth_e3141d889365cebbb290ec8de840f8277e2151b76d2a9e90c9f98842484fe56f.parse() is applicable for argument types: (java.lang.String) values: [updated]

But I haven’t have any ‘updated’ variable on my code except of

def updated() {
    unsubscribe()
    initialize()
}

On smartApp I use this:

settings.virtualswitch1.parse(“s1: ${usvh}”,"s2: ${cpm}”,"s3: ${cpm}”,"s4: ${acpm}”,"s5: ${backgroundSafeLevels}”,“s6: ${lastUpdate}”)

On DHT, I have this parse function:

def parse(String s1, String s2, String s3, String s4, String s5, String s6) {
}

As @RBoy advised, create a second parse() method in the DTH:

def parse( description )
{
}

On the face of it, your DTH is being called with parse( "[updated]" ) so that should handle it. Just because you aren’t explicitly calling parse() yourself, doesn’t mean that other things don’t.

1 Like

Ok I see thanks.
but now how I can pass values from smart app to dht?

I do it before using these:

On smartApp I use this:

settings.virtualswitch1.parse(“s1: {usvh}”,"s2: {cpm}”,"s3: {cpm}”,"s4: {acpm}”,“s5: {backgroundSafeLevels}”,"s6: {lastUpdate}”)

On DHT, I have this parse function:

def parse(String s1, String s2, String s3, String s4, String s5, String s6) {
}

but now it’s not working any more

I wouldn’t have expected it to have changed. Your original parse() method with six parameters should be used when you have six arguments, and the new parse() with one parameter should handle the one argument.

here is my code:

preferences {    
 ...
   	section(“Name The Device“) {
        input "target", title: "Device", required: true
    }


def initialize() { 
 ....
 addChildDevice("boardmedia46837", "Geiger Counter", getDeviceID(), null, [name: getDeviceID(), label: settings.target, completedSetup: true, isComponent: false])
 }


...
def handler(){
settings.target.parse("equivalentDose: ${usvh}","countsPerMinute: ${cpm}","countsPerMinuteForDashboard: ${cpm}","averageCountsPerMinute: ${acpm}","backgroundSafeLevels: ${backgroundSafeLevels}","lastUpdate: ${lastUpdate}")
} 

and I’m getting this error:

something went wrong: groovy.lang.MissingMethodException: No signature of method: java.lang.String.parse() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl) values: [equivalentDose: 0.29, countsPerMinute: 44, countsPerMinuteForDashboard: 44, …]
Possible solutions: wait(), trim(), size(), any(), grep(), size()

settings.target is a string; name of the device.

To be able to call the child device parse() function, you need the child device object.
To get the child object, you need to use the getChildDevice(s)

Assuming if you only have 1 child device, you could probably get away with -
childDevices[0]?.parse(...)

Worked!!! Thanks.
although, I’m getting 2 new devices.
The first has the parsed data displayed correctly, and the second (with same name) does not receive any data

  • EDIT-

I fixed that by placing the addChildDevice() inside of installed() instead of initialize()

Thanks guys for the help!