Here you go. I tried to put enough comments in that it would make sense. This is a completely useless app, but might be a good simple starter go-by.
definition(
name: "Simple App Example",
namespace: "Botched1",
author: "Jason Bottjen",
description: "Example App",
iconUrl: "",
iconX2Url: "",
iconX3Url: "")
preferences
{
page(name: "pageConfig")
}
def pageConfig()
{
dynamicPage(name: "", title: "", install: true, uninstall: true, refreshInterval:0)
{
section("Some Inputs")
{
// Great reference for capabilities: https://docs.smartthings.com/en/latest/capabilities-reference.html
input "tStat", "capability.thermostat", title: "Thermostat", description: "Thermostat", required: true, multiple: false
input "temp1", "capability.temperatureMeasurement", title: "Temperature", description: "Temperature", required: true, multiple: false
input "temp2", "capability.temperatureMeasurement", title: "Temperature", description: "Temperature", required: true, multiple: false
}
section("Some Variables")
{
input(name: "minOpen", type: "number", defaultValue: "10", range: "0..100", title: "Minimum Vent Open %", description: "Min Open %", required: false)
input(name: "moveSize", type: "number", defaultValue: "15", range: "0..100", title: "Vent Move Size %", description: "Move Size %", required: false)
input(name: "deadBand", type: "number", defaultValue: "2", range: "0..100", title: "Vent Position Deadband %", description: "Dead Band %", required: false)
}
section("Some Outputs")
{
input "dimmer1", "capability.switchLevel", title: "Dimmer 1", description: "", required: true, multiple: false
input "dimmer2", "capability.switchLevel", title: "Dimmer 2", description: "", required: true, multiple: false
}
section("Debug")
{
input "debugMode", "bool", title: "Enable debug logging", required: true, defaultValue: false
}
}
}
def installed()
{
log.debug "installed"
// This is run when the app is installed
initialize()
}
def updated()
{
log.debug "updated"
// This is run any time you click DONE on the app setup screen
initialize()
}
def initialize()
{
unschedule()
log.debug "initialize"
// If you want the app to run periodically on a schedule, then schedule it like this.
// Typically you would do this *OR* the subscriptions below, but not both. But you can do both if you have
// a reason to...
//
// This will run the code in section "checkDevices" every 1 minute.
runEvery1Minute(checkDevices)
// If you would rather not run it on a set schedule, and rather when a device's variable changes, you would comment out the runEvery above
// and setup subscriptions to the events you want to trigger action off of
//
// This will subscribe to dimmer1's ON/OFF status, dimmer level value, and the mode of your Hubitat hub.
// When any of those three valuies change, the code in "dimmer1ONOFFHandler", "dimmer1LEVELHandler", or "modeHandler" would run.
subscribe(dimmer1, "switch", dimmer1ONOFFHandler)
subscribe(dimmer1, "level", dimmer1LEVELHandler)
subscribe(location, "mode", modeHandler)
}
def uninstalled()
{
log.debug "uninstalled"
// This is run when the app is uninstalled
}
def checkDevices()
{
// If scheduled in "initialize()" this chunk of code will run however often you scheduled it. Otherwise it will never run or do anything.
log.info("${app.label} - Ran")
// Fetch the current values of some of these devices, and stick them in a variable
def currentTSMode = tStat.currentValue("thermostatOperatingState")
def currentTemp1 = temp1.currentValue("temperature")
def currentTemp2 = temp2.currentValue("temperature")
def currentDimmer1Level = dimmer1.currentValue("level")
def currentDimmer2Level = dimmer2.currentValue("level")
def currentDimmer1ONOFF = dimmer1.currentValue("switch")
def currentDimmer2ONOFF = dimmer2.currentValue("switch")
if (debugMode==true)
{
log.debug "checkDevices"
log.debug "Thermostat State is: $currentTSMode"
log.debug "Temp1 is $currentTemp1"
log.debug "Temp2 is $currentTemp2"
log.debug "Dimmer1 Level is $currentDimmer1Level"
log.debug "Dimmer2 Level is $currentDimmer2Level"
log.debug "Dimmer1 ONOFF is $currentDimmer1ONOFF"
log.debug "Dimmer2 ONOFF is $currentDimmer2ONOFF"
}
// If you wanted to set dimmer 1 to ON:
// dimmer1.on()
// If you wanted to set dimmer 1 to OFF:
// dimmer1.off()
// If you wanted to set the level on Dimmer 1 to 50:
//dimmer1.setLevel(50)
}
def dimmer1ONOFFHandler(evt){
if (debugMode==true) log.debug "Dimmer 1 ON/OFF Status changed to: $evt.value"
}
def dimmer1LEVELHandler(evt){
if (debugMode==true) log.debug "Dimmer 1 Level % changed to: $evt.value"
}
def modeHandler(evt){
if (debugMode==true) log.debug "Mode changed to $evt.value"
}
And here is what the log looked like with debug turned on, and I moved the dimmer1 level and turned it off and on - and then the scheduled "checkDevices" code section ran and dumped all of the variables.
app:472019-02-06 04:29:22.105 pm debug Dimmer2 ONOFF is on
app:472019-02-06 04:29:22.103 pm debug Dimmer1 ONOFF is on
app:472019-02-06 04:29:22.101 pm debug Dimmer2 Level is 99
app:472019-02-06 04:29:22.099 pm debug Dimmer1 Level is 99
app:472019-02-06 04:29:22.097 pm debug Temp2 is 72
app:472019-02-06 04:29:22.095 pm debug Temp1 is 74.70
app:472019-02-06 04:29:22.091 pm debug Thermostat State is: idle
app:472019-02-06 04:29:22.089 pm debug checkDevices
app:472019-02-06 04:29:22.045 pm info Simple App Example - Ran
app:472019-02-06 04:29:04.464 pm debug Dimmer 1 ON/OFF Status changed to: on
app:472019-02-06 04:28:57.901 pm debug Dimmer 1 ON/OFF Status changed to: off
app:472019-02-06 04:28:50.576 pm debug Dimmer 1 Level % changed to: 99
app:472019-02-06 04:28:42.118 pm debug Dimmer 1 Level % changed to: 78
app:472019-02-06 04:28:24.725 pm debug initialize
app:472019-02-06 04:28:24.714 pm debug updated