Help with smartapp - to work on certain days and flexible preferences based on SH modes


#1

Hello,
Looking for some help. I’m trying to write a smartapp to help with automating my Evohome - part of beta testing and also trying to learn groovy!

First problem I’m having is using code that I’d picked up from elsewhere that I thought should allow me to only take actions on selected days. The code is:

private getDaysOk() {
def result = true
if (days) {
def df = new java.text.SimpleDateFormat(“EEEE”)
if (location.timeZone) {
df.setTimeZone(location.timeZone)
}
else {
df.setTimeZone(TimeZone.getTimeZone(“Europe/London”))
}
def day = df.format(new Date())
result = days.contains(day)
}
log.trace "daysOk = $result"
log.debug "daysOk = $result"
result
}

but an if (daysOK) { elsewhere in the code was never triggering and using def temp = daysOK and then show the value of temp in debug suggest daysOK is returning null. Not sure why this works in other peoples’ smartapps but not mine. Not quite sure what the Private getdaysok() code actually is either.

Full smartapp is here https://github.com/TomMirf/SmartThings/blob/master/smartapps/Evohome-Automation/Evohome%20Automation.groovy

Second thing is that at the moment I have hardcoded a selection of my personal ST modes into the code with the appropriate setting for the evohome. What I’d like to do is in the preferences have a number of inputs, one for each of the ST modes where you select the relevant evohome mode. I can combine these into a list then iterate through it in the code I think but I can’t figure out how to make a flexible number of inputs based on the number of modes.

I’d love some help! Enjoying getting back into coding after about 15 years!

Thanks,
Tom