Quick way to check for sunrise/sunset


Going to ask if there was a quick way to check for sunrise/sunset times without having to code for zip code and all…

Found the answer before posting and thought this might help some other newbies like me!

Turns out

getSunriseAndSunset().sunrise.time and getSunriseAndSunset().sunset.time will return the sunrise and sunset times at the hub location… so now all I had to do was

private isItNight(){
           if(getSunriseAndSunset().sunrise.time < now() || 
                 getSunriseAndSunset().sunset.time > now()){
            	return true
            else {
            	return false

Hope this helps someone!


Thank you for the help.

Thanks - code snippets like this are really useful!

Hopefully someone has the time to find/organize them all and make a nice wiki page.

1 Like