[OBSOLETE] Gentle Wake Up

Give me till this weekend. I still have one bug that I haven’t figured out… :frowning: Then I just need to clean up the code a bit. If I don’t post it by Sunday… just reply to the thread and I’ll post what I have.

1 Like

@rag1998 I’m also dealing with support on a dev issue. So its taking me much longer than I wanted to debug… frustrating.

On a positive note, I think I found my problem. Its not my coding per say but I’ll have to work around an issue with devices not setting the dimmer levels and responding back quick enough with the new level. joys.

Ahh k, thanks for the update, no worries take your time…

I’m using this app to slowly turn my lights on in the morning, but some mornings the lights jump instantly to full brightness instead of gradually. It’s happened twice in the past week. Any one else experiencing the same thing?

No, I’m still making more changes to my app… each time I think I have the code correct, I find a new challenge. However, I think i’m getting closer… i’ll post it later when its definitely working.

@steve_vlaminck Thanks for this app, i made a slight modification to add a second set of completion switch tasks, I wanted to be able to both shutoff and turn on a couple devices.

Again thanks a lot, love this app for my mornings!

@David_Solis That sounds pretty useful. Are you thinking about submitting it for publication? I’d love to see community changes make it in to the production version. Same goes for you @DrHill

@David_Solis - I’ll post mine today (thanks for the reminder). There is one small bug but I didn’t get a chance to go back yet and fix it. Overall, I’m pretty satisfied with the new app I wrote.

Awesome, looking forward to it…

Alright, I’ll just warn you now that I’m not a coder. Let me know if you have any questions.

/**

  • AutoDim Better
  • Copyright 2015 Casey Hill
  • 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.
  • App allows you to schedule the dimming of lights. The gentel wakeup app did not understand or sense when someone
  • physically changed the light settings. This app also resumes the light settings if you turn off the lights and
  • then back on again. The app also stops changing the dimming levels if you change the light settings which gentle wakeup didn’t
  • I created this app just because I couldn’t stand the lights being so dim during the day when they should be 100%
  • Likewise, I also didn’t like the lights at full strength during the night or when i woke up in the middle of the night.
    */
    // 10-9-2015 added check the dimmer value to make sure it doesn’t drop below the desired level.
    // 10-9-2015 fixed questions in preferences
    // 10-9-2015 fixed logging when lights should be set for the final setting in MyTimmer

definition(
name: “AutoDim Better”,
namespace: “clh41413”,
author: “Casey Hill”,
description: “Allows you to have a automatic dimming and brightening schedule based on sunrise and sunset.”,
category: “Convenience”)

preferences {
section(“Light”){
input(name: “myswitch”, type: “capability.switchLevel”, title: “Switch”, multiple: false, required: true)
}
section(“Sun Rise Settings”){
input(name: “dimmerLevelSunRise”, type: “number”, title: “Level to dim lights to…”, required: true)
input(name: “sunOffsetSunRise”, type: “number”, title: “How many minutes till desired level?”,required: true)
}
section(“Sun Set Settings”){
input(name: “dimmerLevelSunSet”, type: “number”, title: “Level to dim lights to…”, required: true)
input(name: “sunOffsetSunSet”, type: “number”, title: “How many mintues until the desired level?”,required: true)
}
}

def installed()
{
log.debug "Installing ${settings}"
subscribe(myswitch, “switch”, dimmerHandler)
state.rateofChange = null
state.percentOfRunTime = null
state.previousPercentOfRunTime = null
state.nextPercentOfRunTime = null
state.DevicePreviousLevel = null
//state.rateOfChange = null
state.percentOfRunTime = null
//state.ProgrammedLevel = null
state.DeviceCurrentLevel = null
state.DimmingLevelChanged = null
state.DayorNight = null
//state.FirstRun = null
subscribe(location, “sunsetTime”, dimmerHandler)
subscribe(location, “sunriseTime”, dimmerHandler)

}

def updated()
{
unsubscribe()
log.debug "Updated with ${settings}"
subscribe(myswitch, “Switch”, dimmerHandler)
state.DevicePreviousLevel = null
// state.rateOfChange = null
state.percentOfRunTime = null
// state.ProgrammedLevel = null
state.DeviceCurrentLevel = null
state.DimmingLevelChanged = null
state.DayorNight = null
// state.FirstRun = null
state.percentOfRunTime = null
subscribe(location, “sunsetTime”, dimmerHandler)
subscribe(location, “sunriseTime”, dimmerHandler)

}

def dimmerHandler(evt) {

def switchattr = myswitch.currentValue("switch")
log.debug "switch value: " + switchattr
//log.debug "SwitchChange: $evt.name: $evt.value"

if(switchattr == "on") { //assume its sunset already 
     log.debug "Switch was turned on; calling offHandler"
     state.DevicePreviousLevel = myswitch.currentValue("level")
   //  state.FirstRun = true
     offHandler()  
   }
else{
	 log.debug "Switch was turned off"
     log.debug "my Switch Level was " + myswitch.currentValue("level")
   //  state.FirstRun = false
     log.debug "state.firstrun: ${state.FirstRun}"
	 unschedule() 
}

}

def offHandler(evt) { //just determining if its Day or Night… pretty simple

if(getSunriseAndSunset().sunrise.time < now() && getSunriseAndSunset().sunset.time > now()){
   // log.debug "Calling to adjustTheLights SunRise"
    state.DayorNight = "sunRise"
}
else {
	// log.debug "Calling to adjustTheLights SunSet"
     state.DayorNight = "sunSet"
    }

log.debug "Calling Dimmer to Low() with state.DayorNight: " + state.DayorNight
dimmerTooLow()
//adjustTheLights()

}
def checkForDimmingChange(){
//function checks for the device level vs the programmed level
//function is designed to stop scheduling if you change the dimmer between each minute
// the if statement… well seems like its never perfect…

state.DeviceCurrentLevel = myswitch.currentValue("level")//maybe -1 after this or equal

log.debug "previous percentOfRunTime: " + state.previousPercentOfRunTime + " " + state.DeviceCurrentLevel
log.debug "percentOfRunTime: " + state.percentOfRunTime + " " + state.DeviceCurrentLevel
log.debug "next percentOfRunTime: " + state.nextPercentOfRunTime + " " + state.DeviceCurrentLevel

if((state.DeviceCurrentLevel < state.previousPercentOfRunTime && state.DeviceCurrentLevel > state.nextPercentOfRunTime) || (state.DeviceCurrentLevel > state.previousPercentOfRunTime && state.DeviceCurrentLevel < state.nextPercentOfRunTime && state.DayorNight == "sunRise" )){
 	log.debug "CheckDimming returned 1 ${state.DeviceCurrentLevel}"
    state.DimmingLevelChanged = 1 // continue to schedule
}
else{
  	log.debug "CheckDimming returned 0 " + state.DeviceCurrentLevel + " " + (state.nextPercentOfRunTime) + " " + (state.previousPercentOfRunTime) + " " + (state.nextPercentOfRunTime)
	state.DimmingLevelChanged = 0 // abort it all :-)
}

}

def adjustTheLights() {

myTimmer()
    
if(state.DayorNight == "sunRise"){//Sun is rising so lets get started
	log.debug "Sun Rise was called to adjust lights"

   if(percentOfRunTime<dimmerLevelSunRise){//your under the desired limit
        
        checkForDimmingChange()
        if(state.DimmingLevelChanged==1){ //checking to see if someone moved the dimming levels and only schedule if nothing has changed
             runIn(60,adjustTheLights) // checkin another minute and lower the lights a little more
             log.debug "Scheduling to turn up the lights"
        }  
                   
        myswitch.setLevel(state.percentOfRunTime)
        log.debug "SunRise if statement ran percentOfRunTime: " + (state.percentOfRunTime)
       
        }
  else {
    	
        checkForDimmingChange()
        if(state.DimmingLevelChanged==1){ //checking to see if someone moved the dimming levels and only schedule if nothing has changed
             runIn(60,adjustTheLights) // checkin another minute and lower the lights a little more
             log.debug "Scheduling to turn up the lights"
        }  
                    
        myswitch.setLevel(state.percentOfRunTime)
        log.debug "SunRise if statement ran percentOfRunTime: " + (state.percentOfRunTime)
       
        }
  if(state.percentOfRunTime>dimmerLevelSunRise || state.percentOfRunTime == dimmerLevelSunRise ){ //if you reached or exceeded the set dimmer level then your done
        log.debug "Dimmer level: " + dimmerLevelSunRise
        myswitch.setLevel(dimmerLevelSunRise) //set the dimmer to the minimum it suppose to be
        
        log.debug "SurnRise Time is up"
     	}
}
else {//Sun must be setting now
    
    log.debug "Sun Set was called to adjust lights"
    
    // if percentofruntime is negative then its past midnight.
     if((state.percentOfRunTime>-1) && (state.percentOfRunTime<100) && (state.percentOfRunTime>dimmerLevelSunSet)){
        checkForDimmingChange()
        if(state.DimmingLevelChanged ==1){ //checking to see if someone moved the dimming levels
            runIn(60,adjustTheLights) // checkin another minute and lower the lights a little more
            log.debug "Scheduling to turn down the lights again"
            myswitch.setLevel(state.percentOfRunTime)
        }
        
        //moved up to if
        //log.debug "percentOfRunTime: " + (state.percentOfRunTime)
        //log.debug "SunSet will continue to dimm"
      
        }
    else{
        myswitch.setLevel(dimmerLevelSunSet) //set the dimmer to the minimum it suppose to be
       // log.debug "percentOfRunTime: " + (state.percentOfRunTime)
        log.debug "SunSet Time move to final dimmer level"
        state.percentOfRunTime = 0
        }
}

}

//dimmerTooLow is used to deal with thing at the beginning. It only calls adjustTheLights to make the smooth lighting.
//We can also use dimmerTooLow to just adjust the lights to the proper when we are out of bounds on the percents.

def dimmerTooLow(){//if the automatic dimmer settings are too low then just check in again in a minute

myTimmer() //what is the dimmer setting

//in the morning if the current programmed dimmer is below the current level then fix it.
if(state.percentOfRunTime<state.DevicePreviousLevel && state.DayorNight == "sunRise"){
	log.debug "Its SunRise and the programming level is too low " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	runIn(60,dimmerTooLow) // checkin another minute
 }
 
 if(state.percentOfRunTime>state.DevicePreviousLevel && state.DayorNight == "sunRise"){
	log.debug "Its SunRise and the programming level is too high " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	myswitch.setLevel((state.percentOfRunTime+state.rateofChange))
    runIn(60,adjustTheLights)
 }
 
 //start adjusting the lights now that we match the current level
 if(state.percentOfRunTime == state.DevicePreviousLevel){
  	log.debug "Calling to Adjust the lights since the device level and programming level are the same"
 	adjustTheLights() //start adjusting the lights now that we are good
 }
 
 //in the afternonn if current level is lower than the programming level then fix it.
 // @ 6am the % runtime is 800 ish so the lights don't time to morning  10/11/15
 //I think this might break something by adding in the 100
 if(state.percentOfRunTime > state.DevicePreviousLevel && state.DayorNight == "sunSet"){
	log.debug "Dimmer to high, calling dimmertoolow to adjust the lights " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	runIn(60,dimmerTooLow) // checkin another minute
 }
 
 //in the afternoon if the currne level is higher than the programming level then fix it.
 if(state.percentOfRunTime < state.DevicePreviousLevel && state.percentOfRunTime > 0 && state.DayorNight == "sunSet"){
	log.debug "Dimmer too high, lowering it down and calling to adjust the lights " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	myswitch.setLevel(state.nextPercentOfRunTime)
    log.debug "change lights to " + state.nextPercentOfRunTime
    runIn(60,adjustTheLights)
    }
    
    if(state.percentOfRunTime < state.DevicePreviousLevel && state.percentOfRunTime < 0 && state.DayorNight == "sunSet"){
	log.debug "Dimmer too high and the time is up " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	myswitch.setLevel(dimmerLevelSunSet)
    log.debug "Done - Lights will be set to the final level: " + dimmerLevelSunSet
    //runIn(60,adjustTheLights)
    }
    log.debug "DimmerToLow Completed"

}

def myTimmer(){

log.debug "Timmer was called"
//** Setting variables
int diff, totalRunTime, rateofChange
diff = 0
totalRunTime = 0
state.percentOfRunTime = 0

int myoffsetSunRise = sunOffsetSunRise.toInteger() //making sure they are numbers
int myoffsetSunset = sunOffsetSunSet.toInteger() //making sure they are numbers
def mydate = new Date() 
def mynow = mydate.getTime()  //using this to define the time now

if(state.DayorNight == "sunRise"){
	log.debug "Daytime variables adjusted"
    diff = mynow - getSunriseAndSunset().sunrise.time
    totalRunTime = (myoffsetSunRise*60*1000)  //number of milliseconds
     state.previousPercentOfRunTime = (((diff-120000)/totalRunTime) * 100).toInteger()
     state.percentOfRunTime = ((diff / totalRunTime) * 100).toInteger()
     state.nextPercentOfRunTime = (((diff+120000)/totalRunTime) * 100).toInteger()
     state.rateofChange = (state.nextPercentOfRunTime-state.percentOfRunTime).toInteger()
}
else {
    log.debug "Nighttime variables adjusted"
    diff = mynow - getSunriseAndSunset().sunset.time
    totalRunTime = (myoffsetSunset*60*1000)  //number of milliseconds dimmerLevelSunSet
    state.previousPercentOfRunTime = (100-(((diff-120000)/totalRunTime) * 100)).toInteger()
    state.percentOfRunTime = ((100-(diff / totalRunTime) * 100)).toInteger()
    state.nextPercentOfRunTime = (100-(((diff+120000)/totalRunTime) * 100)).toInteger()
    state.rateofChange = (state.previousPercentOfRunTime-state.percentOfRunTime).toInteger()
}
/*
state.previousPercentOfRunTime = state.previousPercentOfRunTime.round(0)
state.percentOfRunTime = state.percentOfRunTime.round(0)
state.nextPercentOfRunTime = state.nextPercentOfRunTime.round(0)
state.rateofChange = state.rateofChange.round(0)

float a = state.previousPercentOfRunTime
log.debug a
a = a.round(0)
log.debug a
a = a.toInteger()
log.debug a
*/

state.percentOfRunTime = state.percentOfRunTime.toInteger()
log.debug state.previousPercentOfRunTime
log.debug state.percentOfRunTime
log.debug state.nextPercentOfRunTime
log.debug state.rateofChange
}

Hi All. I am about a week in to ST and found ‘Gentle Wake Up’. It worked great for a few days and has since stopped working. It seem that when I press play on the app for testing, it sets the dimmer to the correct beginning value, then never moves on. I am also new to programming so I am unclear how to troubleshoot this. Any thoughts?

It may be related to some platform issues in the last week:

I’m going to run a test night to see what is going on. I’ve noticed the sunset & sunrise doesn’t appear to be working at all either.

According to staff post in the forums, all the fixes have now been pushed out. So it would probably be a good idea to take the batteries out of the hub and then leave it unplugged for a full 15 minutes. Then power it up again.

You need to take the full 15 minutes so that all the devices on your network have time to realize that the coordinator is off-line and go into “panic mode.” That way when the hub back online they should do a new handshake.

This should also resynch your hub with your cloud account.

The good news - sunset is now working but it there was a mistake on my part.

I fixed a few more things which included the sunsetting and sunrising failing to trigger. Sorry about that.
This is a rewrite of the Gentle Wakeup app. I just couldn’t stand the thing continuing to dim after I had already set it where I wanted. This one stops dimming if you manually adjust the lights.

/**

  • AutoDim Better
  • Copyright 2015 Casey Hill
  • 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.
  • App allows you to schedule the dimming of lights. The gentel wakeup app did not understand or sense when someone
  • physically changed the light settings. This app also resumes the light settings if you turn off the lights and
  • then back on again. The app also stops changing the dimming levels if you change the light settings which gentle wakeup didn’t
  • I created this app just because I couldn’t stand the lights being so dim during the day when they should be 100%
  • Likewise, I also didn’t like the lights at full strength during the night or when i woke up in the middle of the night.
    */
    // 10-9-2015 added check the dimmer value to make sure it doesn’t drop below the desired level.
    // 10-9-2015 fixed questions in preferences
    // 10-9-2015 fixed logging when lights should be set for the final setting in MyTimmer
    // 10-26-2015 commented out unused variables
    // 10-30-2015 fixed sunrise and sunset subscriptions since they wouldn’t trigger

definition(
name: “AutoDim Better”,
namespace: “clh41413”,
author: “Casey Hill”,
description: “Allows you to have a automatic dimming and brighting schedule based on sunrise and sunset.”,
category: “Convenience”)

preferences {
section(“Light”){
input(name: “myswitch”, type: “capability.switchLevel”, title: “Switch”, multiple: false, required: true)
}
section(“Sun Rise Settings”){
input(name: “dimmerLevelSunRise”, type: “number”, title: “Level to dim lights to…”, required: true)
input(name: “sunOffsetSunRise”, type: “number”, title: “How many minutes till desired level?”,required: true)
}
section(“Sun Set Settings”){
input(name: “dimmerLevelSunSet”, type: “number”, title: “Level to dim lights to…”, required: true)
input(name: “sunOffsetSunSet”, type: “number”, title: “How many mintues until the desired level?”,required: true)
}
}

def installed()
{
log.debug "Installing ${settings}"
subscribe(myswitch, “switch”, dimmerHandler)
state.rateofChange = null
state.percentOfRunTime = null
state.previousPercentOfRunTime = null
state.nextPercentOfRunTime = null
state.DevicePreviousLevel = null
state.percentOfRunTime = null
state.DeviceCurrentLevel = null
state.DimmingLevelChanged = null
state.DayorNight = null
subscribe(location, “sunset”, dimmerHandler)
subscribe(location, “sunrise”, dimmerHandler)

}

def updated()
{
unsubscribe()
log.debug "Updated with ${settings}"
subscribe(myswitch, “Switch”, dimmerHandler)
state.DevicePreviousLevel = null
state.percentOfRunTime = null
state.DeviceCurrentLevel = null
state.DimmingLevelChanged = null
state.DayorNight = null
state.percentOfRunTime = null
subscribe(location, “sunset”, dimmerHandler)
subscribe(location, “sunrise”, dimmerHandler)

}

def dimmerHandler(evt) {

def switchattr = myswitch.currentValue("switch")
log.debug "switch value: " + switchattr
//log.debug "SwitchChange: $evt.name: $evt.value"

if(switchattr == "on") { //assume its sunset already 
     log.debug "Switch was turned on; calling offHandler"
     state.DevicePreviousLevel = myswitch.currentValue("level")
   //  state.FirstRun = true
     offHandler()  
   }
else{
	 log.debug "Switch was turned off"
     log.debug "my Switch Level was " + myswitch.currentValue("level")
   //  state.FirstRun = false
     log.debug "state.firstrun: ${state.FirstRun}"
	 unschedule() 
}

}

def offHandler(evt) { //just determining if its Day or Night… pretty simple

if(getSunriseAndSunset().sunrise.time < now() && getSunriseAndSunset().sunset.time > now()){
   // log.debug "Calling to adjustTheLights SunRise"
    state.DayorNight = "sunRise"
}
else {
	// log.debug "Calling to adjustTheLights SunSet"
     state.DayorNight = "sunSet"
    }

log.debug "Calling Dimmer to Low() with state.DayorNight: " + state.DayorNight
dimmerTooLow()	

}
def checkForDimmingChange(){
//function checks for the device level vs the programmed level
//function is designed to stop scheduling if you change the dimmer between each minute
// the if statement… well seems like its never perfect…

state.DeviceCurrentLevel = myswitch.currentValue("level")//maybe -1 after this or equal

log.debug "previous percentOfRunTime: " + state.previousPercentOfRunTime + " " + state.DeviceCurrentLevel
log.debug "percentOfRunTime: " + state.percentOfRunTime + " " + state.DeviceCurrentLevel
log.debug "next percentOfRunTime: " + state.nextPercentOfRunTime + " " + state.DeviceCurrentLevel

if((state.DeviceCurrentLevel < state.previousPercentOfRunTime && state.DeviceCurrentLevel > state.nextPercentOfRunTime) || (state.DeviceCurrentLevel > state.previousPercentOfRunTime && state.DeviceCurrentLevel < state.nextPercentOfRunTime && state.DayorNight == "sunRise" )){
 	log.debug "CheckDimming returned 1 ${state.DeviceCurrentLevel}"
    state.DimmingLevelChanged = 1 // continue to schedule
}
else{
  	log.debug "CheckDimming returned 0 " + state.DeviceCurrentLevel + " " + (state.nextPercentOfRunTime) + " " + (state.previousPercentOfRunTime) + " " + (state.nextPercentOfRunTime)
	state.DimmingLevelChanged = 0 // abort it all :-)
}

}

def adjustTheLights() {

myTimmer()
    
if(state.DayorNight == "sunRise"){//Sun is rising so lets get started
	log.debug "Sun Rise was called to adjust lights"

   if(percentOfRunTime<dimmerLevelSunRise){//your under the desired limit
        
        checkForDimmingChange()
        if(state.DimmingLevelChanged==1){ //checking to see if someone moved the dimming levels and only schedule if nothing has changed
             runIn(60,adjustTheLights) // checkin another minute and lower the lights a little more
             log.debug "Scheduling to turn up the lights"
        }  
                   
        myswitch.setLevel(state.percentOfRunTime)
        log.debug "SunRise if statement ran percentOfRunTime: " + (state.percentOfRunTime)
       
        }
  else {
    	
        checkForDimmingChange()
        if(state.DimmingLevelChanged==1){ //checking to see if someone moved the dimming levels and only schedule if nothing has changed
             runIn(60,adjustTheLights) // checkin another minute and lower the lights a little more
             log.debug "Scheduling to turn up the lights"
        }  
                    
        myswitch.setLevel(state.percentOfRunTime)
        log.debug "SunRise if statement ran percentOfRunTime: " + (state.percentOfRunTime)
       
        }
  if(state.percentOfRunTime>dimmerLevelSunRise || state.percentOfRunTime == dimmerLevelSunRise ){ //if you reached or exceeded the set dimmer level then your done
        log.debug "Dimmer level: " + dimmerLevelSunRise
        myswitch.setLevel(dimmerLevelSunRise) //set the dimmer to the minimum it suppose to be
        
        log.debug "SurnRise Time is up"
     	}
}
else {//Sun must be setting now
    
    log.debug "Sun Set was called to adjust lights"
    
    // if percentofruntime is negative then its past midnight.
     if((state.percentOfRunTime>-1) && (state.percentOfRunTime<100) && (state.percentOfRunTime>dimmerLevelSunSet)){
        checkForDimmingChange()
        if(state.DimmingLevelChanged ==1){ //checking to see if someone moved the dimming levels
            runIn(60,adjustTheLights) // checkin another minute and lower the lights a little more
            log.debug "Scheduling to turn down the lights again"
            myswitch.setLevel(state.percentOfRunTime)
        }
      
        }
    else{
        myswitch.setLevel(dimmerLevelSunSet) //set the dimmer to the minimum it suppose to be
       // log.debug "percentOfRunTime: " + (state.percentOfRunTime)
        log.debug "SunSet Time move to final dimmer level"
        state.percentOfRunTime = 0
        }
}

}

//dimmerTooLow is used to deal with thing at the beginning. It only calls adjustTheLights to make the smooth lighting.
//We can also use dimmerTooLow to just adjust the lights to the proper when we are out of bounds on the percents.

def dimmerTooLow(){//if the automatic dimmer settings are too low then just check in again in a minute

myTimmer() //what is the dimmer setting

//in the morning if the current programmed dimmer is below the current level then fix it.
if(state.percentOfRunTime<state.DevicePreviousLevel && state.DayorNight == "sunRise"){
	log.debug "Its SunRise and the programming level is too low " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	runIn(60,dimmerTooLow) // checkin another minute
 }
 
 if(state.percentOfRunTime>state.DevicePreviousLevel && state.DayorNight == "sunRise"){
	log.debug "Its SunRise and the programming level is too high " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	myswitch.setLevel((state.percentOfRunTime+state.rateofChange))
    runIn(60,adjustTheLights)
 }
 
 //start adjusting the lights now that we match the current level
 if(state.percentOfRunTime == state.DevicePreviousLevel){
  	log.debug "Calling to Adjust the lights since the device level and programming level are the same"
 	adjustTheLights() //start adjusting the lights now that we are good
 }
 
 //in the afternonn if current level is lower than the programming level then fix it.
 // @ 6am the % runtime is 800 ish so the lights don't time to morning  10/11/15
 //I think this might break something by adding in the 100
 if(state.percentOfRunTime > state.DevicePreviousLevel && state.DayorNight == "sunSet"){
	log.debug "Dimmer to high, calling dimmertoolow to adjust the lights " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	runIn(60,dimmerTooLow) // checkin another minute
 }
 
 //in the afternoon if the currne level is higher than the programming level then fix it.
 if(state.percentOfRunTime < state.DevicePreviousLevel && state.percentOfRunTime > 0 && state.DayorNight == "sunSet"){
	log.debug "Dimmer too high, lowering it down and calling to adjust the lights " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	myswitch.setLevel(state.nextPercentOfRunTime)
    log.debug "change lights to " + state.nextPercentOfRunTime
    runIn(60,adjustTheLights)
    }
    
    if(state.percentOfRunTime < state.DevicePreviousLevel && state.percentOfRunTime < 0 && state.DayorNight == "sunSet"){
	log.debug "Dimmer too high and the time is up " + state.percentOfRunTime + " " + state.DevicePreviousLevel
   	myswitch.setLevel(dimmerLevelSunSet)
    log.debug "Done - Lights will be set to the final level: " + dimmerLevelSunSet
    //runIn(60,adjustTheLights)
    }
    log.debug "DimmerToLow Completed"

}

def myTimmer(){

log.debug "Timmer was called"
//** Setting variables
int diff, totalRunTime, rateofChange
diff = 0
totalRunTime = 0
state.percentOfRunTime = 0

int myoffsetSunRise = sunOffsetSunRise.toInteger() //making sure they are numbers
int myoffsetSunset = sunOffsetSunSet.toInteger() //making sure they are numbers
def mydate = new Date() 
def mynow = mydate.getTime()  //using this to define the time now

if(state.DayorNight == "sunRise"){
	log.debug "Daytime variables adjusted"
    diff = mynow - getSunriseAndSunset().sunrise.time
    totalRunTime = (myoffsetSunRise*60*1000)  //number of milliseconds
     state.previousPercentOfRunTime = (((diff-120000)/totalRunTime) * 100).toInteger()
     state.percentOfRunTime = ((diff / totalRunTime) * 100).toInteger()
     state.nextPercentOfRunTime = (((diff+120000)/totalRunTime) * 100).toInteger()
     state.rateofChange = (state.nextPercentOfRunTime-state.percentOfRunTime).toInteger()
}
else {
    log.debug "Nighttime variables adjusted"
    diff = mynow - getSunriseAndSunset().sunset.time
    totalRunTime = (myoffsetSunset*60*1000)  //number of milliseconds dimmerLevelSunSet
    state.previousPercentOfRunTime = (100-(((diff-120000)/totalRunTime) * 100)).toInteger()
    state.percentOfRunTime = ((100-(diff / totalRunTime) * 100)).toInteger()
    state.nextPercentOfRunTime = (100-(((diff+120000)/totalRunTime) * 100)).toInteger()
    state.rateofChange = (state.previousPercentOfRunTime-state.percentOfRunTime).toInteger()
}

state.percentOfRunTime = state.percentOfRunTime.toInteger()
log.debug state.previousPercentOfRunTime
log.debug state.percentOfRunTime
log.debug state.nextPercentOfRunTime
log.debug state.rateofChange
}

1 Like

Hi - I found this thread because I’m looking for a gentle wake up app that works like the smartthings one, but with the following improvements:

  1. Can be cancelled by turning any of the effected lights off (so that you can cancel it!)
  2. Can be set to only run during certain modes (So that if I am away it doesn’t run)
  3. Can be easily turned off and on from the smartapp (so that if I know I wont want it to run tomorrow I can just turn it off the night before)

Anything like this available? I saw Dr Hill’s smartapp but the code comes up with an error when you try to add it as a new smartapp

Let me know if this is possible,

