API Call to pause/resume Apps

Hello -- is anyone aware if there's a way to call a Hubitat API that can pause or resume an app? It looks like the Maker API is available to control devices (which I do) but I'd like to use an API call to pause or resume a specific app. (I know you can do this in the interface; I'm just asking if it's possible with an API call.)

Any ideas?

Officially, nothing that I am aware of. Unofficially, you can probably cobble something together by doing a POST to a certain endpoint with a specific body (take a look at your browser's network console or similar feature when you check/uncheck the box in the UI), likely easy if you don't have hub security enabled and slightly difficult but not impossible if you do ... but that would be subject to break with any update if the mechanism this uses ever changes.

2 Likes

As @bertabcd1234 indicated, there is no official method to enable/disable an app. But it is pretty simple to do via an HTTP POST, sent for example, using Rule Machine.

All you need to know is the App-ID. There's a detailed example in the link pasted below describing how to disable/enable the Amazon Echo Skill.

5 Likes

Thank you all!

1 Like

From my HEFailover app:

Toggle Apps Code
def toggleApps(){
    getAppsList()
    state.appsList.each{
        if(it.id != app.id){
            if(state.appToggle == "disabled"){
                appsPost("enable", "${it.id}")
                if(debugEnabled) log.debug "enable, $it.id"
            }else{
                appsPost("disable", "${it.id}")
                if(debugEnabled) log.debug "disable, $it.id"
            }          
        }
    }     
    if(state.appToggle == "disabled") state.appToggle = "enabled"
    else state.appToggle = "disabled"
}

def appsPost(String eOrD, String aId){
    if(eOrD == "enable") tOrF = false
    else tOrF = true
    try{
        params = [
            uri: "http://127.0.0.1:8080/installedapp/disable",
            headers: [
                "Content-Type": "application/x-www-form-urlencoded",
                Accept: "application/json"
            ],
            body:[id:"$aId", disable:"$tOrF"], //
            followRedirects: true
        ]
        if(debugEnabled) log.debug "$params"
        httpPost(params){ resp ->
            if(debugEnabled) log.debug "appsPost response: $resp.data"
		}
    }catch (e){
        
    }
}

def getAppsList() { 
 //   if (security)

	def params = [
		uri: "http://127.0.0.1:8080/installedapp/list",
		textParser: true
	  ]
	
	def allAppsList = []
    def allAppNames = []
	try {
		httpGet(params) { resp ->    
			def matcherText = resp.data.text.replace("\n","").replace("\r","")
			def matcher = matcherText.findAll(/(<tr class="app-row" data-app-id="[^<>]+">.*?<\/tr>)/).each {
				def allFields = it.findAll(/(<td .*?<\/td>)/) // { match,f -> return f } 
				def id = it.find(/data-app-id="([^"]+)"/) { match,i -> return i.trim() }
				def title = allFields[0].find(/data-order="([^"]+)/) { match,t -> return t.trim() }
				allAppsList += [id:id,title:title]
                allAppNames << title
			}

		}
	} catch (e) {
		log.error "Error retrieving installed apps: ${e}"
        log.error(getExceptionMessageWithLine(e))
	}
    state.appsList = allAppsList.sort { a, b -> a.title <=> b.title }
}
4 Likes