Trying To Figure Out Parent/Child App Coding

I have coded the following parent app:

String ParentVar = "Parent"
def ParentMethod() {
    return ParentVar
}

definition(
        name: "MyParent",
        namespace: "Hubi",
        author: "Hubi",
        description: "Parent For Parent/Child Test",
        category: "Convenience",
        iconUrl: "",
        iconX2Url: "",
        iconX3Url: "",
        oauth: [displayName: "HTML Endpoint", displayLink: "https://sharptools.io"])
 
preferences() {
    page(name: "setupScreen")
}
  
def setupScreen() {
    if (!state.accessToken) {   
        // Enable OAuth in the app settings or this call will fail
        createAccessToken() 
    }
     
    return dynamicPage(name: "setupScreen", uninstall: true, install: true) {
        section("Logging") {
            input name: "logEnable", type: "bool", title: "Enable logging?"
        }
    }
}
 
def installed() {
    updated()
}

def updated() {
    log.debug "updated()"
}

and child app:

definition(
        name: "MyChild",
        namespace: "Hubi",
        author: "Hubi",
        description: "Child For Parent/Child Test",
        category: "Convenience",
        iconUrl: "",
        iconX2Url: "",
        iconX3Url: "",
        oauth: [displayName: "HTML Endpoint", displayLink: "https://sharptools.io"])
        parent: "Hubi:MyParent"
 
preferences() {
    page(name: "setupScreen")
}
  
def setupScreen() {
    if (!state.accessToken) {   
        // Enable OAuth in the app settings or this call will fail
        createAccessToken() 
    }
     
    return dynamicPage(name: "setupScreen", uninstall: true, install: true) {
        section("Logging") {
            input name: "logEnable", type: "bool", title: "Enable logging?"
        }
    }
}
 
def installed() {
    updated()
}

def updated() {
    if (logEnable) log.debug "updated()"
    
    log.debug "ParentMethod = " + parent.settings.ParentMethod()
    
//    log.debug "ParentVar = " + parent.settings.ParentVar
}

When I install the child app after the parent app is installed I get the following Log entry for the child:

I thought I have followed the examples I found in the community but apparently not. Could someone please explain how to make this child access to the parent correctly. If you have an example of what I am trying to do I would appreciate it. Also could you point out some documentation of this topic?

Thanks

The settings map is not meant to be directly manipulated (even the same app). Try updateSetting() instead. I think this is accessible from parent to child, but if not, any method you create yourself for sure is, so you can make one that does what you want.

I appreciate the response but I have tried several iterations with updateSettings() and not getting anywhere. Any chance that you could point me to a complete Parent and Child example? I don't care if the child obtains a variable via a method or directly.
Thank You

Note that there is no "s" at the end: updateSetting

What actually happens when you try?

I don't think there is any official complete example, though the needed methods should be documented.

For one I wrote myself, check out this app: Hubitat/apps/DimmerButtonController at master · RMoRobert/Hubitat · GitHub. Use the "v3" child specifically as that is one that actually makes calls into the parent, though possibly not how you will do so (examples are somewhat hard to find as some parent apps are little more than "containers" for related child apps...).

1 Like

During my iterations of changing MyChild I no longer see MyChild in the list after selecting the Apps tab and selecting Add user app. I have rebooted and changed the name to MyChild.1 and then thought a shutdown might help... it did not! I then went into the hubitat documentation and under App Overview section I copied the "A Simple App" example. I then selected the Apps Code tab and then New app and pasted the Simple App into the blank window. I did not change anything and then saved it and selected Oauth/Update. Everything appeared correct and I went back to the Apps tab and selected Add user app and "My First App" did not show up in the list (Same outcome as my program "MyChild"). What can I do to get Hubitat working again. And perhaps more important what could I have done to prevent this?

Thanks

Without fooling around with anything I went back to the Apps tab and then selected Add user app and both MyChild and My First App appears in the list!!!! Please tell me what could be going on?

Thanks Again

