Page 1 of 1

Updating variable with python

PostPosted: Mon Mar 23, 2020 11:17 am
by Sofabutt
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

Re: Updating variable with python

PostPosted: Mon Mar 23, 2020 11:52 am
by jltnol
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)

Re: Updating variable with python

PostPosted: Mon Mar 23, 2020 12:13 pm
by Sofabutt
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.

Re: Updating variable with python

PostPosted: Mon Mar 23, 2020 12:26 pm
by FlyingDiver
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.

Re: Updating variable with python

PostPosted: Mon Mar 23, 2020 12:30 pm
by FlyingDiver
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))

Re: Updating variable with python

PostPosted: Mon Mar 23, 2020 12:37 pm
by Sofabutt
Perfect! Thank you!