Updating variable with python

Posted on
Mon Mar 23, 2020 11:17 am
Sofabutt offline
Posts: 11
Joined: Feb 12, 2018

Updating variable with python

I am using the following script to update the outside temperature:


nowTemp = indigo.variables[1403030637].getValue(float) # WCT_external_temperature
yearHigh = indigo.variables[762466133].getValue(float) # WeatherOutsideTempYearlyHigh
yearLow = indigo.variables[128906629].getValue(float) # WeatherOutsideTempYearlyLow

if nowTemp > yearHigh:
indigo.variable.updateValue(762466133, value=nowTemp)
if nowTemp < yearLow:
indigo.variable.updateValue(128906629, value=nowTemp)

When I run it though, I get the following error:

Mar 23, 2020 at 10:12:25 AM
Script Error embedded script: Python argument types in
VariableCmds.updateValue(VariableCmds, 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):

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

When I run the script from inside the trigger, the following line becomes highlighted:

indigo.variable.updateValue(762466133, value=nowTemp)

Can someone help me troubleshoot this?

Thanks,

Matt

Posted on
Mon Mar 23, 2020 11:52 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Updating variable with python

I am HARDLY a Python person... so this is probably NOT the problem, but I'm thinking the syntax is slightly wrong: I think you need to indent the two lines indicated here...


Code: Select all
nowTemp = indigo.variables[1403030637].getValue(float) # WCT_external_temperature
yearHigh = indigo.variables[762466133].getValue(float) # WeatherOutsideTempYearlyHigh
yearLow = indigo.variables[128906629].getValue(float) # WeatherOutsideTempYearlyLow

if nowTemp > yearHigh:
   indigo.variable.updateValue(762466133, value=nowTemp)
if nowTemp < yearLow:
   indigo.variable.updateValue(128906629, value=nowTemp)

Posted on
Mon Mar 23, 2020 12:13 pm
Sofabutt offline
Posts: 11
Joined: Feb 12, 2018

Re: Updating variable with python

The formatting didn't carry over when I copied and pasted. It does appear in Indigo the way you corrected it. Thanks for pointing that out though.

Posted on
Mon Mar 23, 2020 12:26 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Updating variable with python

Sofabutt wrote:
The formatting didn't carry over when I copied and pasted. It does appear in Indigo the way you corrected it. Thanks for pointing that out though.


Use the "Code" tags when posting Python code.

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

Posted on
Mon Mar 23, 2020 12:30 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Updating variable with python

Sofabutt wrote:
I am using the following script to update the outside temperature:


Code: Select all
nowTemp = indigo.variables[1403030637].getValue(float) # WCT_external_temperature
yearHigh = indigo.variables[762466133].getValue(float) # WeatherOutsideTempYearlyHigh
yearLow = indigo.variables[128906629].getValue(float) # WeatherOutsideTempYearlyLow

if nowTemp > yearHigh:
    indigo.variable.updateValue(762466133, value=nowTemp)
if nowTemp < yearLow:
    indigo.variable.updateValue(128906629, value=nowTemp)

When I run it though, I get the following error:

Code: Select all
Mar 23, 2020 at 10:12:25 AM
   Script Error                    embedded script: Python argument types in
    VariableCmds.updateValue(VariableCmds, 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):

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

When I run the script from inside the trigger, the following line becomes highlighted:

Code: Select all
indigo.variable.updateValue(762466133, value=nowTemp)

Can someone help me troubleshoot this?


You're getting the value of WCT_external_temperature as a float, but you need to save it to the variable as a string. Try converting it to a string before you save it:

Code: Select all
nowTemp = indigo.variables[1403030637].getValue(float) # WCT_external_temperature
yearHigh = indigo.variables[762466133].getValue(float) # WeatherOutsideTempYearlyHigh
yearLow = indigo.variables[128906629].getValue(float) # WeatherOutsideTempYearlyLow

if nowTemp > yearHigh:
    indigo.variable.updateValue(762466133, value=str(nowTemp))
if nowTemp < yearLow:
    indigo.variable.updateValue(128906629, value=str(nowTemp))

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

Posted on
Mon Mar 23, 2020 12:37 pm
Sofabutt offline
Posts: 11
Joined: Feb 12, 2018

Re: Updating variable with python

Perfect! Thank you!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests