Page 2 of 2

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sat Sep 05, 2015 5:05 am
by DaveL17
Hi Korey - here's one way to do it (presumes that the value you're looking for will always follow 'P1VM'). You'll need to figure out how to grab the string in the first place...

Code: Select all
x = 'P1VM-34.5'
start = x.find('P1VM') + 4
vol = x[start:]
indigo.variable.updateValue(123456, vol)

or condensed down:
Code: Select all
x = 'P1VM-34.5'
indigo.variable.updateValue(123456, x[x.find('P1VM') + 4:])

Dave

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sat Sep 05, 2015 2:32 pm
by Korey
DaveL17 wrote:
Hi Korey - here's one way to do it (presumes that the value you're looking for will always follow 'P1VM'). You'll need to figure out how to grab the string in the first place...

Code: Select all
x = 'P1VM-34.5'
start = x.find('P1VM') + 4
vol = x[start:]
indigo.variable.updateValue(123456, vol)

or condensed down:
Code: Select all
x = 'P1VM-34.5'
indigo.variable.updateValue(123456, x[x.find('P1VM') + 4:])

Dave



Thanks, Dave,

That will work if x= P1VM-34.5 , but the value changes, i.e.: P1VM-19.0, it will no longer write to the variable.

How do I get it to just grab P1VM and make that x?

if I can just get x to be the prefix I can have feedback from the unit for every parameter just by changing the script to suit the commands.

I really need to learn python.. :?

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sat Sep 05, 2015 5:41 pm
by DaveL17
Hmmm. Not sure what you're seeing Korey, because it should work for any value.
Code: Select all
>>> x = 'P1VM-34.5'
>>> print x[x.find('P1VM') + 4:]
-34.5

>>> x = 'P1VM-19.0'
>>> print x[x.find('P1VM') + 4:]
-19.0

>>> x = 'P1VM-123456.789'
>>> print x[x.find('P1VM') + 4:]
-123456.789

>>> x = "P1VM Why, oh why didn't I take the blue pill?"
>>> print x[x.find('P1VM') + 4:]
 Why, oh why didn't I take the blue pill?
>>>

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sat Sep 05, 2015 6:33 pm
by FlyingDiver
Korey - YOU need to set the value of X from somewhere else. It's not hardcoded in the script. It's only there so the script will do something for testing purposes.

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sat Sep 05, 2015 6:51 pm
by DaveL17
Joe's right (sorry if that wasn't clear Korey!) The value of 'x' will come from another place--the plugin, a variable value, etc. Korey, contact me offline if you want me to walk you through step by step. Happy to do that. :D

Dave

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sat Sep 05, 2015 9:52 pm
by Korey
Thanks Fellas!


I thought I could do this all with one trigger, but realized I needed to have a seperate trigger that watches the variable that Perry's plugin writes to, then runs this code:

Code: Select all
x = indigo.variables[1959029577].value # Get the value from the variable.
start = x.find('P1VM') + 4
vol = x[start:]
indigo.variable.updateValue(63670514, vol)


Works like a charm!

Now i have about 50 - 100 new actions and triggers to make!! :roll:

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sun Sep 06, 2015 4:42 am
by DaveL17
That's the ticket.

Korey, why don't you contact me offline and we can talk about what you're trying to accomplish. Hopefully, we can keep you from having to write 100 triggers!

Dave

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sun Sep 06, 2015 10:10 pm
by Perry The Cynic
Korey wrote:
The trigger will now fire, just unsure how to pass the -34.5 to a variable, not the whole P1VM-34.5 as it is currently doing :?

I assume there is a simple python script I could run in the trigger to remove the prefix?

Thanks Guys.


Each Recognized Input event has its own variable that you can specify. And by the magic of regular expressions, you can ask for only part of your input string to end up in the variable. Try something like
Code: Select all
P1VM(.*)
as the matched string, and the variable should end up set to -34.5 (as a string, since all Indigo variables are strings). The event will still "eat" the whole string; but it'll only store the part between parentheses.

Cheers
-- perry

Re: Plugin Formulas (aka "field expressions")

PostPosted: Sun Sep 06, 2015 11:40 pm
by Korey
Perry The Cynic wrote:

Each Recognized Input event has its own variable that you can specify. And by the magic of regular expressions, you can ask for only part of your input string to end up in the variable. Try something like
Code: Select all
P1VM(.*)
as the matched string, and the variable should end up set to -34.5 (as a string, since all Indigo variables are strings). The event will still "eat" the whole string; but it'll only store the part between parentheses.

Cheers
-- perry


Thank you Perry!! :D :D :D

You just saved me from having to create around 200 new triggers to parse the info!

Seems my preamp will return the value of 109 different settings (3 zones) :shock:

Thank you once again for your wonderful plugins!