Python arithmatec

Posted on
Tue Nov 10, 2020 3:17 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Python arithmatec

I am trying to update variable C with the difference between Var A and Var B, as follows:
Code: Select all
varA = int(dev.states["temperature"])
varB = indigo.variables[1086851778].getValue(int)
varC = indigo.variables[515949397].getValue(int)
indigo.variable.updateValue(varC, varA - varB)

My syntax is not working.
Suggestions?

Posted on
Tue Nov 10, 2020 3:27 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Python arithmatec

Your call to updateValue needs the first argument to be an instance of an Indigo variable but you are passing an integer value. Try this:

Code: Select all
varA_value = int(dev.states["temperature"])
varB_value = indigo.variables[1086851778].getValue(int)
varC = indigo.variables[515949397]
indigo.variable.updateValue(varC, str(varA_value - varB_value))

Image

Posted on
Tue Nov 10, 2020 3:43 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python arithmatec

I changed the varC line as suggested, but did not add "_value" as I understand that to be arbitrary (perhaps I'm mistaken?), and got the following error message in the event log - which I'm guessing is more syntax?:
Script Error FD lrTempStatus.py: Python argument types in
VariableCmds.updateValue(VariableCmds, int, int)
did not match C++ signature:
updateValue(_VariableCmds {lvalue}, boost::python::api::object elem, CCString value)
Script Error Exception Traceback (most recent call shown last):

FD lrTempStatus.py, line 47, at top level
ArgumentError: Python argument types in
VariableCmds.updateValue(VariableCmds, int, int)
did not match C++ signature:
updateValue(_VariableCmds {lvalue}, boost::python::api::object elem, CCString value)


Line 47:
Code: Select all
indigo.variable.updateValue(varC, varA - varB)

Posted on
Tue Nov 10, 2020 3:50 pm
jay (support) offline
Site Admin
User avatar
Posts: 18216
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python arithmatec

Matt forgot to convert the result to a string (all variable values are strings). I've updated his post to do this.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Nov 10, 2020 4:02 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python arithmatec

The script is not updating varC, but first (maybe related) there's another issue:
Trigger run a script
Script Error FD lrTempStatus.py: invalid syntax
Script Error around line 145 - "pass"

Lines 58-144 are commented out. No idea what line 145 has in it.

Posted on
Tue Nov 10, 2020 4:05 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Python arithmatec

You'll need to copy/paste the contents of the script (file FD lrTempStatus.py it looks like?) for us to see what is wrong.

Image

Posted on
Tue Nov 10, 2020 4:06 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python arithmatec

Sorry - I wasn't clear. Line 144 is the last line (using BBEdit).

Posted on
Tue Nov 10, 2020 4:12 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Python arithmatec

Add a couple of blank lines (returns) after that line and see if that fixes it.

Image

Posted on
Tue Nov 10, 2020 4:45 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python arithmatec

Below is the entire script (there is no line 11 on the BBEdit screen). Do I understand correctly that Indigo will be updated by a script until the script halts? - or does a script need to complete before updating Indigo? Because the varC is not updating, I'm assuming I still have a syntax issue.

Code: Select all
#varA
lRmCld_limit = indigo.variables[1086851778].getValue(int) #livingRm COLD threshhold
dev = indigo.devices[883519697] #living room
#varB
lRmT = int(dev.states["temperature"])
FD_lRm_coldStatus = indigo.variables[515949397]
#FD_lRm_warmStatus = indigo.variables[709335199]

#varC
indigo.variable.updateValue(515949397, str(lRmT - lRmCld_limit)

I get the result:
Trigger run a script
Script Error FD lrTempStatus.py: invalid syntax
Script Error around line 11 - "pass"

Posted on
Tue Nov 10, 2020 4:47 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python arithmatec

Nope. (added 3 lines)

Nov 10, 2020 at 14:46:54
Trigger run a script
Script Error FD lrTempStatus.py: invalid syntax
Script Error around line 14 - "pass"

Posted on
Tue Nov 10, 2020 5:00 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Python arithmatec

You need a closing bracket right at the end.

Your last line has 2 open brackets but only 1 closing.


Sent from my iPhone using Tapatalk Pro

Posted on
Tue Nov 10, 2020 5:00 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python arithmatec

This line is missing a final ')'
Code: Select all
indigo.variable.updateValue(515949397, str(lRmT - lRmCld_limit)


Should be
Code: Select all
indigo.variable.updateValue(515949397, str(lRmT - lRmCld_limit))


The script posted above is correct, you dropped the parenthesis.

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

Posted on
Tue Nov 10, 2020 5:04 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python arithmatec

My python always ends up an embarrassment.
Thanks to all of you.
Bob

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests

cron