Could someone point me to an example of a sender and receiver App? Or provide me a snippet of what I do in each App?
Thanks
The reciever app would use the subscribe method to be informed of the event’s contents
subscribe(location, "cloudBackup", "cldBuHandler")
…
def cldBuHandler(evt){
//log.debug evt.properties
if(evt.value != “true”) {
notifyDevice.each {
it.deviceNotification("Cloud Backup Failed on ${hub.location.name}")
}
}
}
Subscribe is described here:
What would the sender App look like?
It’s just a simple sendEvent (also documented in the link above)
sendEvent(name:”app1Event”, value:”somethingImportant”)
Note that apps, while technically able to send events, rarely do so. There's usually a different way to get what you need--but it's certainly an option if not. You may want to describe what you're really trying to do, and someone can suggest a Hubitat-y way to do it if you aren't certain this is what you're looking for.
I developed some automations on my PC using Visual Studio/C++. I needed Notifications to drive my automations and I got those from Apps on my phone that I sent over to the PC. Ring Alarm Pro are the main Notifications I needed but of course I would have Notifications from all the app's I have on my phone. When I got the Hubitat a few weeks ago one of the first things I did was to send the generated Notifications from the PC to the Hub. This Hub App I want to view as a Notification Server and the Client Apps would subscribe to the Events called "Notification". I know I have other ways of getting the info in the Notifications but I would like to stay with what I have and be able to SendEvent these Notifications to Client Apps that have subscribed. I have read that people have been able to get SendEvent's from Apps to another App but they seem to have problems in doing that. The only thing I have heard that succeeded was in Smarthings by using:
sendLocationEvent(name:"switch", value:"on", data:["ItWorked"], descriptionText: "description you want", deviceId: :"the-128bit-device-identifier-here", source: "DEVICE", isStateChange:true)
So far I haven't got this to work or the suggestion from thebearmay.
Thanks
What are the "client apps"? If they are all child apps of your parent app, a common paradigm for a related set of apps, they can communicate with each other directly without needing to send events.
Mmmm... sounds interesting. I have a way out now.,. thks. If I did not make the Clients children do you know how I could make SendEvent or SendLocationEvent work. A snippet of both Server and Client or actual examples would be really appreciated. I have tried both and haven't succeeded yet. Thanks
@thebearmay gave you an example above. One app would send, the other subscribe (the subscription being to the location
object, not a device as is often the case). If you go back to that approach, I'd suggest sharing a minimal non-working example so someone can see what you're trying.
But if the parent/child setup works for you, I'd say that's generally a better approach.
I got the following Server and Client App to work:
SERVER
definition(
name: "Notification Server",
namespace: "Example",
author: "Hubi",
description: "Impliment a server to send NOTIFICATION's",
category: "Convenience",
iconUrl: "",
iconX2Url: "")preferences {
section("Logging") {
input name: "logEnable", type: "bool", title: "Enable logging?"
}
}def installed() {
log.debug "installed()"
updated()
}def uninstalled() {
log.debug "uninstalled()"
}def updated() {
if (logEnable) log.debug "updated()"
sendLocationEvent(name:"NOTIFICATION", value:"Back Door Opened", data:["ItWorked"], descriptionText: "description you want", deviceId: "", source: "Ring", isStateChange: true)
}
CLIENT
definition(
name: "Notification Client",
namespace: "Example",
author: "Hubi",
description: "Impliment a client to receive NOTIFICATION's",
category: "Convenience",
iconUrl: "",
iconX2Url: "")preferences {
section("Logging") {
input name: "logEnable", type: "bool", title: "Enable logging?"
}
}def installed() {
log.debug "installed()"
updated()
}def updated() {
if (logEnable) log.debug "updated()"
unsubscribe()
def MyLocation = getLocation()
log.debug "MyLocation = " + MyLocation
subscribe(MyLocation, "NOTIFICATION", Handler)
}def uninstalled() {
log.debug "uninstalled()"
}def Handler(evt) {
log.debug "*** Entered Notification Handler ***"log.debug "evt = " + evt log.debug "evt.value = " + evt.value log.debug "evt.name = " + evt.name log.debug "evt.date = " + evt.date log.debug "evt.source = " + evt.source def Data = getData() log.debug "getData() = " + Data
}
I am getting an error in the Client when executing "def Data = getData()"... anybody know why?
Thanks for the help.
Needs to be evt.getData()
O’Boy! Programs are picky aren’t they…LOL Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.