Events seem to have a mind of their own

(trac starr) #1


I have a custom SmartApp and DeviceType. I need to communicate between the two. Seems simple right?


Here I have a simple subscribe command defined in my install/update functions.

subscribe(myDevices, "getStatus", "refreshHandler")

This is followed up with the event handler function defined as:

def refreshHandler
    myDevices.each { d->
       def data = state.deviceValues[d.deviceNetworkId]

For simplicity my example is sending out to all devices, not just the one that sends out the originating event.

The deviceType is pretty simple(or at least should be).

I define a two custom commands and an attribute:

command "forceRefreshStatus"
command "generateEvent"
attribute "refresh", "string"

I then have a tile defined as

standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat") {
        state "default", action:"forceRefreshStatus", icon:"st.secondary.refresh"

Followed by a definition of the commands:

def forceRefreshStatus()
    def dni = device.deviceNetworkId
    sendEvent(name: "getProtectStatus", value: "${dni}")
def generateEvent(Map results) 
    log.debug "generate event"

Here’s what I find happens. I can press the Refresh tile the first time, the message is sent and received as expected, with the smartapp making the call to generateEvent with it’s data.

However, any other time I press Refresh the message isn’t received by the smartapp.

If I look at the event list for the device in the web dashboard things get confusing. Here’s the abbreviated version of what I see (oldest event at top)


  • DEVICE/getStatus/deviceNetworkId
  • COMMAND/empty/forceRefreshStatus
  • APP_COMMAND/empty/generateEvent

Second Press

Third Press

What the heck? I’m totally lost as to why the SmartApp no longer receives the message. I think it has something to do with the device Status? I have no clue how that works, but I notice my devices change from ACTIVE to INACTIVE at some point.