Code for Loading "routine" page in settings area


(David Fenstermaker) #1

I’m new to this language so I’m trying to learn.

I’m modifying a already made program to be able to execute a selected routine when an event triggers. I’ve read that I need to create a dynamic page to refresh the local routines then the user can select which routines they want.

I figure out how to create the routine selection page, but how do I “call” thy page under the main preference page… below is my code

preferences {

page (name: "Settings", title: "Settings", install:true, uninstall:true){
  section ("Text alerts to...") {
    input("recipients", "contact", title: "Send notifications to") {
        input "phone1", "phone", title: "Phone Number 1", required: false
        input "phone2", "phone", title: "Phone Number 2", required: false
        input "phone3", "phone", title: "Phone Number 3", required: false
    }
  }
  section ("Activate alarms...") {
    input "alarms", "capability.alarm", title:"Alarms", multiple:true, required:false
    input "silent", "enum", options: ["Yes","No"], title: "Silent alarm only (Yes/No), i.e. strobe"
    input "clear", "number", title:"Active (seconds)", defaultValue:0
  }
  section ("Options...") {
    input "zipcode", "text", title: "Zip Code", required: false
    // http://www.wunderground.com/weather/api/d/docs?d=data/alerts
    input "filters", "text", title: "Filter Alerts (x,x,...)", required: false, defaultValue:"TOW,SEW,WAT,FLO,FOG,SPE"
    input "skipfilters", "bool", title: "Still text (skip filters)?", required: false, defaultValue:false
  }
  section ("Actions..."){
    input "selectActions"  //need to call "selectActions" page
  }}
  page(name: "selectActions", title:"Select Routine", nextpage:"Settings", uninstall:true)
}

def selectActions() {
    dynamicPage(name: "selectActions", title: "Select Routine...", uninstall: true) {

        // get the available actions
            def actions = location.helloHome?.getPhrases()*.label
            if (actions) {
            // sort them alphabetically
            actions.sort()
                    section("Hello Home Actions") {
                            log.trace actions
                // use the actions as the options for an enum input
                input "action", "enum", title: "Select an action to execute", options: actions
                    }
            }
    }
}