Current Time, Sunrise and Sunset Information on Control Page

This forum is for questions about control pages.
McIntoshBear
Posts: 29
Joined: Fri Apr 26, 2019 1:12 pm
Location: Massachusetts

Current Time, Sunrise and Sunset Information on Control Page

Post by McIntoshBear »

Hello,

Is there a way to get the Current Time, Sunrise and Sunset information shown in the Indigo Client (lower right corner) to display in a Control Page?

If there is a way I have not been able to find it or figure it out.

Thanks.
User avatar
FlyingDiver
Posts: 7305
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: Current Time, Sunrise and Sunset Information on Control

Post by FlyingDiver »

You would need to run a script on a schedule (every second?) to put those values in variables that you can display in the control page. The formatting is up to you. See https://pythonexamples.org/python-datetime-format/

Indigo makes available the calculated sunrise/sunset values for your specified location. See https://wiki.indigodomo.com/doku.php?id ... r_commands. Use the formatting tools from the first link.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
DaveL17
Posts: 6845
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Current Time, Sunrise and Sunset Information on Control

Post by DaveL17 »

This is exactly what I do. I have a Python script called Routine Variable Operations that I run once per minute. Not everything in the script is updated every minute, but my time variables are. (Some of the variables below are not for Control Pages).
Screenshot 2023-11-21 at 11.28.46 AM.png
Screenshot 2023-11-21 at 11.28.46 AM.png (37.82 KiB) Viewed 14585 times
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
McIntoshBear
Posts: 29
Joined: Fri Apr 26, 2019 1:12 pm
Location: Massachusetts

Re: Current Time, Sunrise and Sunset Information on Control

Post by McIntoshBear »

Thanks.

I have a learning curve ahead of me. I am going to have to learn Python. I guess getting 3 date-time values from the Indigo server and putting them in variables is as good a place to start as any.

First things first, I will look for an on-line Python tutorial. Does anyone have a good or preferred tutorial site where I can learn this, new to me, scripting language?

As Agatha Christie's Poirot would say ..... it will be good for the little grey cells.

I currently running Indigo , 2023.1.1, on a late 2014 Mac mini, running macOS Monterey, version 127.1. Any issues running in this environment? I am planning to get a new mac Mini in the new year.

Thank you.
User avatar
DaveL17
Posts: 6845
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Current Time, Sunrise and Sunset Information on Control

Post by DaveL17 »

Look on YouTube for a cat named Net Ninja. He's the best in the business IMO. To whet your appetite,

Code: Select all

from datetime import datetime

now          = datetime.now()
day          = f"{now:%A}"
fancy_date   = f"{now:%B %d, %Y}"
fancy_time   = f"{now:%I:%M}"
am_pm        = f"{now:%p}"

indigo.variable.updateValue(12345676, day)
indigo.variable.updateValue(12345677, fancy_date)
indigo.variable.updateValue(12345678, fancy_time)
indigo.variable.updateValue(12345679, am_pm)
The long numbers are (fake) variable IDs.
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
User avatar
DaveL17
Posts: 6845
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Current Time, Sunrise and Sunset Information on Control

Post by DaveL17 »

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
jltnol
Posts: 1009
Joined: Tue Oct 15, 2013 11:11 pm

Re: Current Time, Sunrise and Sunset Information on Control

Post by jltnol »

And there is a slightly different way to manage the time. There is a Clock Display plugin for Indigo. You create a Device, and it basically does the rest. You can put the data form your clock Device on a page easily enough, but it doesn't do the seconds perfectly, just due to the what the plugin is written I guess.

But if having the exact second isn't such a big deal, check out the Clock Display plugin.

AND it also has sunrise /sunset as well, so you should be all set to gather this date from your clock device and put it in a web page.

I can't say its as accurate to the nano-second as the python method would be, but mostly like it'll be good enough...

Don't hesitate to ask if you need help getting this info onto a webpage.

In the plugin settings, you can stipulate how you'd like the Sunrise/Sunset time displayed. This is what I use:
%-I:%M %p, which gives me 6:32 AM and 5:02 PM (at least for today)

You'll also find the attached file very helpful in understanding the codes Python uses for day, date, and time.
McIntoshBear
Posts: 29
Joined: Fri Apr 26, 2019 1:12 pm
Location: Massachusetts

Re: Current Time, Sunrise and Sunset Information on Control

Post by McIntoshBear »

Thank you DaveL17, jltnol and FlyingDiver. :)

The Clock Display plug in has done the trick for the short term. To get up to speed and build something useful in Python will take a while for this 78 yo.

My previous home automation server (used for 20+ years) had if - then - else logic built in. That is the thing I miss the most in Indigo.

If I learn Python I suspect I can add conditional actions in schedules and triggers.

I want to thank each of you for responding to my question.

I'm off and running .... slowly.
User avatar
DaveL17
Posts: 6845
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Current Time, Sunrise and Sunset Information on Control

Post by DaveL17 »

I didn't even know about the Clock Display plugin. Glad to hear that works for you.

As far as if - then - else logic, once you get the hang of some simple Python commands, this is very easy to do given how Python integration is baked into Indigo. Say you have a schedule that you only want to run if a certain condition is true ( everything to the right of a "#" is a comment, and ignored by Python).

Code: Select all

my_var = indigo.variables[12345678]  # this is how you reference an Indigo Variable -- by its ID (or its name, although that's discouraged).
my_test = my_var.value               # Get the value of my_var (Indigo variables always contain a text string).  Let's say here it's "20".
my_test = int(my_test)               # Convert the text string to an integer.

if my_test > 10:                     # Since 20 > 10, this "if" will be executed
    return True                      # Return the value True
else:
    return False                     # You don't have to do this, but it's nice to be thorough.
This code goes into the Condition tab of the schedule, in the lower box that says, "If Python script returns True".

It may seem like a lot at first, but once you get the hang of it, it's really pretty straightforward.
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
jltnol
Posts: 1009
Joined: Tue Oct 15, 2013 11:11 pm

Re: Current Time, Sunrise and Sunset Information on Control

Post by jltnol »

And just to echo Dave's comments on Python, I knew nothing when I started, and still feel like I'm in Python Kindergarten, BUT the folks here, Dave being one of them, have ALWAYS been helpful in helping me solve scripting problems when I get stuck.

My advice is Don't Be Afraid to try some basic ideas in Python.
User avatar
DaveL17
Posts: 6845
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Current Time, Sunrise and Sunset Information on Control

Post by DaveL17 »

When I came over to Indigo, I didn't even know Python existed. But I knew Lua existed and I wanted no part of that.
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
User avatar
DaveL17
Posts: 6845
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Current Time, Sunrise and Sunset Information on Control

Post by DaveL17 »

Incidentally, I just stumbled across another free option for Python learning.

Harvard University has placed their Introduction to Programming with Python course on Open Courseware (tuition free).
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
McIntoshBear
Posts: 29
Joined: Fri Apr 26, 2019 1:12 pm
Location: Massachusetts

Re: Current Time, Sunrise and Sunset Information on Control

Post by McIntoshBear »

Thank you DaveL17.

Harvard is about a half hour away from my home. This is definitely on to do list in the New Year.

Thanks again.
User avatar
DaveL17
Posts: 6845
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Current Time, Sunrise and Sunset Information on Control

Post by DaveL17 »

You're welcome. I hope you find it useful.
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
Post Reply

Return to “Control Pages”