Current Time, Sunrise and Sunset Information on Control Page

Posted on
Tue Nov 21, 2023 8:56 am
McIntoshBear offline
Posts: 29
Joined: Apr 26, 2019
Location: Massachusetts

Current Time, Sunrise and Sunset Information on Control Page

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.

Posted on
Tue Nov 21, 2023 9:16 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Current Time, Sunrise and Sunset Information on Control

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

Posted on
Tue Nov 21, 2023 11:34 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Current Time, Sunrise and Sunset Information on Control

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 13923 times

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

[My Plugins] - [My Forums]

Posted on
Tue Nov 21, 2023 12:43 pm
McIntoshBear offline
Posts: 29
Joined: Apr 26, 2019
Location: Massachusetts

Re: Current Time, Sunrise and Sunset Information on Control

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.

Posted on
Tue Nov 21, 2023 12:54 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Current Time, Sunrise and Sunset Information on Control

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]

Posted on
Tue Nov 21, 2023 1:02 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Current Time, Sunrise and Sunset Information on Control


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

[My Plugins] - [My Forums]

Posted on
Tue Nov 21, 2023 3:25 pm
jltnol offline
Posts: 994
Joined: Oct 15, 2013

Re: Current Time, Sunrise and Sunset Information on Control

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.

Posted on
Tue Nov 21, 2023 9:48 pm
McIntoshBear offline
Posts: 29
Joined: Apr 26, 2019
Location: Massachusetts

Re: Current Time, Sunrise and Sunset Information on Control

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.

Posted on
Wed Nov 22, 2023 6:39 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Current Time, Sunrise and Sunset Information on Control

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]

Posted on
Wed Nov 22, 2023 4:36 pm
jltnol offline
Posts: 994
Joined: Oct 15, 2013

Re: Current Time, Sunrise and Sunset Information on Control

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.

Posted on
Wed Nov 22, 2023 4:50 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Current Time, Sunrise and Sunset Information on Control

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]

Posted on
Sun Dec 03, 2023 7:52 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Current Time, Sunrise and Sunset Information on Control

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]

Posted on
Sun Dec 03, 2023 10:13 pm
McIntoshBear offline
Posts: 29
Joined: Apr 26, 2019
Location: Massachusetts

Re: Current Time, Sunrise and Sunset Information on Control

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.

Posted on
Mon Dec 04, 2023 5:39 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Current Time, Sunrise and Sunset Information on Control

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]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 9 guests