Sounds like you didn't hit "Done" after opening the app the first time to actually install it (alternatively, installOnOpen: true in your definition will do it). Such apps are "orphaned" and can temporarily be navigated back to if you still have the URL (or the app ID or can get to it from a device you've selected, though that's unlikely to have saved without a "Done," either), otherwise the platform eventually cleans them up.

1 Like

I like the last comment... "the platform eventually cleans them up". Between the apps showing up and not showing up I did nothing else except allowed time to pass... I did no tinkering. I would also figure that no matter what if I reboot/shutdown things would be OK... they were not. I was hoping to hear that Hubitat has a rebuild or consistency check that can be explicitly invoked. Ok... it looks like I am back to my original task.

I appreciate the response bertabcd1234.

I'm not sure if you still have concerns, or specifically what you mean with this:

An app that was not "fully" installed will be automatically removed, which should make things "OK" in that you do not have abandoned (unlisted) apps floating around. If you want a different outcome, you'll need to completely install the app, which can be done by hitting "Install" the first time you open the app (I made a mistake above when I said "Done" -- the button is in the same place and does almost the same thing, but this is what it will say for new apps) or use installOnOpen: true.

The latter can be quite handy if you -- or a user -- is likely to launch the parent app, click a button to install a child app, and you don't want to make everyone "Install" or "Done" their way out to commit everything. I normally specify this on, at least, my parent apps.

When I said "things would be OK... they were not" meant that after reboot when I went into the Apps tab and then selected Add user app I did not see the apps that I created and Oauth'd.

I deleted the "My First App" that I used prior. I then just went into the Apps code tab and entered that code again and Oauth'd it and saved it and then exited the editor. I then went to the Apps tab and selected Add user app and "My First App" did not exist in the list.

I just went back into the Apps tab and selected Add user app and it is now appears!? I brought "My First App" back into my Hubitat because I wanted to bring your "DimmerButtonontroller" app in and the same thing happened... it did not show up in the list. Just like "My First App" it will be there and then NOT be there.

Is there a diagnostic I can run on the Hubitat environment that would check for errors/problems? I realize you think this is user error but that is why I selected "My First App" to demonstrate the problem.

Thanks

A backup, soft reset, and restore of your database would clear things up if that is the problem. You can do this manually, or you can have the hub do it for you by just doing Settings > Reboot with the "rebuild database" option selected (much easier, though no way to tell if it actually did it).

I did indeed assume user error, or at least not knowing that there are complete and incomplete app install "states" (something that doesn't normally come up), but in any case, the latter is the only time something like this should happen. :slight_smile:

Appreciate the response. And I took your recommendation to Reboot with the "rebuild database" option selected. Earlier today I brought in your "Dimmer Button Controller" and "Dimmer Button Controller (Child App) 3":

To minimize changes I left your name. I then went to the Apps tab and find the following:

Please note that the child is not present. Earlier the "Dimmer Button Controller" app did not show up in this list either. It seems if I do nothing and bring this list up again I see things changed!?

Thanks

I just commented out "parent:" in the child and it now shows up in the list. Should it show up if it has the line "parent:"?

I just UNcommented out "parent:" and it is still in the list?

Child apps, i.e., ones that specify a parent: in their definition, will not show up in the Add User App list (or built-in, but you can't see that code to know in the first place). This is because they are meant to be installed only by creating an instance via the parent, which is the app that should show up.

If you un-comment (or remove) this restriction then add it back, apps you have already added will not be affected, though I would normally not recommend doing this, and this behavior is not documented/guaranteed/not subject to change.

1 Like

Appreciate the information. I finally took your Parent/Child example (Dimmer Button Controller and child) and added my own method to the parent and, of course, was able to execute it from the child. I now have a baseline to fool around with understanding child apps. Thanks for the example and all your feedback. From a newbies standpoint I think a book (or maybe just an epamphlet) on the missing things from the Hubitat help document would compensate the writer... with LOTS of examples. How's your calendar for the next many weeks? Thanks Again

1 Like