I'm new to Harmony Hub integration - but have installed the driver from @ogiewon, no problems. I can send device commands, get activity and config information. Now I want to build an app that I can control my media equipment using Google Assistant. I will write a Google Automation that will "trigger" the custom app. Here is some basic, starter code:
definition(
name: "Media System Control",
namespace: "DHHJ",
author: "DHJ",
description: "Control all media functions",
category: "My Apps",
iconUrl: "",
iconX2Url: ""
)
preferences {
section {
input "MediaSystemSwitch", "capability.switch", title: "Media System Switch", multiple: false, required: true
}
}
def installed() {
log.debug "Installing Media Control app......"
updated()
}
def updated() {
log.info "Updating Media Control app......"
unsubscribe()
subscribe(MediaSystemSwitch, "capability.switch", MediaSystemSwitchEventHandler)
}
def MediaSystemSwitchEventHandler(evt) {
log.debug "Media System Event handler called with event name= ${evt.name}, value= ${evt.value}"
}
When Google Assistant "turns on the MediaSystemSwitch", the app is not installed/update. Is it because I have to define it's capability to something other than a generic switch? The HE log shows the switch being turned on so the Google part is okay.
I don't think this matters, but it's non-conventional in any case, so I would suggest:
Changing this to mediaSystemSwitch;
Changing this to match;
changing the reference to "mediaSystemSwitchEventHandler" (it is normally documented as a string, even though it's usually good about the name itself too); and
changing this to match, i.e., def medaSystemSwitchEventHandler.
This will at least bring you in line with Groovy conventions (camel-casing methods and variables), but the hub itself does some magic with certain names, and non-conventional capitalization can get confusing there even if this works otherwise (and it probably will since I don't think these are any of those, and even then...).
Anyway, back to the question:
Do you mean that installed() or updated() are not called? If so, this is normal. The first is called exactly once, when the user first adds the app. The latter is called only when you/the user clicks "Done" in the app. What should happen when your switch is turned on or off is that the event handler (mediaSystemSwitchEventHandler() or whatnot) runs.
Your problem is that this:
should be something like this:
// assuming you also adopt camel-casing:
subscribe(mediaSystemSwitch, "switch", "mediaSystemSwitchEventHandler")
// ^~~~~~ event/attribute name here,
// not capability name
Note that you also need to call subscribe() for that to happen in the first place. This should happen once you select the device and hit "Done" in your app (calling updated()), but it won't happen if you just select the device and don't "save" your settings this way.
Google doesn't trigger the app, it sends an event to the driver. To simplify the cycle, when Google sends the event to your "mediaSystemSwitch" driver, the app is listening to the switch event (on/off) via subscribe method.
When the app receives the event from subscribe(mediaSystemSwitch, "switch", "mediaSystemSwitchEventHandler"), then that event is passed to the method "medaSystemSwitchEventHandler(evt)"
Thx very much- my mistake with some typos. One question though- how does HE "know" that the mediaSystemSwitch should use the @ogiewon Harmony driver and not a generic switch capability, since they are both switch drivers?
It uses whatever device you pick in your app preferences. That's when the install() and update() methods are triggered. After you add the user app in your list of apps and you open, then select the device and hit done, that's install() method. If you later come back and change your app preferences that's when update() method is triggered.
It doesn't. If you want to allow for selection of only devices using a specific driver, use the device.driverName format instead of the capability.capabilityName format for the type on your input. See: App Preferences | Hubitat Documentation
But if you are just writing this app for yourself, this is also something you can just know and remember (or instruct users to do if not). I'd say it's fairly rare to restrict selection to only specific drivers, but the option is available if you need it.
Maybe I'm missing something here? I get that the app preferences uses the device mediaSystemSwitch and its installed and updated. But the input statement in preferences says that device has "capability.switch". Where/how does the Harmony integration driver come into play?
No, that is not a device. Is the name of your input field. Once you install the app, you'd be able to select the device with a switch capability from your list of switches.