Child variables from Parent

Folks,
This had been asked and answered before, however I am still running into issues.
Scenario:

Parent/Child app

Child sets a variable state or other like

def localtStatState = state.thermostatState
parent.callHeat(localtStatState) 

in parent I am trying to get that var " localtStatState"

def callHeat() {
    if (debugLogging) log.debug("Call for heat...")
    childApps.each {child ->
    
        debuglog "Child app: ${child.label}   Zone state    ${child.currentValue("localtStatState")}"
    }  

However this returns null , same with child.currentValue("state.thermostatState")

There was a discussion of using sendEvent from child but how would I subscribe parent for this event?

you could cheat,
have your parent call a function in the child.
Have the child function call a function in the parent that sends the data you are looking for.

It's actually easier than that... In your parent app...

def localtStatState = child.getState()?.thermostatState

The call to getState returns the state vars for the child. It's only a getter though, changes to the child state vars will not be saved.

1 Like

Um, so your child calls parent.callHeat(localtStatState)?

So your parent's function should be

   def callHeat(localtStateState) {  
   // now you can refer to localtStatState in this function
   }
3 Likes

Thank you, This is exactly what I did . Will try @srwhite solution as well - looks promising.
I am new to groovy (though had been around the block with other things) and need to figure out scoping issues for variables in HE