Sunrise/Sunset SmartApp stopped working

I started using the “Sunrise/Sunset” SmartApp written by SmartThings that’s in the official templates. I used it for 3-4 weeks with no issues but about 4-5 days ago, it stopped triggering for both sunrise and sunset. Any idea what happened? I even rebooted my hub just in case, but no changes. See the code below.




  • Copyright 2015 SmartThings
  • 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:
  • 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.
  • Sunrise, Sunset
  • Author: SmartThings
  • Date: 2013-04-30
    name: “Sunrise/Sunset”,
    namespace: “smartthings”,
    author: “SmartThings”,
    description: “Changes mode and controls lights based on local sunrise and sunset times.”,
    category: “Mode Magic”,
    iconUrl: “”,
    iconX2Url: “

preferences {
section (“At sunrise…”) {
input “sunriseMode”, “mode”, title: “Change mode to?”, required: false
input “sunriseOn”, “capability.switch”, title: “Turn on?”, required: false, multiple: true
input “sunriseOff”, “capability.switch”, title: “Turn off?”, required: false, multiple: true
section (“At sunset…”) {
input “sunsetMode”, “mode”, title: “Change mode to?”, required: false
input “sunsetOn”, “capability.switch”, title: “Turn on?”, required: false, multiple: true
input “sunsetOff”, “capability.switch”, title: “Turn off?”, required: false, multiple: true
section (“Sunrise offset (optional)…”) {
input “sunriseOffsetValue”, “text”, title: “HH:MM”, required: false
input “sunriseOffsetDir”, “enum”, title: “Before or After”, required: false, options: [“Before”,“After”]
section (“Sunset offset (optional)…”) {
input “sunsetOffsetValue”, “text”, title: “HH:MM”, required: false
input “sunsetOffsetDir”, “enum”, title: “Before or After”, required: false, options: [“Before”,“After”]
section (“Zip code (optional, defaults to location coordinates)…”) {
input “zipCode”, “text”, required: false
section( “Notifications” ) {
input(“recipients”, “contact”, title: “Send notifications to”) {
input “sendPushMessage”, “enum”, title: “Send a push notification?”, options: [“Yes”, “No”], required: false
input “phoneNumber”, “phone”, title: “Send a text message?”, required: false


def installed() {

def updated() {
//unschedule handled in astroCheck method

def initialize() {
subscribe(location, “position”, locationPositionChange)
subscribe(location, “sunriseTime”, sunriseSunsetTimeHandler)
subscribe(location, “sunsetTime”, sunriseSunsetTimeHandler)



def locationPositionChange(evt) {
log.trace "locationChange()"

def sunriseSunsetTimeHandler(evt) {
log.trace "sunriseSunsetTimeHandler()"

def astroCheck() {
def s = getSunriseAndSunset(zipCode: zipCode, sunriseOffset: sunriseOffset, sunsetOffset: sunsetOffset)

def now = new Date()
def riseTime = s.sunrise
def setTime = s.sunset
log.debug "riseTime: $riseTime"
log.debug "setTime: $setTime"

if (state.riseTime != riseTime.time) {

	if(riseTime.before(now)) {
		riseTime =

	state.riseTime = riseTime.time "scheduling sunrise handler for $riseTime"
	schedule(riseTime, sunriseHandler)

if (state.setTime != setTime.time) {

    if(setTime.before(now)) {
	    setTime =

	state.setTime = setTime.time "scheduling sunset handler for $setTime"
    schedule(setTime, sunsetHandler)


def sunriseHandler() { "Executing sunrise handler"
if (sunriseOn) {
if (sunriseOff) {

def sunsetHandler() { "Executing sunset handler"
if (sunsetOn) {
if (sunsetOff) {

def changeMode(newMode) {
if (newMode && location.mode != newMode) {
if (location.modes?.find{ == newMode}) {
send “${label} has changed the mode to ‘${newMode}’”
else {
send “${label} tried to change to undefined mode ‘${newMode}’”

private send(msg) {
if (location.contactBookEnabled) {
log.debug(“sending notifications to: ${recipients?.size()}”)
sendNotificationToContacts(msg, recipients)
else {
if (sendPushMessage != “No”) {
log.debug(“sending push message”)

    if (phoneNumber) {
        log.debug("sending text message")
        sendSms(phoneNumber, msg)

log.debug msg


private getLabel() {
app.label ?: “SmartThings”

private getSunriseOffset() {
sunriseOffsetValue ? (sunriseOffsetDir == “Before” ? “-$sunriseOffsetValue” : sunriseOffsetValue) : null

private getSunsetOffset() {
sunsetOffsetValue ? (sunsetOffsetDir == “Before” ? “-$sunsetOffsetValue” : sunsetOffsetValue) : null

Why are you using this SmartApp instead of Smart Lighting? I think you’ll find Smart Lighting to work much better for you.

1 Like


I want to use some baseline code which I could then modify. Smart Lights was not in the new SmartApp templates. Where can I find the code for that?



Hi @TexasFlyer,

You won’t find Smart Lighting as a template unfortunately. That’s probably considered “core” ST, like Smart Home Monitor, so it’s unlikely that code will end up in a template.

Out of curiosity, have you tried Smart Lighting to see if it will do what you need? If it doesn’t, I bet CoRE will. I’ve pretty much done away with most of my own SmartApps now that Smart Lighting, SHM, and especially CoRE can do them.

Check to see if your sunrise/sunset times have been updating properly:

Log in to, click Locations, click List Events, then click the “From Location” filter.

You should be looking at something like this:

If you see that you got a sunriseTime and a sunsetTime for today, then I’ll need to confirm if something changed on our end.

If you don’t see that, however, go back to the Location level and click “List SmartApps”.

Scroll down and find “Weather Station” and hit “Update”:

Then go back to see if you pulled tomorrows sunrise/sunset times.



I checked and found sunset, sunsetTime, sunrise, and sunriseTime triggered today. See the below:

I’m having a problem with sunrise/sunset, i’m using the Smart lighting app at its most basic but it doesnt fire on sunrise or sunset. I dont have any sunrise/sunset events in the log and when i click UPDATE against weather station it doesnt do anything.

any ideas?

I’m on HUB2 and it seems to be quite buggy, i get lots of errors in the android gui when i try and save things, maybe it needs a full reset?

UPDATE: I reset the hub (removed location) and started over again, i now have sunrise and sunset events

1 Like