Subscribe

i have a very simple smartapp that i use to send and receive events from homeseer, but its not working and i must be missing something obvious, but it seems the subscription of events don't work.

so in my preferences section i have

section(title: "Select Devices") {
        input "virtualSwitch", "capability.switch", title: "Select Switch", required: true, multiple:false
    }

i then have both the updated and installed section call the init() function which contains the following code and subscription

def init() {
  state.lastOnChanged = 0
  state.lastOffChanged = 0
  subscribe(virtualSwitch, "switch", handleEvent)
}

so this calls my handleEvent function when a switch event is recieved

which has the following very simple code

def handleEvent(evt) {
    
    log.debug "Event Value is: ${evt.value}"
    def result
	if (evt.value == "on")
    {
    	sendOnCommand()
    }
    else
    {
    	sendOffCommand()
    }
    
    
}

now i won't go into the next part of code. the handle event has a log.debug command to show the event value.

so now when i install the smartapp i get the following

so as you can see i have a valid subscription and when i turn on and off the switch i get the following in the log after updating the app.

app:862018-05-01 10:55:15.684:debugUpdated with token: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

app:862018-05-01 10:55:15.683:debugUpdated with Application Id: 86

app:862018-05-01 10:55:15.682:debughttp://xxx.xxx.xxx.xxx/apps/api/86

i then turn on and off the virtual switch. in the logs i receive nothing else and i can see the following in my

AFAIK my code is correct. however the smartapps are not processing events...so there is something broken here.

ok i have just rebooted the hubitat hub

now i get the following when turning off and on the hub

app:862018-05-01 11:03:09.780:debugSending Off Web Request to HomeSeer Id 996

app:862018-05-01 11:03:09.777:debugEvent Value is: off

app:862018-05-01 11:02:07.111:debugSending home Web Request to HomeSeer Id 996

app:862018-05-01 11:02:07.108:debugEvent Value is: on

the the hub was not processing subscriptions to events. this is only after a few days of using the hub. so the hub doesn’t have any handling around a failure of a process, and either restart the process or the hub. it so doesn’t fill me with confidence leveraging this platform.

anyway to get more detailed logging?

ok it seems im doing something that is killing the hub. i am working on developing and app, and all i do is update the app and the hub stops processing events, not just for that smartapp but all smartapps. but as we dont have root access to the android box, unable to assist in troubleshooting.

any suggestions?

Without posting the entire application source code, it will be pretty hard for others to assist with debugging this issue. I can tell you that subscribing to events within custom apps is working fine for me. No hub lockups.

One thing I did notice is that you’re using a function call init() to subscribe to your events. But, you don’t show what function(s) are calling init(). Here is how my HubDuino App handles subscriptions:

preferences {
	section("Select the HubDuino Bridge Device") {
		input "HubDuino", "capability.sensor"
    }    
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	subscribe()
    HubDuino.refresh()
}

def uninstalled() {
    childDevices.each { deleteChildDevice(it.deviceNetworkId) }
}

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

def subscribe() {
    subscribe(HubDuino, "all", childHandler)
}

@ogiewon yup i’m being very specific though as it doesn’t matter what is calling init() as i know init() is running and the events are being subscribed to. but then the function in that is supposed to run when the event is created never runs.

I also know now its not my code as a reboot of the hub and the same code works. until it doesn’t again at some indeterminable time later.

my hub is getting into a state where its not processing any events, not for this app or even rule machine. so this is falling down the cracks to where i have no visibility. so there is an unhandled exception on the underlying platform that is not being caught and actioned upon.

but i have gotten into this state by just updating the settings of an app without changing anything. as well as adding or removing a rulemachine rule. so if i can get traces or further logging i can troubleshoot. but the current state of affairs i cant see anything else to troubleshoot against.

Understood. Probably best to submit a case to support@hubitat.com to have them look into it.