Httpget and logging

I have written a small driver to monitor the status of all the lights switches on my network.
I have the maker api installed.
I am using httpGet on an array of device ip's.

Now that everything is working well, I am disabling all the debug logs from the apps/drivers I use. However, every time the httpGet executes, I have three debug messages for each url.


lights2

In the screenshot, it shows a "listDevices", "FindDevice" and "deviceItem" for each of the url's in the array. I can not find anywhere to disable this debug logging. Any ideas?

Looks like it's not your driver, so I suspect that app 133 is MakerAPI and you need to turn off debugging in it.

4 Likes

I don't know what's wrong with me. That option was definitely not there when I looked twenty minutes ago. I think it's time for a break. Thanks for the reply. I totally feel deserving of the dunce cap.. lol.

2 Likes

Unrelated to your issue at hand but still odd: why are you using Maker API for this? Since you're writing an app code (but I'd suggest an app instead of a driver...), you could just offer a selector for the devices directly in your app then use those direct references to the device objects to do whatever you want on them, including querying their state.

Thank you for the direction. I have no idea why I wrote a driver instead of an app. I started with an app; but thought I could not subscribe to event changes from other devices. I'm still trying to wrap my head around the app/driver relationship.

At first it seemed from intuition the driver was the way to go. So next up... writing my first app :slight_smile:

2 Likes

I didn't catch that this was a driver, but if it does need to be a driver for some reason, I suppose that is an option. But my mind went there since this kind of thing is, indeed, normally an app. :slight_smile:

Apps can subscribe to changes (events) from devices; it's drivers that can't, as they are generally intended to be use in apps. This is really one of the primary purposes for which most apps are written — think of things like the Notifications app, Basic Rule, or anything you'd use to create an automation.

There is some new developer documentation, including some for apps, in case you haven't seen it yet. You can probably skip the general platform overview if you're already familiar, but then I might suggest:

Good luck!

2 Likes

Thank you for helping to clarify. I know I started as an app... but I guess I thought you could only subscribe to inputs you created directly in the app. I didn't see any examples on how to subscribe to items already defined in other apps.

After looking again at the app example you mentioned; I'm guessing the "inputs" are where you set which items you want to "watch" from the front-end?

Then, when you subscribe to the input name (backend); you will be notified via that function when anything selected from the other inputs is changed?

ie... if I create an input that is for "When one of these lights changes..."
Then go to the front-end of the app and select the five lights...
Anytime one of those lights status changes; it will fire my handler?
And from there I can get the specific device from the event being returned?

... sorry if this is all over the place.

You are correct. You'll need to provide an input to select these devices in your app. (The exception would be if these are child apps and you selected the devices in the parent app—and have some way to know which of those you want, in which case you can assign all or part of the value of a setting from one app to a setting in the other. I'm not sure I'd start this complicated.)

Yes, you can subscribe to events from devices that have been selected as part of an input. (I assume this is what you mean.)

You have to subscribe to the specific devices and events you are interested in (using the subscribe() method), then your "handler" (specified when you subscribe) method will run. This handler method is passed an event object, and one piece of information available on that object is the device that generated the event. For example:

subscribe(myInputName, "switch.on", "mySwitchOnHandler")

// ...

def mySwitchOnHandler(evt) {
   log.trace "device  = ${evt.device}" // DeviceWrapper object, will print displayName by default
   log.trace "attribute = ${evt.name}" // will always be 'switch' in this example
   log.trace "value = ${evt.value}" // will always be 'on' in this example
}
1 Like

Thanks for your time!! That helps.
So I now have an app.

I have an input:

input name: "lightDevices", type: "capability.switch", title: "When these lights are switched...", multiple: true

I subscribe to it on the updated() method:

subscribe( lightDevices, "switch.on", "mySwitchOnHandler", [filterEvents: false] )

Then I log on my handler:

def mySwitchOnHandler(evt) {
    log.trace evt.device
    log.trace evt.value
    log.debug evt
}
  1. How do I know what values are available in the evt response of mySwitchOnHandler()? I know there is .device and .value. Anything else in the object?
  2. Am I able to query the states of the additional values that were set in the input handler? Say I selected five switches in the input; but only one is being described in the handler. What is the best way to determine the states of the other four switches that were assigned to the input?

Here is my use-case:

  1. I have five lights that take up too much space on my main dashboard page. I have a heavily modified dashboard using fades between pages instead of additional dashboard links.
  2. I moved the five lights to their own dashboard page.
  3. On my main dashboard, I'd like a single icon that displays the status of each light.
  4. If any one of the five lights are "on", the tile should be "on".
  5. If all of the lights are off, the tile should be "off".
    ( I handle the last two with a class on the div container of the tile)

The issue, I think, is that I need to know the state of all five devices in order to build the tile html structure.

lights

If your app is keeping up with the on/off of all switches you should be able to do this with the subscriptions; alternatively you could query each device on the status change for any using deviceHandle.currentValue("switch")

1 Like

How do I get the deviceHandle of other switches from inside the subscribe() callback?
I've tried logging the response, but can only find .device and .value.
Are those the only two values in the returned object? How do I see all values? I try logging the response itself, but I get something like "com.hubitat.hub.domain.Event@b99190". How do I see a dump of all parameters and values in the response?

Thank you for your patience.

Are you looking for things like evt.device.currentValue("switch")?

I have no idea what I'm looking for.. lol. I know I'm looking for the status of other switches that have been selected in my input statement. But it looks like it only logs events for the device being selected/switched?

Please allow me a few moments, and I'll get my test code up on github with some comments... if you wouldn't mind taking a look.

But for now, I'm just curious how you know what all is possible from the returned response of subscribe? Are the "evt" parameters listed anywhere? Can you log them all to debug... so you can at least see what you are working with?

When you select the devices to subscribe to it creates an array of those devices, so just a matter of using that array to retrieve the values, i.e.

valuesMap = []
lightDevices.each {
     valuesMap["${it.name}"]=it.currentValue("switch")
}

Try:

log.debug evt.properties
1 Like

Okay, it's starting to make a little sense.
I dumped that array, and thought it was just a string of comma separated device names. Each one of those is the deviceObject?
This is what it looked like in my log:
[Living Room Ceiling Fan, Living Room Lights, Dining Room Lights, Bedroom Josh Lights, Bedroom Office]

Here is the code I'm working with:

Code

You're saying that line 40 is an array of the device objects?

Bingo!! Ahh... thank you for removing that splinter from the back of my mind!!

Nicole Scherzinger Television GIF

1 Like
valuesMap = []
lightDevices.each {
     //valuesMap["${it.name}"] = it.currentValue("switch")
    debug.log it.name
}
log.debug valuesMap

java.lang.NullPointerException: Cannot invoke method log() on null object on line 40 (method mySwitchOnHandler)

Line 40 being the log.debug.

change debug.log to log.debug

Ugh... I swear... It's my last job of seven years.
It was always debug.log. That's going to be a hard one to break.

You, sir, are amazing.
It all makes sense now.
Thank you SO VERY much for the help!

1 Like

Download the Hubitat app