display "next execution" of schedule items?

Posted on
Tue May 23, 2017 4:31 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

display "next execution" of schedule items?

There is a column on the schedule pane that shows the next execution of each schedule item. Is there a way to call this info and, say, pass it to a variable which could then be displayed on a control page?

Use case:
I'd like to show when timed lights are scheduled to next go on or off.

I could write some multi-step logic, using several variables and the Wunderground Astronomical plugin sunrise/sunset device states, but that could become unwieldy pretty quickly (hours and minutes are reported separately, and most of my schedules are a little off the actual sunrise/sunset, meaning I'd have to do some math on the device state, and account for crossing the 0 or 60 minute mark). It would be much easier to just use the "next execution", which Indigo seems to already know anyway.

Thanks.

Posted on
Tue May 23, 2017 5:55 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: display "next execution" of schedule items?

You can get the next scheduled execution of any schedule using a Python script:

Code: Select all
s = indigo.schedules[987654321] # some schedule ID
indigo.variable.updateValue(1234567, value="{:%H:%M}".format(s.nextExecution)) # some variable ID


So, run that script as often as you want the time to be updated in the variable (once a minute perhaps). You can use the standard date/time specifiers provided by Python to format the value in the variable to whatever you want.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue May 23, 2017 6:48 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: display "next execution" of schedule items?

Thanks for the quick response Jay. I can see this having several uses actually.

I defined a new variable, and filled in that new variable ID and the schedule ID into the script you posted. Unfortunately, I am getting this error when I test it:

Script Error embedded script: 'VariableList' object has no attribute 'updateValue'
Script Error Exception Traceback (most recent call shown last):

embedded script, line 2, at top level
AttributeError: 'VariableList' object has no attribute 'updateValue'


Thanks.

Posted on
Tue May 23, 2017 6:58 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: display "next execution" of schedule items?

Professor Falken wrote:
Thanks for the quick response Jay. I can see this having several uses actually.

I defined a new variable, and filled in that new variable ID and the schedule ID into the script you posted. Unfortunately, I am getting this error when I test it:

Script Error embedded script: 'VariableList' object has no attribute 'updateValue'
Script Error Exception Traceback (most recent call shown last):

embedded script, line 2, at top level
AttributeError: 'VariableList' object has no attribute 'updateValue'


Thanks.

Change 'variables' on line 2 to 'variable'.

Code: Select all
s = indigo.schedules[702639074] # some schedule ID
indigo.variable.updateValue(283709108, value="{:%H:%M}".format(s.nextExecution)) # some variable ID

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

[My Plugins] - [My Forums]

Posted on
Tue May 23, 2017 7:10 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: display "next execution" of schedule items?

That worked like a charm. Thanks to both of you.

Posted on
Tue May 23, 2017 8:10 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: display "next execution" of schedule items?

Dave,

Any idea how I could alter this to remove the leading 0 on hours 1-9?

I see there is a python command str.lstrip('0') which I think is designed to do that, but I can't seem to get it to work right.

Posted on
Tue May 23, 2017 8:39 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: display "next execution" of schedule items?

Professor Falken wrote:
Dave,

Any idea how I could alter this to remove the leading 0 on hours 1-9?

I see there is a python command str.lstrip('0') which I think is designed to do that, but I can't seem to get it to work right.

My guess is that you're probably trying to strip a numeric zero instead of a string zero. I broke this down a bit to make the steps more obvious, but you don't have to do it so incrementally.

Code: Select all
s = indigo.schedules[702639074] # some schedule ID
v = "{:%H:%M}".format(s.nextExecution)  # This formats a datetime object as a string
v2 = v.lstrip('0')  # Strip a _string_ zero
indigo.variable.updateValue(283709108, value=v2) # some variable ID


ETA: I see you have a string zero in your post, I'm just guessing that you're trying to strip a numeric zero because this lstrip works perfectly for me.

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

[My Plugins] - [My Forums]

Posted on
Tue May 23, 2017 8:51 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: display "next execution" of schedule items?

You were exactly right, and that works perfectly. Thanks a lot.

Posted on
Tue May 23, 2017 8:55 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: display "next execution" of schedule items?

Professor Falken wrote:
You were exactly right, and that works perfectly. Thanks a lot.

Sweet. Glad I could help.

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

[My Plugins] - [My Forums]

Posted on
Wed May 24, 2017 8:22 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: display "next execution" of schedule items?

Sorry, yeah, a typo in the script. I've fixed it above in case someone else finds the script useful.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed May 24, 2017 12:13 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: display "next execution" of schedule items?

Yes, I could see a few applications where I could use this script. Thanks.

I also really appreciate Dave helping me drop the leading zeros from the hour. Next I may see if I can adapt his trick for date displays ("Friday June 2, 2017" looks much better than "Friday June 02, 2017").

Posted on
Tue May 30, 2017 6:02 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: display "next execution" of schedule items?

Dropping back by here in case anyone else finds this string later also looking to strip leading zeros off of single digit days and/or hours ("May 3" instead of "May 03", or "5:45 pm" instead of "05:45 pm") as I was. Dave's script above works, but it turns out there is a way to do it right from the date formatting.

I found this more robust list of date/time formats, and it includes options for both of those (%e and %l, respectively). These do seem to be working in Indigo. The one for lowercase am/pm (ironically the uppercase %P) doesn't work for me. I haven't tested any of the other ones on this list.

https://linux.die.net/man/3/strftime

Posted on
Tue May 30, 2017 6:34 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: display "next execution" of schedule items?

Yes, that's right. Here's an example of the whole thing:

Code: Select all
s = indigo.schedules[702639074] # some schedule ID
indigo.variable.updateValue(283709108, value="{:%A %B %e, %Y %l:%M}".format(s.nextExecution)) # some variable ID

Note that the fifth parameter is a lower case el ('L').

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

[My Plugins] - [My Forums]

Posted on
Tue May 30, 2017 6:50 pm
johnfdl offline
Posts: 177
Joined: May 18, 2017
Location: Atlanta, GA USA

Re: display "next execution" of schedule items?

DaveL17 wrote:
Yes, that's right. Here's an example of the whole thing:

Code: Select all
s = indigo.schedules[702639074] # some schedule ID
indigo.variable.updateValue(283709108, value="{:%A %B %e, %Y %l:%M}".format(s.nextExecution)) # some variable ID

Note that the fifth parameter is a lower case el ('L').

So I assume the 283709108 is the ID for the variable where we are storing the next scheduled execution, but where are we getting the 702639074 from?

Posted on
Tue May 30, 2017 8:02 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: display "next execution" of schedule items?

johnfdl wrote:
So I assume the 283709108 is the ID for the variable where we are storing the next scheduled execution, but where are we getting the 702639074 from?

702639074 is the Indigo ID of the schedule that we want to query for its next execution time.

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

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 2 guests