Thank you, it’s a really good example and almost what I need. Let me try to explain my requirements using an example.
Thermostat modes
I would like to have an option to configure thermostat modes in the application. Each mode includes thermostatMode, heatingSetpoint, coolingSetpoint and other parameters. I would like to add, change or remove a mode at any time. Currently I have the following modes:
Off: thermostatMode="off"
Regular: thermostatMode=“auto”, heatingSetpoint=70, coolingSetpoint=80
Energy Saving: thermostatMode=“auto”, heatingSetpoint=65, coolingSetpoint=85
I may need other modes later on. My application should switch thermostat to one of these modes based on some configurable conditions (time of the day, presence sensors, movement sensors, windows/doors opened, etc.)
NOTE: I already tried to use Phrases, but the solution look overcomplicated and still cannot correctly process all events.
I tried to create a simple app with a UI similar to phrases with the following pages:
preferences {
page (name: "modes");
page (name: "modeConfiguration");
}
def modes() {
dynamicPage(name: "modes", title: "Configure Thermostat Modes", nextPage: "appPreferences") {
section ("List of Modes") {
for(int i = 0; i < state.modeNumber; i++) {
def mode_name=settings."mode_name_${i}"
href (name: "mode_${i}_id", title: "${mode_name}", page: "modeConfiguration?mode=${i}");
}
}
section ("") {
href (name: "modeAddInput", title: "Add a mode", page: "modeConfiguration?mode=${state.modeNumber}", required: false);
}
}
}
def modeConfiguration() {
currentMode=params.mode
dynamicPage (name: "modeConfiguration", title: "Add a thermostat mode", uninstall: false) {
section ("Mode Preferences") {
input (name: "mode_name_${currentMode}", type: "text", title: "Enter mode name");
input (name: "mode_therm_$currentMode}", type: "enum", title: "Enter thermostat mode", options: ["off", "auto", "heat", "cool"], refreshAfterSelection: true);
if (settings."mode_therm_${currentMode}"=="auto" || settings."mode_therm_${currentMode}"=="heat") {
input (name: "mode_heat_${currentMode}", type: "number", title: "Enter heat point");
}
if (settings."mode_therm_${currentMode}"=="auto" || settings."mode_therm_${currentMode}"=="cool") {
input (name: "mode_cool_${currentMode}", type: "number", title: "Enter cool point");
}
if (!settings."mode_name_${currentMode}") {
state.modeNumber = state.modeNumber+1;
}
}
}
}
The only issue is that parameters are not passed to the second page. I have several similar requirements (like configuring time of the day when thermostat should be switched to a different mode) for this app and for other apps.