Show Sunrise/Sunset time on Control Page [Solved]

Posted on
Fri Feb 12, 2016 5:27 pm
jalves offline
Posts: 744
Joined: Jun 16, 2013

Show Sunrise/Sunset time on Control Page [Solved]

Just for fun I'd like to be able to show the current sunrise and sunset times on a control page. I see that Indigo has that information, but I can't seem to find a way to show it on a control page. I was going to put it into a variable, but I also can't figure out how to access the sunrise/sunset time. Am I missing something obvious?
Last edited by jalves on Fri Feb 12, 2016 5:42 pm, edited 1 time in total.

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Fri Feb 12, 2016 5:42 pm
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Show Sunrise/Sunset time on Control Page

Never mind. Found my answer in a previous post here. Solution is to run this script:

tell application "IndigoServer"

set value of variable "sunrise" to "Sunrise: " & (weekday of (calculate sunrise) as string) & " " & (time string of (calculate sunrise) as string)


set value of variable "sunset" to "Sunset: " & (weekday of (calculate sunset) as string) & " " & (time string of (calculate sunset) as string)

end tell

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Fri Jun 14, 2019 5:43 am
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Show Sunrise/Sunset time on Control Page [Solved]

Yes, I've always used something similar to do the same. Such a simple thing with AppleScript. But how to fill "sunset" and "sunrise" variables using Python? I figured out how to fill my "date" variable:

# sets variable date to current date

# import
from datetime import datetime

# get the current date
tCurrentDate = datetime.now()

# convert date to desired format and set variable
indigo.variable.updateValue(1554385019, value=("Date: " + tCurrentDate.strftime("%a, %b %d, %Y"))) # "date"

Posted on
Fri Jun 14, 2019 5:53 am
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Show Sunrise/Sunset time on Control Page [Solved]

Scratch that. Found it elsewhere:

from datetime import datetime
sunrise = indigo.server.calculateSunrise()
indigo.variable.updateValue(1728448011, value=datetime.strftime(sunrise, "%-I:%M"))
sunset = indigo.server.calculateSunset()
indigo.variable.updateValue(3027629, value=datetime.strftime(sunset, "%-I:%M"))

Posted on
Fri Jun 14, 2019 5:54 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Show Sunrise/Sunset time on Control Page [Solved]


Posted on
Fri Jun 14, 2019 5:55 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Show Sunrise/Sunset time on Control Page [Solved]

OK :D

Posted on
Fri Jun 14, 2019 6:00 am
racarter offline
User avatar
Posts: 468
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Show Sunrise/Sunset time on Control Page [Solved]

If you'd like some snazzy icons with the sunrise/sunset times, try this:

Code: Select all
sun = u'\u2600 '.encode('utf-8')
moon = u'\u263E '.encode('utf-8')
nextSunrise = indigo.server.calculateSunrise()
indigo.variable.updateValue(<sunrise variable ID>, value=sun+nextSunrise.strftime("%H:%M"))
nextSunset = indigo.server.calculateSunset()
indigo.variable.updateValue(<sunset variable ID>, value= moon+nextSunset.strftime("%H:%M"))

Posted on
Fri Jun 14, 2019 12:44 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Show Sunrise/Sunset time on Control Page [Solved]

Thanks all! I'll be bach!! I'm converting years of AppleScript to Python. Well, some of it. I'm using this opportunity to rid my system of code I don't really use all that much. "Less is more" is the new mantra!!

While I don't support Indigo's decision to dump AppleScript, I think I understand it, in part anyway. While I wish AppleScript was being supported by all developers, one can't really expect them all to stay onboard a train from which the engineer (Apple) has jumped off... :?

Posted on
Fri Jun 14, 2019 3:46 pm
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Show Sunrise/Sunset time on Control Page [Solved]

Rather than deal with scripts, I've moved on to simply utilizing the Clock Display plugin. Sunrise and sunset are one of the values this plugin provides when you create a new device.

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Fri Jun 14, 2019 10:44 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Show Sunrise/Sunset time on Control Page [Solved]

Nice.

Poor cat, lots of ways to skin it! :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests