Httpget and logging

LOL. Switching languages, it's always the little things that get you.

1 Like

I see you found one way above, but they're in the docs, too. :slight_smile:

https://docs2.hubitat.com/developer/event-object

(Keep in mind that in Groovy, .getX() and .x are generally the same.)

1 Like

Yes, yes. Now that I know how those methods are tied to the returned event object; I feel MUCH more comfortable. I've been sidetracked with trying to get my garage door and a Zooz Zen17 working together. As soon as I have that licked, I'll be back to coding. But yes, thank you both, again. Very helpful making that connection.

Well.. running in circles again.
I have my app running well, and generating the html code I'd like in my dashboard tile. But how do I get it into the tile?

  1. Only way I know to get a dashboard tile is to create a driver, and assign it to a new device. Can it be done from an app?
  2. If not, how do you communicate with the driver attributes from the app callback method? How do I send my result from the app, to the attribute of the driver?

Only devices have attributes, so yes. Select the device with an input like you did the switches or have the app create it as a child, then using the device object use sendEvent the text for the attribute. Can also use a command in the device and pass the text as a parameter. This has some of the techniques in it:

https://raw.githubusercontent.com/thebearmay/hubitat/main/apps/hubInfoAggregation.groovy

This. one does the sendEvent version
https://raw.githubusercontent.com/thebearmay/hubitat/main/apps/forceClose.groovy

1 Like

In your second link; this line:
addChildDevice("hubitat","Virtual Button","cscButton001",[name:"Close Contact Button"])

Is that a device you had already created manually; and linked to a driver? Or are you creating it on-the-fly programmatically?

EDIT: Okay, I'm seeing how it creates a new device under devices on the front end. Continuing to experiment. Thanks for the kick in the right direction.

1 Like

Okay, the lightbulbs are going off everywhere.

So, in your second link, that is basically a button on the dashboard which, when clicked, sets all defined contacts to "closed" and all defined motions to "inactive"? That was a bit opposite of my case where I want to watch sensors, and update a tile. But SUPER helpful to see it work both ways.

Once issue, using your second link as an example again.
I define this, and all was good:

if(createChild) {
   addDevice()
} else {
   removeDevice()
}

I defined the addDevice() and I could see the child device created successfully.
Then I defined the removeDevice function:

def removeDevice(){
    unsubscribe()
    deleteChildDevice("lightManagerChild001")
}

No matter how many times I tried to save, I kept getting a generic error "unknown exception occurred while saving the app". It had to do with the deleteChildDevice() function. Commenting it out allowed me to save. Moving it to another function, like updated() worked, and the child device was removed. Moving the function back into removeDevice() once again caused the error and I was unable to save.

I altered my logic, and have deleteChildDevice() working from another function. But I'd still like to understand why it wouldn't work like your example.

May be a scoping issue but hard to tell. If you get a chance post the error and I'll see if it rings any bells.

Thanks. I have moved on and restructured the code. Since I'm the only one using the app; I just moved the method to the uninstalled() function, and it works fine there.

Okay, so now all is working properly, and I generate all the needed html on each switch subscription. Very cool. Now, how do I get the html back to the tile attribute?

I have this:

addChildDevice("hubitat","Virtual Switch","lightManagerChild001",[name:"Light Manager New"])

And that makes a new device (a switch) with the "on" and "off" commands. But it only has "switch" as an attribute. I can't get my html from my app into a new attribute for the child device.

I tried when adding the new child device, to see if I could set additional attributes at that point, but didn't work. I can pass the html back to the "switch" attribute, since that is the only one that is available, but then it overwrites the on/off value the switch should have.

Is there a way to add additional attributes (states??) to the child device when creating from an app?

Attributes have to be in the driver selected.

Here's one I use as a generic device for a few apps that I create tile data for:

https://raw.githubusercontent.com/thebearmay/hubitat/main/genHtmlDev.groovy

  1. Do you install that driver manually before installing the app; or auto-create it from the app? If from the app; I'm guessing you tie into the addChildDevice somehow?
  2. It looks like you are updating html "from" the driver "to" the app? Is this possible in the reverse? I'm guessing call the child method from the parent app?

I install the driver first. Then you can either create the device from the app or create it ahead of time and create a link to it using the input selection.

Once it's linked to the app you can either use the command with 2 parameters (slot #, text) or send an event directly, i.e.

childDevice.sendEvent(name:"html0", value:"$myHtmlStr")

Got it. Going to experiment. Thank you so much for the continued guidance.

Just paying it forward....

1 Like

BOOM!! It has all fallen into place.
This is so much better than the driver idea, and polling every so often.
You have been so helpful, I can't even put it into words.
I stalked you for a donation link; but couldn't find one.
Point me in the right direction; and let me at the very least buy dinner for you +1.

Thank you!

1 Like

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