If script failing

Posted on
Mon Nov 18, 2019 7:36 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: If script failing

SMUSEBY wrote:
I was using the following, but reading the heading, I see that it is not for setting the value, but rather for changing the python type.
myInteger = 1
indigo.variable.updateValue(1234567, value=unicode(myInteger))


BTW, that should work correctly as it is how you set a variable value. Did you change the number to the ID of a valid Indigo variable?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Nov 18, 2019 11:42 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: If script failing

What's a unicode? I get lost very early on.
I know - I'm a failure. Believe me - I tried several tutorials. I never managed to get past the first 2 or 3 lessons: they seemed irrelevant and very tedious. And not for lack of interest - this stuff is fun, even though I'm no good at it.
And if you and others hadn't been willing to take the time to help me, I'd be SOL.
So, I'm both guilty and very grateful.
What makes me sad is that all you nice folks that have helped me out can't see the end result: the Lutron stuff is rock solid, and by combining it with a cleaned up Indigo environment running Python scripts - lots of them - I have a system that is really quite wonderful. It is very flexible, reliable, and easy to maintain. I'm quite happy, and to repeat, thanks to all of you for your patience, time and many contributions.

Posted on
Tue Nov 19, 2019 4:39 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: If script failing


I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Nov 19, 2019 6:14 am
agame offline
Posts: 514
Joined: Jul 13, 2017
Location: Melbourne, Australia

Re: If script failing

As a migrant from Vera, a couple of years ago, there are clear advantages in Indigo. One massive gap, that still puzzles me, is Indigo's lack of a tool (plugin or native) for doing basic maths/manipulation of variables without resorting to Python. Say, adding 10 seconds to a timestamp before a comparison, or doing some other calculation.

Coding shouldn't be necessary for basic maths on variables.

Posted on
Tue Nov 19, 2019 9:07 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: If script failing

agame wrote:
As a migrant from Vera, a couple of years ago, there are clear advantages in Indigo. One massive gap, that still puzzles me, is Indigo's lack of a tool (plugin or native) for doing basic maths/manipulation of variables without resorting to Python. Say, adding 10 seconds to a timestamp before a comparison, or doing some other calculation.

Coding shouldn't be necessary for basic maths on variables.


Oddly enough, we've had very few requests for that type of functionality. It also probably explains why there aren't any plugins for doing it (though I do seem to recall a plugin that does some calculations though I can't remember the details). Demand certainly plays a part in what goes into Indigo and this just hasn't risen to the top(ish) yet.

So I suppose massive is in the eye of the beholder... :wink:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Nov 19, 2019 6:14 pm
agame offline
Posts: 514
Joined: Jul 13, 2017
Location: Melbourne, Australia

Re: If script failing

Well looks like I'll need to stick to Python! damn.

It also probably explains why there aren't any plugins for doing it


The only observation I'd add is that the vast majority of plugins implement features the plugin developer needed personally. Presumably such an individual would not struggle with basic variable manipulation!...I'd observe there's actually a significant trickle of posts here relating to confusion in manipulating variables - albeit presented as Python support requests rather than Indigo feature requests.

Posted on
Tue Nov 19, 2019 6:26 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: If script failing

Perhaps it would help if I were to explain better my confusion. In the example,
myInteger = 1
indigo.variable.updateValue(1234567, value=unicode(myInteger))

there is the work, 'unicode'.
If one is conversant in Python, I suspect it's definitive.
For me, it's not clear how to understand the inclusion of 'unicode'. Is it a specification, or do the characters 'unicode' need to be included. So to actually assign the variable, do I write
indigo.variable.updateValue(1234567, value=unicode(myInteger))

or
indigo.variable.updateValue(1234567, value=(myInteger))[/quote]
or
substitute something else for 'unicode'
[/quote]
?
And then there is the treatment for integers, floating, boolean and strings.

Posted on
Tue Nov 19, 2019 7:18 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: If script failing

If you try:
Code: Select all
indigo.variable.updateValue(1234567, value=(myInteger))
You'll get an error because you'd be trying to save the integer 1 to a variable and variables only accept strings. Strings are text. Integers (and floats) are numbers. True and False are boolean values.

You must use:
Code: Select all
myInteger = 1
indigo.variable.updateValue(1234567, value=unicode(myInteger))
The unicode bit converts the item in parentheses to a Unicode string (text). Unicode is a system that allows a wide array of characters to be used as text--even though they aren't A-Z, 0-9, etc.

unicode(1) makes the number 1 into the string "1" (the quotes are important). Then Indigo saves the string to the variable.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Nov 19, 2019 7:37 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: If script failing

agame wrote:
The only observation I'd add is that the vast majority of plugins implement features the plugin developer needed personally. Presumably such an individual would not struggle with basic variable manipulation!...I'd observe there's actually a significant trickle of posts here relating to confusion in manipulating variables - albeit presented as Python support requests rather than Indigo feature requests.


I have working code to add to the Multitool plugin that takes a variable value and applies the user's formula to it. For example, take the value of Variable X, add 10 percent (X * 1.1), and save the result to Variable X. It can handle addition, subtraction, multiplication, division, exponents, and a couple others. It runs on the same code that I use for applying adjustments to matplotlib plugin plots. I should be able to throw up a build fairly soon. Stay tuned.

For device states, there is the Scale Adapters (or Adapters) plugin.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Nov 19, 2019 8:22 pm
agame offline
Posts: 514
Joined: Jul 13, 2017
Location: Melbourne, Australia

Re: If script failing

DaveL17 wrote:
I have working code to add to the Multitool plugin that takes a variable value and applies the user's formula to it. For example, take the value of Variable X, add 10 percent (X * 1.1), and save the result to Variable X. It can handle addition, subtraction, multiplication, division, exponents, and a couple others. It runs on the same code that I use for applying adjustments to matplotlib plugin plots. I should be able to throw up a build fairly soon. Stay tuned.

For device states, there is the Scale Adapters (or Adapters) plugin.


How useful that would be! (would it handle time values as well as real numbers?)

(and yes the Adapters plugin is tremendous).

Posted on
Tue Nov 19, 2019 8:47 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: If script failing

SMUSEBY wrote:
Perhaps it would help if I were to explain better my confusion. In the example,
myInteger = 1
indigo.variable.updateValue(1234567, value=unicode(myInteger))

there is the work, 'unicode'.
If one is conversant in Python, I suspect it's definitive.

unicode(something) casts the variable something into a unicode string. That is, it forces it into the type unicode string. A unicode string is just a string that support unicode characters. You can have strings that aren't unicode, but in-general Indigo likes unicode strings because it makes handing accented characters relatively straightforward. Just think of unicode as being a string for this discussion. Let's take another example:

someInteger = 5
someRealNumber = 5.0
someUnicodeString = u"hello world"

so above are 3 python variables. The variables internal type is defined by what you assign to the variable. The first is an integer type variable, the next a real number variable, and the last a unicode string. Indigo always stores variable values as unicode strings, and the updateValue expects a unicode string for that second argument. Given above if I were to do:

someUnicodeString = unicode(someRealNumber)

then someUnicodeString would now be a unicode string. That is it would be u"5.0" and not 5.0. You can cast from one type to another just by using the type name and a parentheses. So after above I could then do this:

someInteger = int(someUnicodeString)

and that will set someInteger to be an integer with the value 5. Note if someUnicodeString isn't a number (say it was the unicode string u"hello world") then the line above would fail. You would get a python exception thrown because it isn't possible to convert "hello world" into an integer. You can always convert integers and real numbers to strings though, you just may not be able to convert in the other direction .

Image

Posted on
Tue Nov 19, 2019 9:13 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: If script failing

agame wrote:
How useful that would be! (would it handle time values as well as real numbers?)

That would be pretty easy to add (pun intended) so consider it done. It'll likely be a separate tool because it will only support addition and subtraction (not even sure subtraction is needed in this context, but that could be the beer talking).

What I'm thinking is an Action item for each.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Nov 19, 2019 10:04 pm
agame offline
Posts: 514
Joined: Jul 13, 2017
Location: Melbourne, Australia

Re: If script failing

DaveL17 wrote:

What I'm thinking is an Action item for each.



I think that sounds perfect, essentially another modify variable action.

I won't buy into the need for subtraction argument, lest its a slippery slope to the 'its all in python anyhow' discussion

Posted on
Wed Nov 20, 2019 6:40 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: If script failing

After sleeping on it, I think date subtraction could be useful. I can envision a circumstance where you have a timestamp in the future and want that timed thing to happen earlier.

I'll include it.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Nov 20, 2019 8:53 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: If script failing

Date subtraction is useful in log viewing; show me events in the last 7 days, ie now minus 7 days.


Sent from my iPhone using Tapatalk Pro

Who is online

Users browsing this forum: No registered users and 4 guests