Page 1 of 1
Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 4:25 am
by McJohn
Feature Request:
Option to simple edit Variable Values in Indigo to for example round values or values with 2 decimals.
I want to round an Indigo Variable:
"Electra_dag" with Value 3.848
to Value 3.85
Can anybody help me with the right Python script?
Thanks in advance!
John
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 4:39 am
by marketability
hope this is of help...
- Code: Select all
mmyvar = indigo.variables[518594898] # "Electra_dag"
myvar2 = 3.848
indigo.variable.updateValue(myvar, str(round(myvar2,2))))
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 5:39 am
by McJohn
Thanks for the fast reply my friend!
mmyvar = indigo.variables[518594898] # "Electra_dag"
myvar2 = 3.848
indigo.variable.updateValue(myvar, str(round(myvar2,2))))
I thinkI have to change theID of the Indigo Variable Electra_dag to my ID, it's 1723121229
But the variable is continuous changing (electric meter), so I wonder if the named 3.848 is right.
And I got a script error:
Script Error embedded script: invalid syntax
Script Error around line 3 - "indigo.variable.updateValue(myvar, str(round(myvar2,2))))"
Thanks for the help!
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 8:09 am
by marketability
Try this...
- Code: Select all
mmyvar = indigo.variables[1723121229] # "Electra_dag"
indigo.variable.updateValue(myvar, str(round(myvar2,2)))
looks like I had one too many right brackets
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 8:17 am
by McJohn
Thanks for the update:
I got:
Script Error embedded script: global name 'myvar' is not defined
Script Error Exception Traceback (most recent call shown last):
embedded script, line 2, at top level
NameError: global name 'myvar' is not defined
(even with one m at myvar)
Sorry
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 8:18 am
by marketability
oops I'm keyboard clumsy today... try
- Code: Select all
myvar = indigo.variables[1723121229] # "Electra_dag"
indigo.variable.updateValue(myvar, str(round(myvar2,2)))
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 8:21 am
by McJohn
You are fast, sorry:
Script Error embedded script: global name 'myvar2' is not defined
Script Error Exception Traceback (most recent call shown last):
embedded script, line 2, at top level
NameError: global name 'myvar2' is not defined
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 8:55 am
by marketability
more haste... less speed
try...
- Code: Select all
myvar = indigo.variables[1723121229] # "Electra_dag"
xvar = float(myvar.value)
xvar = round(xvar,2)
indigo.variable.updateValue(myvar, str(xvar))
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 9:31 am
by McJohn
Thanks!
Script Error embedded script: invalid syntax
Script Error around line 4 - "indigo.variable.updateValue(myvar, str(xvar)"
Sorry
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 9:36 am
by FlyingDiver
McJohn wrote:Thanks!
Script Error embedded script: invalid syntax
Script Error around line 4 - "indigo.variable.updateValue(myvar, str(xvar)"
Sorry
You're missing the last ")" on that line.
Re: Indigo Variable round to 2 decimals
Posted:
Sun Nov 27, 2016 11:16 am
by McJohn
It's working! Great!
Thanks for all your time and warm greetings from the Netherlands!