Events being duplicated

Hi guys,

I’ve been creating a smartApp and noticed that the same event fires multiple times. I’ve written another app which boils it down to the problem. I’ve seen a few posts about this but they’re all very old so I though I would re-raise it.

Using my test switch (Original ST power outlet) I get 2 or 3 hits on manualSwitchHandler when I press the button on the side of the physical switch to turn it on.

definition(
    name: "Testing",
    namespace: "jamescoyle",
    author: "James Coyle",
    description: "Testing",
    category: "My Apps",
    iconUrl: "https://www.jamescoyle.net/wp-content/uploads/2020/10/octo-logo-fav.png",
    iconX2Url: "https://www.jamescoyle.net/wp-content/uploads/2020/10/octo-logo.png",
    iconX3Url: "https://www.jamescoyle.net/wp-content/uploads/2020/10/octo-logo.png"
)

preferences {
    section("Switches") {
        input "testingSwitches", "capability.switch", title: "Turn these devices on", multiple: true, required: false
    }
}

def installed() {
    initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"

    initialize()
}

def initialize() {
    unsubscribe()
  
    subscribeToSwitches()
}

/* Subscriptions */
def subscribeToSwitches(){

    testingSwitches.each { s -> 
        log.info "Subscribing: ${s}"
        subscribe(s, "switch", manualSwitchHandler)
    }
}

def manualSwitchHandler(evt) {
    log.info "DATE: ${new Date()}, ${evt.displayName}, Change: ${evt.isStateChange()}"
}

The log output looks like, for example:

14:42:11: info DATE: Mon Nov 09 14:42:11 UTC 2020, Office heater, Change: true
14:42:11: info DATE: Mon Nov 09 14:42:11 UTC 2020, Office heater, Change: true
14:42:11: info DATE: Mon Nov 09 14:42:11 UTC 2020, Office heater, Change: true

I’ve checked the events on the switch (under ‘My Devices’) and only one event is being raised.
I’ve logged the ID of the event using ${evt.id} and it’s the same ID for each log.
I’ve added a counter to an atomicState variable to prove that it is actually executing the method call multiple times and isn’t just a superficial log display error.

Is this intended behaviour? If not, any ideas?

1 Like

Each event should trigger a SmartApp subscription once. There is on-going issue with subscriptions which may be causing what you’re seeing. Tagging @vlad @erickv