Use addChildDevice with manual IP entry

Did you try

location.hubs[0].id

That just returns this:

[physicalgraph.app.HubWrapper@4dd94160, physicalgraph.app.HubWrapper@72532d8d][0].id

The HubWrapper does not have a GUID value that is accessible as far as I can tell.

The GUID is the only thing that works.

Yes! The “id” field works!! Thanks. How did you figure that out? Is there some way to view the fields or did you just guess a name? And @pstuart, how did you know that it needed a GUID? Thanks to you both for all your help!

If anyone else is stuck on this, here is the final answer that works for me:

preferences {
     section("Setup my device with this IP:port:") {
        input "theAddr", "string", multiple: false, required: true
	}
    section("on this hub...") {
        input "theHub", "hub", multiple: false, required: true
    }
}

def installed() {
    log.debug "Installed with settings: ${settings}"
    initialize()
}

def updated() {
    log.debug "Error: Cannot update with settings: ${settings}"
}

def initialize() {
    def parts = theAddr.split(":")
    def iphex = convertIPtoHex(parts[0])
    def porthex = convertPortToHex(parts[1])
    def dni = "$iphex:$porthex"
    def d = addChildDevice("com.obycode", "MacThing", dni, theHub.id, [label:"${app.label}", name:"MacThing"])
    log.trace "created ${d.displayName} with id $dni"
}

private String convertIPtoHex(ipAddress) { 
    String hex = ipAddress.tokenize( '.' ).collect {  String.format( '%02X', it.toInteger() ) }.join()
    log.debug "IP address entered is $ipAddress and the converted hex code is $hex"
    return hex
}

private String convertPortToHex(port) {
    String hexport = port.toString().format( '%04X', port.toInteger() )
    log.debug hexport
    return hexport
}
1 Like

Just intuition… and experience. Hacking things means tearing existing stuff apart and seeing how to put it back together.

ST docs absolutely suck. The examples are not even solid code, some pseudo code.

I don’t have time to always do things the right way, since this is a hobby for me, sometimes you have have to brute force break some methods and let the error messages lead you to what it is expecting.

Other times, you just guess and hope you get lucky…

No magic here, just trial and error and a never give up attitude, but always read the directions (RTFM) last, try first…

1 Like

Yes, it does. Here’s a sample code:

location.hubs.each {
	log.debug "Hub name: ${it.name}"
	log.debug "Hub ID: ${it.id}"
	log.debug "Hub type: ${it.type}"
	log.debug "Hub Local IP: ${it.localIP}"
} 

This produces (IDs are obscured for privacy):

5:47:12 PM PDT: debug Hub Local IP: 192.168.1.147
5:47:12 PM PDT: debug Hub type: PHYSICAL
5:47:12 PM PDT: debug Hub ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
5:47:12 PM PDT: debug Hub name: Home Hub
5:47:12 PM PDT: debug Hub Local IP: null
5:47:12 PM PDT: debug Hub type: VIRTUAL
5:47:12 PM PDT: debug Hub ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
5:47:12 PM PDT: debug Hub name: Virtual Hub

Thanks, got it working, weird though I can’t select the hub in the simulator only in the app…

Glad I was able to help. getProperties() is your friend :wink:

2 Likes

Ahh, good to know. Thanks a lot!