Page 1 of 1

Setting a variable for the season or a couple of months

PostPosted: Sat Aug 20, 2022 12:48 pm
by tazswe
Up in the north we have long warm days during summer and short cold during winther .
This will influence both ypur outdoor activities and the length of the sunrise and sunset.

I am not sure how to set a variable for ex june-aug to summer and dec-feb to winther.

Setting a variable for the season or a couple of months

PostPosted: Sat Aug 20, 2022 4:24 pm
by howartp
You’d need a few triggers - first day of each ‘season’, ie June, September, December, March.

Have them each set the value of your variable to some text value.


Sent from my iPad using Tapatalk Pro

Re: Setting a variable for the season or a couple of months

PostPosted: Sun Oct 16, 2022 5:36 pm
by ryanbuckner
Here's what I use in a schedule that runs every day at 12:01AM :

Code: Select all

#!/usr/bin/env python
from datetime import date, datetime

Y = 2000 # dummy leap year to allow input X-02-29 (leap day)
seasons = [('winter', (date(Y,  1,  1),  date(Y,  3, 20))),
           ('Spring', (date(Y,  3, 21),  date(Y,  6, 20))),
           ('Summer', (date(Y,  6, 21),  date(Y,  9, 22))),
           ('Fall', (date(Y,  9, 23),  date(Y, 12, 20))),
           ('winter', (date(Y, 12, 21),  date(Y, 12, 31)))]

def get_season(now):
    if isinstance(now, datetime):
        now = now.date()
    now = now.replace(year=Y)
    return next(season for season, (start, end) in seasons
                if start <= now <= end)

strSeason = get_season(date.today())
indigo.variable.updateValue(921811727, str.title(strSeason))