@AdamV What error are your receiving? It could be the code it getting messed up on the ST site. I’ll likely find a new way to post it. So far, the code is installed on 4 different light switches in my house and running 100% w/o errors.

My app does all three things you mentioned.

I also updated it last week with a small bug fix but that was due to the sunrise and sunset issues.

@DrHill Thanks for getting back so quick!

The error is super weird and I suspect is due to the way that the code was pasted into ST. To get around this, highlight the code and use the “preformatted text” button in the editor in here before posting.

This is the error incase it helps:

Validation Error(s) occurred during save(): - Field error in object 'physicalgraph.app.SmartAppVersion' on field 'iconUrl': rejected value [null]; codes [physicalgraph.app.SmartAppVersion.iconUrl.nullable.error.physicalgraph.app.SmartAppVersion.iconUrl,physicalgraph.app.SmartAppVersion.iconUrl.nullable.error.iconUrl,physicalgraph.app.SmartAppVersion.iconUrl.nullable.error.java.lang.String,physicalgraph.app.SmartAppVersion.iconUrl.nullable.error,smartAppVersion.iconUrl.nullable.error.physicalgraph.app.SmartAppVersion.iconUrl,smartAppVersion.iconUrl.nullable.error.iconUrl,smartAppVersion.iconUrl.nullable.error.java.lang.String,smartAppVersion.iconUrl.nullable.error,physicalgraph.app.SmartAppVersion.iconUrl.nullable.physicalgraph.app.SmartAppVersion.iconUrl,physicalgraph.app.SmartAppVersion.iconUrl.nullable.iconUrl,physicalgraph.app.SmartAppVersion.iconUrl.nullable.java.lang.String,physicalgraph.app.SmartAppVersion.iconUrl.nullable,smartAppVersion.iconUrl.nullable.physicalgraph.app.SmartAppVersion.iconUrl,smartAppVersion.iconUrl.nullable.iconUrl,smartAppVersion.iconUrl.nullable.java.lang.String,smartAppVersion.iconUrl.nullable,nullable.physicalgraph.app.SmartAppVersion.iconUrl,nullable.iconUrl,nullable.java.lang.String,nullable]; arguments [iconUrl,class physicalgraph.app.SmartAppVersion]; default message [{0} cannot be null] - Field error in object 'physicalgraph.app.SmartAppVersion' on field 'iconX2Url': rejected value [null]; codes [physicalgraph.app.SmartAppVersion.iconX2Url.nullable.error.physicalgraph.app.SmartAppVersion.iconX2Url,physicalgraph.app.SmartAppVersion.iconX2Url.nullable.error.iconX2Url,physicalgraph.app.SmartAppVersion.iconX2Url.nullable.error.java.lang.String,physicalgraph.app.SmartAppVersion.iconX2Url.nullable.error,smartAppVersion.iconX2Url.nullable.error.physicalgraph.app.SmartAppVersion.iconX2Url,smartAppVersion.iconX2Url.nullable.error.iconX2Url,smartAppVersion.iconX2Url.nullable.error.java.lang.String,smartAppVersion.iconX2Url.nullable.error,physicalgraph.app.SmartAppVersion.iconX2Url.nullable.physicalgraph.app.SmartAppVersion.iconX2Url,physicalgraph.app.SmartAppVersion.iconX2Url.nullable.iconX2Url,physicalgraph.app.SmartAppVersion.iconX2Url.nullable.java.lang.String,physicalgraph.app.SmartAppVersion.iconX2Url.nullable,smartAppVersion.iconX2Url.nullable.physicalgraph.app.SmartAppVersion.iconX2Url,smartAppVersion.iconX2Url.nullable.iconX2Url,smartAppVersion.iconX2Url.nullable.java.lang.String,smartAppVersion.iconX2Url.nullable,nullable.physicalgraph.app.SmartAppVersion.iconX2Url,nullable.iconX2Url,nullable.java.lang.String,nullable]; arguments [iconX2Url,class physicalgraph.app.SmartAppVersion]; default message [{0} cannot be null]

Thanks for your help!

FYI - I just tried pasting the code in section by section and I still get the error

@AdamV 'll look at that later today. I won’t be at a computer for several more hours.

Maybe I’ll create an account on get hub so it’s pasted clearly.