This should be an easy one, but I am getting stuck and I am getting stuck on the UTC offset.
This is my goal: When it gets cloudy and/or rainy outside, I would like certain lights my house to come on. If I use an illuminance handler to trigger this it should be easy, but for the fact that the sunsets (and it gets dark before the sunset).
For example, I do not want the lights going on each day an hour before sunset because the illuminance drops, but I do want the lights to go on at 11:30am if it is pouring rain. In essence, I have to use the time of day as a buffer between when (and when not) to turn on the lights.
I used light up the night as my starting point and then added sections for start time, end time and offset time for UTC.
In a perfect world I would prefer that the app run based on sunrise and sunset meaning I can turn it on to activate 2 hours after sunrise and 2 hours after sunset and would love help on that
I must be doing something wrong because I receive the following error…
java.lang.NullPointerException: Cannot invoke method contains() on null object @ line 88
This is where I am on the app:
/**
- Light Up The Night
- Author: SmartThings
*/
// Automatically generated. Make future change here.
definition(
name: “Cloudy and Rainy Day”,
namespace: “smartthings”,
author: “SmartThings”,
description: “Turn your lights on when it gets dark and off when it becomes light again.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet-luminance.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet-luminance@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)
preferences {
section(“Monitor the luminosity…”) {
input “lightSensor”, “capability.illuminanceMeasurement”
}
section("Time Settings"){
input "What time does this Start?", "timeOfDay_begin", title: "Begins"
input "What time does this End?", "timeOfDay_end", title: "Ends"
input "What is the UTC offset?", "timeOffset", title: "Offset"
}
section(“Turn On Switch…”) {
input “switches”, “capability.switch”, multiple: true
}
section(“Turn on Dimmers…”) {
input “dimmers”, “capability.switchLevel”, multiple: true
}
section("How bright?") {
input "level","number", title: "How bright 0-99?", required:true
}
}
def installed() {
subscribe(lightSensor, “illuminance”, illuminanceHandler)
}
def updated() {
unsubscribe()
def currTime = now()
def currTime5 = currTime + 56060*1000
def timeOfDay_begin = timeToday(timeBegin)
def timeOfDay_end = timeToday(timeEnd)
def timeOfDay_end_plus24hours = timeOfDay_end.time+ 24*60*60*1000
def timeOfDay_begin5 = timeOfDay_begin.time - 5*60*60*1000
def timeOfDay_end5 = timeOfDay_end.time - 5*60*60*1000
log.debug "currTime $currTime $currTime5"
log.debug "timeOfDay_begin.time $timeOfDay_begin.time $timeOfDay_begin5"
log.debug "timeOfDay_end.time $timeOfDay_end.time $timeOfDay_end5"
log.debug "timeOfDay_begin $timeOfDay_begin"
log.debug "timeOfDay_end $timeOfDay_end"
if(currTime >= timeOfDay_begin.time) log.debug "currTime >= timeOfDay_begin.time"
if(currTime <= timeOfDay_end.time) log.debug "currTime <= timeOfDay_end.time"
if(currTime >= timeOfDay_begin.time || currTime <= timeOfDay_end.time){
log.debug "should work"
}
if(currTime >= timeOfDay_begin5 || currTime <= timeOfDay_end5){
log.debug "555 should work $timeOffset"
}
subscribe(lightSensor, “illuminance”, illuminanceHandler)
}
// New aeon implementation
def illuminanceHandler(evt) {
def lastStatus = state.lastStatus
def currTime = now()
def currTime5 = currTime + 5*60*60*1000
def timeOfDay_begin = timeToday(timeBegin)
def timeOfDay_end = timeToday(timeEnd)
def timeOfDay_end_plus24hours = timeOfDay_end.time+ 24*60*60*1000
log.debug currTime
log.debug timeOfDay_begin.time
log.debug timeOfDay_end_plus24hours
def timeOfDay_begin_UTCoffset = timeOfDay_begin.time - timeOffset*60*60*1000
def timeOfDay_end_plus24_UTCoffset = timeOfDay_end_plus24hours - timeOffset*60*60*1000
//http://build.smartthings.com/forums/topic/comparing-current-time-with-input-time/
//if current time is equal to or after user's time
if(currTime >= timeOfDay_begin.time || currTime <= timeOfDay_end.time){ //timeOfDay_end_plus24hours){
// if(currTime5 >= timeOfDay_begin5 || currTime <= timeOfDay_end5){
if (evt.integerValue < 201) {
switches.on()
dimmers.setLevel(level)
state.lastStatus = "on"
}
else if (evt.integerValue > 201) {
switches.off()
state.lastStatus = "off"
}
}
}