Python script: testing time an if/then condition

Posted on
Sat Oct 19, 2019 5:26 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python script: testing time an if/then condition

What is the error you're seeing?

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Oct 19, 2019 5:30 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python script: testing time an if/then condition

When I replace your variable with my email address, the script runs without error.

Are you sure that you have the Indigo Email settings configured properly?

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Oct 19, 2019 12:21 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python script: testing time an if/then condition

Code: Select all
import datetime
now = indigo.server.getTime()
now_formatted = datetime.datetime.strftime(now, "%H:%M")
varA = indigo.variables[180461382] #email address
hseVcnt = indigo.variables[1176596514].getValue(bool)

# theBody = "The house is vacant, and the front door was opened at %s" % (now.value)
theBody = "The house is vacant, and the front door was opened at {}" .format("value", now_formatted))
# theBody = "The house is vacant, and the front door was opened at {}" .format("value", now))
# theBody = "some text"
# if hseVcnt
indigo.server.sendEmailTo(varA.value, subject = "BRK House-front door opened", body = theBody)


produces the error,

Oct 19, 2019, 11:20:01
Script Error fDrOpenEmail.py: invalid syntax
Script Error around line 8 - "theBody = "The house is vacant, and the front door was opened at {}" .format("value", now_formatted))"

Posted on
Sat Oct 19, 2019 12:26 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Python script: testing time an if/then condition

You’ve too many closing brackets on the end of that line.


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Oct 20, 2019 5:20 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python script: testing time an if/then condition

That was embarrassing. Removed the extra ')', but the 'theSubj" returns "value", not the formatted time.

Code: Select all
import datetime
now = indigo.server.getTime()
now_formatted = datetime.datetime.strftime(now, "%H:%M")
theAddress = indigo.variables[1979525395] #email address BOB
theSubj = "G house warmup OFF at {}" .format("value", now_formatted)
theBody = "The house was never occupied, and the heater was reset to 5C."

indigo.server.sendEmailTo(theAddress.value, subject = theSubj, body = theBody)

Posted on
Sun Oct 20, 2019 6:08 pm
forestfield offline
Posts: 83
Joined: Dec 29, 2014
Location: West Sussex

Re: Python script: testing time an if/then condition

That "value" in the 5th line is spurious, that line should be

Code: Select all
theSubj = "G house warmup OFF at {}" .format(now_formatted)

Posted on
Sun Oct 20, 2019 6:38 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python script: testing time an if/then condition

I believe I made the suggested change, and received a new (to me) error:
Script Error hseWarmupAutoOFF.py: 'Boost.Python.function' object has no attribute 'value'
Script Error Exception Traceback (most recent call shown last):

hseWarmupAutoOFF.py, line 11, at top level
AttributeError: 'Boost.Python.function' object has no attribute 'value'

Code: Select all
season = indigo.variables[325456157].getValue #season
import datetime
now = indigo.server.getTime()
now_formatted = datetime.datetime.strftime(now, "%H:%M")
theAddress = indigo.variables[1979525395] #email address BOB
theSubj = "G house warmup OFF at {}" .format(now_formatted)
theBody = "The house was never occupied, and the heater was reset to 5C OR HseWarmup20 was enabled."

indigo.actionGroup.execute(808629488) #action group allOFF

if season.value != "summer":
   indigo.server.sendEmailTo(theAddress.value, subject = theSubj, body = theBody)

Posted on
Sun Oct 20, 2019 7:09 pm
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python script: testing time an if/then condition

SMUSEBY wrote:
I believe I made the suggested change, and received a new (to me) error:
Script Error hseWarmupAutoOFF.py: 'Boost.Python.function' object has no attribute 'value'
Script Error Exception Traceback (most recent call shown last):

hseWarmupAutoOFF.py, line 11, at top level
AttributeError: 'Boost.Python.function' object has no attribute 'value'

Code: Select all
season = indigo.variables[325456157].getValue #season
import datetime
now = indigo.server.getTime()
now_formatted = datetime.datetime.strftime(now, "%H:%M")
theAddress = indigo.variables[1979525395] #email address BOB
theSubj = "G house warmup OFF at {}" .format(now_formatted)
theBody = "The house was never occupied, and the heater was reset to 5C OR HseWarmup20 was enabled."

indigo.actionGroup.execute(808629488) #action group allOFF

if season.value != "summer":
   indigo.server.sendEmailTo(theAddress.value, subject = theSubj, body = theBody)


You used the .value property twice for the season Indigo variable. Once in the first line, then again in the next to last.

Here's how I would do that script:

Code: Select all
import datetime

now = indigo.server.getTime()
now_formatted = datetime.datetime.strftime(now, "%H:%M")
season = indigo.variables[325456157].value       #season
theAddress = indigo.variables[1979525395].value    #email address BOB
theSubj = "G house warmup OFF at {}" .format(now_formatted)
theBody = "The house was never occupied, and the heater was reset to 5C OR HseWarmup20 was enabled."

indigo.actionGroup.execute(808629488) #action group allOFF

if season != "summer":
   indigo.server.sendEmailTo(theAddress, subject = theSubj, body = theBody)

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

Posted on
Sun Oct 20, 2019 10:17 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python script: testing time an if/then condition

It works. I have an idea why my version failed - perhaps you will confirm it.
The problem was not with the date/time, but rather how I treated the variables.

Code: Select all
season = indigo.variables[325456157].getValue #season
if season.value != "summer":

if season != "summer":


The only difference I could find between my version and yours is above - I used the first two lines, and yours employed the last line.
My theory is that I assigned the value of the indigo variable 'season' to the local python variable 'season'., and python found that disagreable. Had I assigned the indigo value of variable 'season' to 'newVar', mine would have worked. - albeit with two lines vs one. If there is some other reason, please let me know.
Follow on question - what are the symbols used to display year, month, day, and day of the week? - similar to %M and %H for minutes and hours?
As always, thank you for all your time and patience.
Bob

Posted on
Mon Oct 21, 2019 1:06 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Python script: testing time an if/then condition

For the formatting codes, scroll almost to the bottom of https://docs.python.org/3/library/datetime.html

There’s a table with them all in.


Sent from my iPhone using Tapatalk Pro

Posted on
Mon Oct 21, 2019 5:18 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python script: testing time an if/then condition

SMUSEBY wrote:
It works. I have an idea why my version failed - perhaps you will confirm it.
The problem was not with the date/time, but rather how I treated the variables.

Code: Select all
season = indigo.variables[325456157].getValue #season
if season.value != "summer":

if season != "summer":


The only difference I could find between my version and yours is above - I used the first two lines, and yours employed the last line.
My theory is that I assigned the value of the indigo variable 'season' to the local python variable 'season'., and python found that disagreable. Had I assigned the indigo value of variable 'season' to 'newVar', mine would have worked. - albeit with two lines vs one. If there is some other reason, please let me know.


Look more closely at the two lines you used. The first has .getValue (which is wrong, btw), and the second .value. You're trying to get the value of the Indigo variable twice. That doesn't work. It's got nothing to do with the names of the variables.

My example also has two lines, the first one was:
Code: Select all
season = indigo.variables[325456157].value       #season


the .value property gets the native value of the Indigo variable, which is a string. Which is what you want. You use .getValue() when you want to convert the string to a number or boolean. Which is not needed here.

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

Posted on
Mon Oct 21, 2019 5:19 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python script: testing time an if/then condition

howartp wrote:
For the formatting codes, scroll almost to the bottom of https://docs.python.org/3/library/datetime.html

There’s a table with them all in.


Better to use https://docs.python.org/2.7/library/datetime.html, which is the Python 2.7 documentation, just in case there's any differences between Python 2.7 and Python 3.X.

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

Posted on
Mon Oct 21, 2019 8:10 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Python script: testing time an if/then condition

Damned Safari!


Sent from my iPhone using Tapatalk Pro

Posted on
Wed Oct 23, 2019 7:33 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python script: testing time an if/then condition

the .value property gets the native value of the Indigo variable, which is a string. Which is what you want. You use .getValue() when you want to convert the string to a number or boolean. Which is not needed here.
Very interesting. Thank you.
Python 2.7 vs 3.0: latest version isn't the one we're using?

Posted on
Wed Oct 23, 2019 7:37 pm
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python script: testing time an if/then condition

SMUSEBY wrote:
Python 2.7 vs 3.0: latest version isn't the one we're using?


No. For backwards compatibility, Indigo is still using 2.7.X, because that's what Apple included in MacOS X in all versions back that Indigo still supports.

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

Who is online

Users browsing this forum: No registered users and 7 guests