Creating dynamic preference inputs


(Aaron) #1

So I’m trying to dynamically create a list of options based on the setting in a previous page like is documented here: http://docs.smartthings.com/en/latest/smartapp-developers-guide/preferences-and-settings.html#dynamic-preferences

preferences {
page(name: "config", title: "HTD (W)GW-SL1 Config", uninstall: true, nextPage: "active") {
    section() {
        input("ipAddress", "text", multiple: false, required: true, title: "IP Address:", defaultValue: "172.16.1.133")
        input("tcpPort", "integer", multiple: false, required: true, title: "TCP Port:", defaultValue: 10006)
        input("HTDtype", "enum", multiple: false, required: true, title: "HTD Controller:", options: ['MC-66', 'MCA-66'])
        input("theHub", "hub", multiple: false, required: true, title: "Pair with SmartThings Hub:")
    }
}
page(name: "active", title: "Select Active Zones and Sources", nextPage: "naming") {
    section("Which zones are available?") {
        input("active_zones", "enum", multiple: true, title: "Active Zones", options: controllerZones(HTDtype))
    }
    section("Which input sources are available?") {
        input("active_sources", "enum", multiple: true, title: "Active Sources:", options: controllerSources(HTDtype))
    }
}
}

// How many sources does our controller support?
private String[] controllerSources(controller) {
log.debug("finding sources for controller type: ${controller}")
switch(controller) {
	case "MC-66":
    	return ["1", "2", "3", "4", "5", "6"]
    case "MCA-66":
    	return ["1", "2", "3", "4", "5", "6"]
}
return []
}

// How many zones does our controller support?
private String[] controllerZones(controller) {
log.debug("finding zones for controller type: ${controller}")
switch(controller) {
	case "MC-66":
    	return ["1", "2", "3", "4", "5", "6"]
    case "MCA-66":
    	return ["1", "2", "3", "4", "5", "6"]
}
return []
}

However when I run that code, my debug lines are writing to the log:
11:38:36 AM: debug finding sources for controller type: null
11:38:36 AM: debug finding zones for controller type: null

I seem to be doing something wrong, but I can’t figure out for the life of me what it might be?


(Aaron) #2

LOL. Of course, 30sec after posting I realize my error:

The 2nd page has to be defined as a dynamic_page as thus:

def page2() {
dynamicPage(name: “page2”) {
section() { }
}
}


(Brandon) #3

Are you working on connecting the HTD MCA-66 to SmartThings? If so, could you share if you completed it and the source?


(Aaron) #4

I’ve been busy with other things (too many hobbies) and need to come up with a proxy to convert the REST API calls the ST can make to the raw TCP socket communication the MCA-66 expects. That said, you can check out some code here: https://github.com/synfinatic/SmartThings


(Brandon) #5

There is a person that did this with the vera named newverauser without a proxy. Obviously a different platform but I have a feeling he’s working on something for SmartThings too… @newzwaveuser

NewZwaveUser - Do you have a working solution?


(Aaron) #6

I’ve been talking to a bunch of people, including people at HTD. Vera doesn’t need a proxy since it supports standard TCP sockets.