Page 1 of 2

display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 4:31 pm
by Professor Falken
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.

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 5:55 pm
by jay (support)
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.

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 6:48 pm
by Professor Falken
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.

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 6:58 pm
by DaveL17
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

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 7:10 pm
by Professor Falken
That worked like a charm. Thanks to both of you.

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 8:10 pm
by Professor Falken
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.

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 8:39 pm
by DaveL17
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.

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 8:51 pm
by Professor Falken
You were exactly right, and that works perfectly. Thanks a lot.

Re: display "next execution" of schedule items?

PostPosted: Tue May 23, 2017 8:55 pm
by DaveL17
Professor Falken wrote:
You were exactly right, and that works perfectly. Thanks a lot.

Sweet. Glad I could help.

Re: display "next execution" of schedule items?

PostPosted: Wed May 24, 2017 8:22 am
by jay (support)
Sorry, yeah, a typo in the script. I've fixed it above in case someone else finds the script useful.

Re: display "next execution" of schedule items?

PostPosted: Wed May 24, 2017 12:13 pm
by Professor Falken
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").

Re: display "next execution" of schedule items?

PostPosted: Tue May 30, 2017 6:02 pm
by Professor Falken
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

Re: display "next execution" of schedule items?

PostPosted: Tue May 30, 2017 6:34 pm
by DaveL17
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').

Re: display "next execution" of schedule items?

PostPosted: Tue May 30, 2017 6:50 pm
by johnfdl
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?

Re: display "next execution" of schedule items?

PostPosted: Tue May 30, 2017 8:02 pm
by DaveL17
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.