Increment Date Using a Varaible and Python Script

Posted on
Sun Mar 15, 2020 4:00 pm
HEGarrard offline
Posts: 40
Joined: Sep 09, 2014

Increment Date Using a Varaible and Python Script

I am trying to figure out how I can take a date, stored as a variable and increment it by 1 day using a python script. I assume the date is being stored as a string and not a "date"

Background ...
What I am trying to accomplish involves using the Indigo app on my iPhone or iPad to set a START DATE and END DATE for a Heating and Air Conditioning schedule on the upper floor of my home, when I know I have someone staying upstairs. Adding the START TIME AND END TIME are options as well.

So I have created a control page where I can select TODAY and using a python script insert today's date into a variable named START_DATE. I then have a "+DAY" and "-DAY" to be able to increase the date by one day (or decrease if I hit the +DAY one too many times).

I am having issues trying to figure out how to "read" the variable START_DATE, convert it back to a date that python can then increment by 1 day.

To set variable to TODAY is use ...

Code: Select all
from datetime import date
indigo.variable.updateValue(1193981403, date.today().strftime("%Y-%m-%d")) 

To increment the date by 1 day ... this is what I would want to do - using the timedelta function.
I am assuming the reason it fails is because the variable is a string and not a date value.

Code: Select all
from datetime import timedelta
target_date = (indigo.variables[1193981403].value)
target_date = target_date + timedelta(days=1)
indigo.variable.updateValue(1193981403, value=str(target_date))

I have searched various websites trying to find a way to convert a string to a date.

Any ideas?

Thanks!

Posted on
Sun Mar 15, 2020 7:58 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Increment Date Using a Varaible and Python Script


Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Mar 15, 2020 8:14 pm
HEGarrard offline
Posts: 40
Joined: Sep 09, 2014

Re: Increment Date Using a Varaible and Python Script

Thank you Jay!

I am not sure why my searches over the past couple of days did not find this jewel!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests