Setting a variable for the season or a couple of months

Posted on
Sat Aug 20, 2022 12:48 pm
tazswe offline
Posts: 211
Joined: Mar 13, 2017
Location: Sweden

Setting a variable for the season or a couple of months

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.

Posted on
Sat Aug 20, 2022 4:24 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Setting a variable for the season or a couple of months

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

Posted on
Sun Oct 16, 2022 5:36 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

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

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))



Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest