Page 1 of 1

Last Day of the Month

PostPosted: Sat Jan 15, 2022 12:22 am
by jltnol
I need to have a schedule happen on the last day of the month... but am guessing this isn't possible thru the Schedule GUI, right ? In Date/Days Of The Month, I did try entering 31, 30, 29, 28 in hopes that whatever date it ran across first would make this work, but once I enter those numbers, they are automatically put back in sequence from low to high.

Re: Last Day of the Month

PostPosted: Sat Jan 15, 2022 7:38 am
by jalves
How about if you have it run at 1201 am on the first day of every month but randomized to -10 minutes?

Re: Last Day of the Month

PostPosted: Sat Jan 15, 2022 7:44 am
by DaveL17
As far as I know, there's no direct way to do it with the Indigo UI. But I think it can probably be done simply with a conditional script.

Run your schedule every day.

On the condition tab, use this Python script (in the block that says, "If Python script returns True:"):
Code: Select all
import datetime as dt
try:
    now = dt.datetime.now()
    last_dom = dt.datetime(now.year, now.month, now.day + 1)
    return False
except:
    return True

In a nutshell, this script attempts to add one day to the current date. If the current day is the last day of the month, the script will generate an error (for example, trying to create a date of 2022-01-32). If the script generates an error, it will return the value of 'True', indicating that today is the last day of the month. This will allow the schedule to run.

At least that's the idea. :D

Re: Last Day of the Month

PostPosted: Sat Jan 15, 2022 8:07 am
by CliveS
You could try setting a schedule for Day of month = 28,29,30,31 and Time at 00.01
Paste into Condition 'If Python script returns True'

Code: Select all

import calendar
from time import gmtime, strftime
lastDay = calendar.monthrange(int(strftime("%Y", gmtime())), int(strftime("%m", gmtime())))[1]
todayDay = int(strftime("%d"))
indigo.server.log(str(lastDay))    # Only required for testing
indigo.server.log(str(todayDay)) # Only required for testing
if str(todayDay) == str(lastDay):
# if str(todayDay) == str(todayDay):  #For testing - always return True
   return True
else:
   return False


Re: Last Day of the Month

PostPosted: Sat Jan 15, 2022 8:53 am
by jltnol
thanks

I'll give both of these options a try.

My problem with the 12:01 on the 1st with random is that the data in the file will all be from the previous month, but would be labeled with the current month at least sometimes. This was going to be my fall back compromise. At least Indigo would create a new file every month without my intervention, and naming the files correctly could have been easily done manually.

And I now realize that my idea of reversing the dates in the GUI wouldn't have worked either.

Re: Last Day of the Month

PostPosted: Sun Jan 16, 2022 3:14 pm
by ryanbuckner
Set your condition on a schedule run every day to fire if Python returns true. Check to see if tomorrow is in a different Month than today:

Code: Select all
import datetime

current_date = datetime.datetime.today()
nextday_date = datetime.datetime.today() + datetime.timedelta(days=1)
if (current_date.month != nextday_date.month):
    return True
else:
    return False