Daylight switch season based

Posted on
Thu Oct 03, 2019 9:00 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Daylight switch season based

You're might be introducing bogus characters. When someone posts sample code in a CODE block, click on the "Select all" link, then command-c to copy, then switch to Indigo, and command-v. Don't do anything else. Don't try to select the code manually.

The errors you're getting might be valid. I'm post code samples, but I'm not testing them myself. Can't do that without setting up all the variables. So it's possible the samples might have errors in them. So post the EXACT message you get, maybe with a cropped screen grab of the dialog box.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Oct 03, 2019 9:06 am
mroest offline
Posts: 25
Joined: Feb 01, 2017

Re: Daylight switch season based

Thank you so much.
When i paste the scripts it gives an error:

embedded script: 'unicode ' object is not callable

any idea?

FlyingDiver wrote:
I broke this into two sections for readability, but it should all be one script.

See https://docs.python.org/2/library/datetime.html for the use of the formatting strings to get day/date/month/etc strings.

Code: Select all
    -- Set strDay to current weekday
    set value of variable "strDay" to weekday of dteCurDateTime as string
    log "Update variable strDay to " & value of variable "strDay" using type "Schedule: SetDateTimeVariables"
   
    -- Set strMonth to current month
    set value of variable "strMonth" to month of dteCurDateTime as string
    log "Update variable strMonth to " & value of variable "strMonth" using type "SSchedule: etDateTimeVariables"
   
    set value of variable "intMonth" to month of dteCurDateTime as number
    log "Update variable intMonth to " & value of variable "intMonth" using type "Schedule: SetDateTimeVariables"
   
    --Set strSeason based on month
    if {"1", "2", "3"} contains value of variable "intMonth" then
       set value of variable "strSeason" to "Winter"
       
    else if {"4", "5", "6"} contains value of variable "intMonth" then
       set value of variable "strSeason" to "Spring"
       
    else if {"7", "8", "9"} contains value of variable "intMonth" then
       set value of variable "strSeason" to "Summer"
       
    else if {"10", "11", "12"} contains value of variable "intMonth" then
       set value of variable "strSeason" to "Autumn"
       
    end if
    log "Update variable strSeason to " & value of variable "strSeason" using type "Schedule: SetDateTimeVariables"


Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from datetime import date
today = date.today()
indigo.variable.updateValue("strDay", today.strftime("%A"))
indigo.variable.updateValue("strMonth", today.strftime("%B"))
indigo.variable.updateValue("intMonth", today.strftime("%m"))
if today.month() in [1, 2, 3]:
    indigo.variable.updateValue("strSeason", "Winter")
elif today.month() in [4, 5, 6]:
    indigo.variable.updateValue("strSeason", "Spring")
elif today.month() in [7, 8, 9]:
    indigo.variable.updateValue("strSeason", "Summer")
elif today.month() in [10, 11, 12]:
    indigo.variable.updateValue("strSeason", "Autumn")


Code: Select all
    --Set strDayType based on strDay
    if value of variable "intOverride" > 0 then
       -- set day to value of variable "strOverride" and reduce variable by 1
       set value of variable "strDayType" to value of variable "strOverride"
       set value of variable "intOverride" to (value of variable "intOverride") - 1
    else
       -- determine daytype regular
       if {"Monday", "Tuesday"} contains value of variable "strDay" then
          set value of variable "strDayType" to "werk"
         
       else if {"Wednesday"} contains value of variable "strDay" then
          set value of variable "strDayType" to "thuiswerk"
         
       else if {"Thursday", "Friday"} contains value of variable "strDay" then
          set value of variable "strDayType" to "thuis"
         
       else
          set value of variable "strDayType" to "vrij"
         
       end if
    end if
    log "Update variable strDayType to " & value of variable "strDayType" using type "Schedule: SetDateTimeVariables"


Code: Select all
intOverride = indigo.variables['intOverride'].value(int)
if intOverride > 0:
    indigo.variable.updateValue("strDayType", indigo.variables['strOverride'].value)
    indigo.variable.updateValue("intOverride", str(intOverride - 1))

else:
    if indigo.variables['strDay'].value in ['Monday', 'Tuesday']:
        indigo.variable.updateValue("strDayType", "werk")
    elif indigo.variables['strDay'].value in ['Wednesday']:
        indigo.variable.updateValue("strDayType", "thuiswerk")
    elif indigo.variables['strDay'].value in ['Thursday', 'Friday']:
        indigo.variable.updateValue("strDayType", "thuis")
    else:
        indigo.variable.updateValue("strDayType", "vrij")

Posted on
Thu Oct 03, 2019 9:15 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Daylight switch season based

mroest wrote:
Thank you so much.
When i paste the scripts it gives an error:

embedded script: 'unicode ' object is not callable

any idea?


Not really. No line number? No highlighting? Just that single error? Look in the Log window, not just the script editor.

If there's nothing else, try copying the entire script into the scripting shell (under the Plugins menu) and see if it gives a more error detail.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Oct 03, 2019 9:17 am
mroest offline
Posts: 25
Joined: Feb 01, 2017

Re: Daylight switch season based

I copied from my windows laptop. now do it from apple..

With this script
Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from datetime import date
today = date.today()
indigo.variable.updateValue("strDay", today.strftime("%A"))
indigo.variable.updateValue("strMonth", today.strftime("%B"))
indigo.variable.updateValue("intMonth", today.strftime("%m"))
if today.month() in [1, 2, 3]:
    indigo.variable.updateValue("strSeason", "Winter")
elif today.month() in [4, 5, 6]:
    indigo.variable.updateValue("strSeason", "Spring")
elif today.month() in [7, 8, 9]:
    indigo.variable.updateValue("strSeason", "Summer")
elif today.month() in [10, 11, 12]:
    indigo.variable.updateValue("strSeason", "Autumn")

it highlights the row if today.month() in [1,2,3]:

and gives the error embedded script: ínt' object is not callable
Last edited by mroest on Thu Oct 03, 2019 9:25 am, edited 1 time in total.

Posted on
Thu Oct 03, 2019 9:20 am
mroest offline
Posts: 25
Joined: Feb 01, 2017

Re: Daylight switch season based

and for this script
Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
intOverride = indigo.variables['intOverride'].value(int)
if intOverride > 0:
    indigo.variable.updateValue("strDayType", indigo.variables['strOverride'].value)
    indigo.variable.updateValue("intOverride", str(intOverride - 1))

else:
    if indigo.variables['strDay'].value in ['Monday', 'Tuesday']:
        indigo.variable.updateValue("strDayType", "werk")
    elif indigo.variables['strDay'].value in ['Wednesday']:
        indigo.variable.updateValue("strDayType", "thuiswerk")
    elif indigo.variables['strDay'].value in ['Thursday', 'Friday']:
        indigo.variable.updateValue("strDayType", "thuis")
    else:
        indigo.variable.updateValue("strDayType", "vrij")

it highlights the row intoverride = ... with the error unicode object is not callable

I have to pick up my kids now so will try again later tonight...

Thanks again!

Posted on
Thu Oct 03, 2019 9:25 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Daylight switch season based

Can you PLEASE use the "Code" tags? Please?

it highlights the row if today.month() in [1,2,3]:

and gives the error embedded script: ínt' object is not callable


My bad. Change that line to:
Code: Select all
if today.month in [1, 2, 3]:


And the other one to:

Code: Select all
intOverride = indigo.variables['intOverride'].getValue(int)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Who is online

Users browsing this forum: No registered users and 1 guest