Indigo Variable round to 2 decimals

Posted on
Sun Nov 27, 2016 4:25 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Indigo Variable round to 2 decimals

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

Posted on
Sun Nov 27, 2016 4:39 am
marketability offline
User avatar
Posts: 198
Joined: Dec 08, 2015
Location: UK

Re: Indigo Variable round to 2 decimals

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))))

Posted on
Sun Nov 27, 2016 5:39 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Indigo Variable round to 2 decimals

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!

Posted on
Sun Nov 27, 2016 8:09 am
marketability offline
User avatar
Posts: 198
Joined: Dec 08, 2015
Location: UK

Re: Indigo Variable round to 2 decimals

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

Posted on
Sun Nov 27, 2016 8:17 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Indigo Variable round to 2 decimals

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
Last edited by McJohn on Sun Nov 27, 2016 8:19 am, edited 1 time in total.

Posted on
Sun Nov 27, 2016 8:18 am
marketability offline
User avatar
Posts: 198
Joined: Dec 08, 2015
Location: UK

Re: Indigo Variable round to 2 decimals

oops I'm keyboard clumsy today... try

Code: Select all
myvar = indigo.variables[1723121229] # "Electra_dag"
indigo.variable.updateValue(myvar, str(round(myvar2,2)))

Posted on
Sun Nov 27, 2016 8:21 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Indigo Variable round to 2 decimals

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

Posted on
Sun Nov 27, 2016 8:55 am
marketability offline
User avatar
Posts: 198
Joined: Dec 08, 2015
Location: UK

Re: Indigo Variable round to 2 decimals

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))

Posted on
Sun Nov 27, 2016 9:31 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Indigo Variable round to 2 decimals

Thanks!

Script Error embedded script: invalid syntax
Script Error around line 4 - "indigo.variable.updateValue(myvar, str(xvar)"


Sorry :(

Posted on
Sun Nov 27, 2016 9:36 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Indigo Variable round to 2 decimals

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.

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

Posted on
Sun Nov 27, 2016 11:16 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Indigo Variable round to 2 decimals

It's working! Great!

Thanks for all your time and warm greetings from the Netherlands! :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests