Does Web Service SmartApps support creating events?

(Jonathan Bisson) #1

Hey guys,

I’ve successfully created a Web Service app which basically listen to any REST API coming from my router when a new user connect to my router (DD-WRT). So how it works is when someone connect to my router (through WIFI) , the router will call a REST API to the web service smarthing app and I’ll catch the event there. At this time, I’ve sent a push notificaton inside the smart app and that works fine. I was wondering if I could maybe leverage this to an event and let other app subscribe to this event instead of just sending a push notification. Basically, transforming the web service app to a “soft” device handler with a capability.

This would allow other apps to subscribe to this event and do what ever they want to do with it. For example, I would prefer using the “notify when” smartapp to fire a notification on that new “event” instead of my smart app itself.

The first thing I had in mind is to create an event and fire it off from my smartapp but I don’t believe we can create event from a smartapp, only device handler correct?

The second thing I had in mind was that if only device handler can fire event, I would create a device handler that would be able to create event and will propagate, however, I don’t think the platform support creating virtual device handler and web service. Also it seems that all device handler need to be bind with a real device so don’t think this is good.

Is there any way I could do what I want to do (ie: create an event from a web service and let other app subscribe to it) or this is just not supported… ?

any help will help !



(Joshua Moore) #2

There is nothing stopping you from creating your own device type (virtual for instance) and creating a virtual device that has nothing to do with a physical one (you can create it in the IDE). I do this all the time to group lights and setup scenes.

( co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #3

You may actually be creating a Device here with a “Service Manager” SmartApp.

Devices can be “Web Services” devices that can use “createAuthToken()” to support incoming messages (in turn, creating Attribute update Events…).

(Jonathan Bisson) #4

Hey guys,

thanks for you help. I finally managed to get it working. I didn’t need a Service Manager. Basically, I created a device handler (virtual), that has the notification capability. From my Web Service smartapp, I just invoke my notification by doing

preferences {
section(“Title”) {
input “notification”, “capability.notification”, multiple: true

mappings {
path("/sendNotification") {
action: [
POST: “sendNotification”

def sendNotification() {

and on my device handler:
def deviceNotification(String str) {
log.debug "Executing ‘deviceNotification’"
sendEvent(name: “onNewUserConnected”, value: “$str”, descriptionText: “$str”, isStateChange:true)

Other apps can get subscribe to the attribute event by doing:
input “notification”, “capability.notification”, title: “Notifications”, required: false, multiple: true

subscribe(notification, “onNewUserConnected”, eventHandler)

thanks a lot guys, work great now!

(Ravi Dubey) #5

Hi @jbisson,

I have created Smart Web Service App which gets user’s switches and command it from my external application. Now, I would like to catch events and wants to manage other devices. For example, when door opens, a switch should get on.

Do you know how to achieve this? I am new in ST development and having tough time in getting this functionality.