I don't see this function in the hubitat docs, though they're so often incomplete I typically spend my time reading the ST docs. It looks like I want to do something similar to this post from ages ago which was never answered.
Perhaps there is another way around this problem as well.
I'm learning the platform, and working on a notification dispatcher which allows selecting devices and sending notifications based on mode, time of day, etc. In order to accomplish this I think I need to be able to fire code off when a child device receives a deviceNotification command.
Cheers
You want to subscribe to device events.. Not a command..
subscribe
Subscribe to events sent from a device, app or location.
Signature
void subscribe(InstalledAppWrapper app, handlerMethod)
void subscribe(Location location, handlerMethod)
void subscribe(DeviceWrapper device, String attributeName, handlerMethod, Map options = null)
void subscribe(DeviceWrapperList devices, String attributeName, handlerMethod, Map options = null)
void subscribe(Location location, String attributeName, handlerMethod, Map options = null)
Parameters
app - Installed App to subscribe to.
location - Location to subscribe to.
device - Device to subscribe to.
handlerMethod - The method to run when an event is received.
attributeName - The name of the attribute to subscribe to.
options - Optional values to configure the subscribe. Possible values:
filterEvents - Used for device subscriptions. Set to false to receive all events, defaults to true and events that do not have a changed value will not be processed.
1 Like
device notification is a command to a device. But the device itself has to publish an attribute for your app to subscribe to. What driver are you using that you are trying to subscribe to the event of?
If you are trying to have some middleman device receive the notification, you most likely want to have a driver like this one to do it.
/**
*/
metadata {
definition (name: "Virtual Notification", namespace: "Ryan780", author: "Ryan780") {
capability "Notification"
capability "Actuator"
}
preferences {
}
}
def installed(){
sendEvent(name:"message", value:" ")
}
def updated() {
}
def initialized(){
}
def deviceNotification(message){
message = message.replace("%20"," ").replace("%5B","[").replace("%5D","]")
sendEvent(name: "message", value: message, isStateChange:true)
}
This driver will allow you to use it in Rule Machine or anywhere else you use Device Notification. But all it does is publish the message as the attribute "message". It has the capability "actuator" just to make device selection easier. You then subscribe to the message attribute and you are all set.
Note: The replace is there just because where I was using this was from the Maker API. you can keep it or modify that as you need.
Interesting .. I was wondering where this came from as I had never seen this used before.. Looks like there is a function like that in ST.. Weird.. But there is no equivalent here.. Nor should there be on ST IMHO..
https://docs.smartthings.com/en/latest/ref-docs/smartapp-ref.html#subscribetocommand
When you have unlimited cloud resources at your disposal it's very easy to "over-engineer" things.
1 Like
Perfect, thanks. I have a custom device driver as well, but I didn't think to use it to convert a notification into an event.
Yeah, this is the problem with not having documentation ... you have to wander around another platform which inspired this one in order to get ideas...but sometimes you get the wrong ideas!
Take a look at Follow Me, sounds like it already does a lot of what your looking for. Feel free to look at the code too.