Location.dusk\dawn

Hi All,

Since 20th Dec my dusk\dawn automation is broken. I finally checked it out and found that these methods that I wrote years ago always returns 20th Dec, not the current day:

def getSunrise() {
Date sunrise = readDate(location.currentValue(“sunriseTime”), “yyyy-MM-dd’T’HH:mm:ss.SSS’Z’”)
return sunrise
}

def getSunset() {
Date dusk = readDate(location.currentValue(“sunsetTime”), “yyyy-MM-dd’T’HH:mm:ss.SSS’Z’”)
return dusk
}

Does anyone know what’s changed and how I fix it?

Thanks!

Tagging @nayelyz

If you look at your Installed SmartApps in the IDE, do you still have Weather Station running? It used to come under Hello Home! but should now be under Smart Lighting.

Hey @taasss, can you share the SmartApp source code, please?

The app is 1,800 lines of code that will be hard to understand, but I can post if you like.

Here’s an abridged version of what I’m doing:

def go() {
def dawn = generateDate(getSunrise(), 30)

runOnce(dawn, “handleDuskDawn”)
}

def getSunset() {
Date dusk = readDate(location.currentValue(“sunsetTime”), “yyyy-MM-dd’T’HH:mm:ss.SSS’Z’”)
return dusk
}

def generateDate(Date time, minsOffset) {
Date timeBeforeTime = new Date(time.time + (minsOffset.toInteger() * 60 * 1000))

if (timeBeforeTime < new Date())
{
    timeBeforeTime = timeBeforeTime + 1;
}

return timeBeforeTime

}

What I really need is a new way to get dusk\dawn, then I can rewrite the method…

@orangebucket - Yes I did used to have it, but deleted it after selling my Netatmo. Is that how this property got set?

Yes, it sets the location sunrise, sunset, sunsetTime and sunriseTime attributes used by legacy apps. Not to be confused with any other app of the same name.

I believe it gets created automatically if you create a Smart Lighting automation using sunrise and sunset, so hopefully that allows it to be recreated if deliberately deleted.

What @orangebucket said helps (thanks BTW), you can use a virtual device in the Smart Lightning app if you don’t want to use a real one. I don’t know how complex is your SmartApp automation, but you can also use the Rules API to trigger some actions with sunrise, sunset, etc.