Works on IOS - doesn't on Android


(Andy - United Kingdom) #1

Guys
I wrote a small smartapp to toggle a switch on for a period of time then off for a period of time (used with a pump/drain)
Funny thing is the app works perfectly on IOS which I test on but it doesn’t show settings or much else on Android.

Is this a known issue or have I cocked up somehow?
(BTW I’m sure there is a better way to code this but it works for me)

Code below:

/**
 *  Cycle Switch Timer
 *
 *  Copyright 2017 Andrew Parker
 *
 *  The code for the days of the week is not mine - Unfortunately I cannot remember where it came from
 *	If this is your code please contact me so that I can credit you properly
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
    name: "Cycle Switch On Timer",
    namespace: "Cobra",
    author: "Andrew Parker",
    description: "Sets a switch on for a specified time then off for a specified time then on again... ",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
	 section("Which switch to enable/disable App") {
        input(name:"switch1", type: "capability.switch", required: false, multiple: true)
	}
    
    
     section("Which days to run") {
        input "days", "enum", title: "Select Days of the Week", required: true, multiple: true, options: ["Monday": "Monday", "Tuesday": "Tuesday", "Wednesday": "Wednesday", "Thursday": "Thursday", "Friday": "Friday", "Saturday": "Saturday", "Sunday": "Sunday"]
    }
      
     section("Which switch to cycle...") {
        input(name:"switch2", type: "capability.switch", required: true, multiple: true)
	}
    section("How long to stay on") {
		input(name:"ondelay", type:"enum", title: "Minutes", required: true, options: [1,2,3,4,5,10,15,20,30,40,50,60])
	}
    section("How long to stay off") {
		input(name:"offdelay", type:"enum", title: "Minutes", required: true, options: [1,2,3,4,5,6,7,8,9,10,15,20,30,40,50,60])
	}
    

}


def installed() {
	log.debug "Installed with settings: ${settings}"

	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"

	unsubscribe()
	initialize()
}

def initialize() {
	 subscribe(switch1, "switch", switch1Handler)
     
    
}


// Config & actions

def switch1Handler(evt){
   state.currS1 = evt.value 
   log.trace " $switch1 is $state.currS1"
   if (state.currS1 != "off" ) {
   runswitchOnNow()
   }
    if (state.currS1 != "on" ) {
   switchOff()
}
}



def runswitchOnNow () {
if (state.currS1 != "off" ) {
 def df = new java.text.SimpleDateFormat("EEEE")
    
    df.setTimeZone(location.timeZone)
    def day = df.format(new Date())
    def dayCheck = days.contains(day)
    if (dayCheck) {


	log.debug "Cycling power on switch(es): $switch2 "
    def delay = ondelay
    switch2.on()
    log.debug "switch: $switch2 is on"
    log.debug " Waiting for ${delay} minute(s) before switching off"
    
    
     if (delay == "1"){
    runIn(60, switchOff)}
     else if (delay == "2"){
    runIn(120, switchOff)}
      else if (delay == "3"){
    runIn(180, switchOff)}
      else if (delay == "4"){
    runIn(240, switchOff)}
      else if (delay == "5"){
    runIn(300, switchOff)}
    else if (delay == "10"){
    runIn(600, switchOff)}
     else if (delay == "15"){
    runIn(900, switchOff)}
     else if (delay == "20"){
    runIn(1200, switchOff)}
     else if (delay == "30"){
    runIn(1800, switchOff)}
     else if (delay == "40"){
    runIn(2400, switchOff)}
     else if (delay == "50"){
    runIn(3000, switchOff)}
     else if (delay == "60"){
    runIn(3600, switchOff)}
     
 
}
else {
 log.debug " Not today!"
 }
}
}


def switchOff (){
log.debug "Switching off"
switch2.off()
log.trace "$switch2 is now off"
switchbackOn()
}


def switchbackOn () {
 if (state.currS1 != "off" ) {
 def df = new java.text.SimpleDateFormat("EEEE")
    
    df.setTimeZone(location.timeZone)
    def day = df.format(new Date())
    def dayCheck1 = days.contains(day)
    if (dayCheck1) {


	log.debug "Turning on switch(es): $switch2 "
    def delay1 = offdelay
    log.debug " Waiting for ${delay1} minute(s) before switching on"
    
    
     if (delay1 == "1"){
    runIn(60, switchOn)}
     else if (delay1 == "2"){
    runIn(120, switchOn)}
      else if (delay1 == "3"){
    runIn(180, switchOn)}
      else if (delay1 == "4"){
    runIn(240, switchOn)}
      else if (delay1 == "5"){
    runIn(300, switchOn)}
     else if (delay1 == "6"){
    runIn(360, switchOn)}
     else if (delay1 == "7"){
    runIn(420, switchOn)}
     else if (delay1 == "8"){
    runIn(480, switchOn)}
     else if (delay1 == "9"){
    runIn(540, switchOn)}
    else if (delay1 == "10"){
    runIn(600, switchOn)}
    else if (delay1 == "15"){
    runIn(900, switchOn)}
     else if (delay1 == "20"){
    runIn(1200, switchOn)}
     else if (delay1 == "30"){
    runIn(1800, switchOn)}
     else if (delay1 == "40"){
    runIn(2400, switchOn)}
     else if (delay1 == "50"){
    runIn(3000, switchOn)}
     else if (delay1 == "60"){
    runIn(3600, switchOn)}
     
 else {
 log.debug " Not today!"
 }
}
}
}



def switchOn (){
log.trace "Switching back on"
runswitchOnNow ()

}

(Andy - United Kingdom) #2

This is apparently what it looks like on Android:


(www.rboyapps.com - Make your home your butler!) #3

Could be a temporary glitch with Android. What version of the app are you using?
Have you tried reducing the number of enum entries?


(Andy - United Kingdom) #4

@RBoy Thanks for taking the time to look at this.
Unfortunately I was trying to help someone else out with an app so I don’t have an android to test with.
I’ll try and find out the details.

Is there normally any difference?


(www.rboyapps.com - Make your home your butler!) #5

Not unless there is a bug in the android (which it is full of)