Plugin Formulas (aka "field expressions")

Posted on
Sun Aug 12, 2012 4:22 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Plugin Formulas (aka "field expressions")

The just-released new versions of the Cynical Plugins have a pervasive new feature I should discuss on its own. I call it Plugin Formulas.

Here's the basic idea: When you type a value into a plugin UI text field (a message to send, a string to match, a repeat count - anything really), you can now also put in a formula that calculates the value of the field. Plugin formulas are actually Python expressions, with the meanings of names adjusted to be most useful for the one-liners they must needs be. You can use Indigo variables in those formulas, and the value of the field will change as you change those variables.

This should be useful to you even if you're not a Python programmer. Here's an attempt at a gentle introduction for non-programmers: http://www.cynic.org/indigo/plugins/info/formula_tutorial.html. If you do know how to write Python code, this is going to be easy; go there to get started: http://www.cynic.org/indigo/plugins/info/formulas.html.

Obvious places to use plugin formulas include the text to be sent to Cynical Network devices; the overlay text to be set on Cynical SecuritySpy cameras; the IR symbols to be sent to Cynical Caché IR emitters; and the volume setting on Cynical Denon AV receivers. The Cynical Calendars plugin lets you use plugin scripts (the big brother of plugin formulas) directly in calendar events.

Use this thread to ask questions and complain about problems with plugin formulas and scripts in general. They should work consistently in all the Cynical plugins. I think this is a big deal, and I'm sure it has some "interesting" bugs to match. Let me know.

Cheers
-- perry

Posted on
Sun Aug 12, 2012 6:16 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Plugin Formulas (aka "field expressions")

I'll try the Cynical Caché update in a bit, and the Plugin Formulas look awesome. Thanks for all the updates.

Image

Posted on
Sat Jun 14, 2014 10:47 am
colinpartridge offline
Posts: 373
Joined: Jan 13, 2014
Location: London, UK

Re: Plugin Formulas (aka "field expressions")

I'm struggling with the simplest of plugin formula for Cynical Network 1.6.1. I have some action groups sending text to a yamaha receiver . For example the sent text to change to hdmi input 2 is
Code: Select all
@MAIN:INP=HDMI2
. I have a variable setup called YamahaCurrentState which stores the value of the current state( eg.@MAIN:INP=HDMI2), generated when the input is switched. I am trying to call this variable by setting the text to
Code: Select all
=YamahaCurrentState

which I would have thought should work, but it doesn't. For completeness I've attached the action group view in case there are any clues
.Image

Image

Any thoughts?

Colin

Posted on
Sat Jun 14, 2014 11:17 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Plugin Formulas (aka "field expressions")

Just to make sure it isn't some case sensitivity problem, temporarily change the variable name from YamahaCurrentState to foo, and change the send text field to just "=foo".

Image

Posted on
Sat Jun 14, 2014 12:47 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Plugin Formulas (aka "field expressions")

Just to make sure it isn't some case sensitivity problem, temporarily change the variable name from YamahaCurrentState to foo, and change the send text field to just "=foo".

Variable names are case-sensitive, yes. (They're just sent to the variables map; I'm assuming they're meant to be sensitive or that map would accept them in any case.)

Cheers
-- perry

Posted on
Sat Jun 14, 2014 5:25 pm
colinpartridge offline
Posts: 373
Joined: Jan 13, 2014
Location: London, UK

Re: Plugin Formulas (aka "field expressions")

Changing the variable name to something simpler and lowercase didn't make any difference.

Colin

Posted on
Sun Jun 15, 2014 2:53 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Plugin Formulas (aka "field expressions")

I'm struggling with the simplest of plugin formula for Cynical Network 1.6.1. I have some action groups sending text to a yamaha receiver .

So exactly what happens, and what did you expect to happen?

Here's a basic trick to test Cynical Network: Create an auto-connecting TCP Out device to localhost port 6666 (or some other fixed, unused port). Then in Terminal, run
Code: Select all
$ nc -l 6666

The device will connect to Terminal; what you type in Terminal will become device input, and anything you Send Text to the device will show up in Terminal. This lets you play around with the plugin until you get that part right. Of course, I can't tell you whether your actual command strings are right; but Terminal/nc lets you pretend to be the network device for testing purposes.

Cheers
-- perry

Posted on
Sun Jun 15, 2014 4:30 pm
colinpartridge offline
Posts: 373
Joined: Jan 13, 2014
Location: London, UK

Re: Plugin Formulas (aka "field expressions")

Hi Perry
I have a bunch of actions which change the selected input of a Yamaha AV receiver, The form of the text to achieve this is @MAIN:INP=AV4 to change to AV4 etc. This works perfectly.. However I would like to change the input based on a previously stpred variable hence using you formula method. I have tried your test method and the result I get "should" work, the text received by Terminal is identical to the direct form of the text, except the command sent does not work. I am at a loss to understand why. The line endings of both the real and test devices are the same. I'll persevere with this when I have more time, as I'm sure I'll get it to work eventually...or I'll find another way.

Cheers

Colin

Posted on
Wed Jun 18, 2014 3:12 am
colinpartridge offline
Posts: 373
Joined: Jan 13, 2014
Location: London, UK

Re: Plugin Formulas (aka "field expressions")

Hi Perry,
I think I have found out why this action is not working, but i'm not clear what the solution is. My recognised input trigger has the pattern
Code: Select all
@MAIN:INP=

no parentheses as I didn't want the line endings. The last line is put into a variable Yamaha-Input. The problem is that what is stored in the variable has a trailing \n which I hadn't spotted before as I was only looking at the visible text. Is this something I should be able to remove by refining the regular expression?

Colin

Posted on
Wed Jun 18, 2014 9:32 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Plugin Formulas (aka "field expressions")

Try
Code: Select all
@MAIN:INP=(.*)
as the trigger pattern, and correspondingly
Code: Select all
="@MAIN:INP=" + YourVariable
in the Send Text action. That makes the variable just the name of the input source. You could also include the @MAIN:INP= inside the parentheses (and omit it from the action); either should work (just be consistent).

Cheers
-- perry

Posted on
Wed Jun 18, 2014 1:24 pm
colinpartridge offline
Posts: 373
Joined: Jan 13, 2014
Location: London, UK

Re: Plugin Formulas (aka "field expressions")

Hi Perry
@MAIN:INP=(.*) and (@MAIN:INP=.*) both gave me a trailing newline. In the meantime I did find a neat website http://www.regexr.com which allows you to build a regex against text input which after a bit of playing around gave me a regex of (@MAIN:INP=\w+) which appears to be working without the trailing newline and all is good now.
Thanks for your input.

Cheers
Colin

Posted on
Wed Jun 18, 2014 3:46 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Plugin Formulas (aka "field expressions")

Right. In this context, the dot doesn't implicitly exclude newlines (because the newline is configurable), so if there's multiple newlines in the input buffer, it'll eat some. Your answer (\w*) works fine as long as you're only matching "word" characters. You could say [^\n]* instead. Or you could use the non-greedy wildcard (.*?). Any of those should do the job for you.

Cheers
-- perry

Posted on
Thu Jun 19, 2014 2:33 am
colinpartridge offline
Posts: 373
Joined: Jan 13, 2014
Location: London, UK

Re: Plugin Formulas (aka "field expressions")

Thanks Perry, your regex makes more sense generally, its all new to me so learning curve is hyperbolic at the moment, I'll give yours a shot when I get chance.

cheers

Colin

Posted on
Fri Sep 04, 2015 11:03 pm
Korey offline
User avatar
Posts: 813
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Plugin Formulas (aka "field expressions")

Been using the Cynical Network plugin for years to flawlessly control my my Anthem D1 Processor via RS232. Kudos to Perry!

Trying now to decode values from the output and then have the value stored as an Indigo variable.

Not having much luck in parsing the output to get the correct expression.


Sending:

P1VM?

Results in this:

Code: Select all
 
Action Group                    Zone 1 Volume ?
  Cynical Network                 scanning '\nP2P1\n\n\nP2P0\n\nP2P1\n\n\n\nP2P0\n\n\nP2P0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nP2P0\n\n\nP2P0\n\nP2P1\n\n\n\n\n\nP2P0\n\n\nP2P0\n\n\nP2P0\n\nP2P1\n\n\nP2P0\n\nP2P0\n\n\nP2P0\n\nP2P1\n\n\n\n\nP2P0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nP1VM-22.5\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nInvalid Command\nInvalid Command\nInvalid Command\nInvalid Command\n\n\n\n\n\nP1VM-31.0\n'
  Cynical Network                  trying <RE('(.*nP1VM-(\\f+).*)(?s)\\r')16> <IOM+ 321270181=D1 Zone 1 Volume>
  Cynical Network                  trying <RE('(.*?)(?s)\\r')16> _UNRECOGNIZED
  Cynical Network                  no match



I can see the zone 1 Volume retuned from the unit as : P1VM-22.5 and P1VM-31.0 ?

How the hell do I grab this value and insert it as a Variable?? :?

Thanks in advance.

Here are an example of the codes available to be polled:

Code: Select all
P1P?      query main zone power: returns P1Px
P1S?      query main zone source: returns P1Sx or P1Xxy (if in simulcast)
P1VM?      query main zone volume: returns P1VMsxx.x
P1VF?      query current main zone front volume returns P1VFsxx.x (returns P1VF +0.0 if no signal)
P1VC?      query current main zone center volume returns P1VCsxx.x (returns P1VC +0.0 if no signal)
P1VR?      query current main zone surround volume returns P1VRsxx.x (returns P1VR +0.0 if no signal)
P1VB?      query current main zone back volume returns P1VBsxx.x (returns P1VB +0.0 if no signal)
P1VS?      query current main zone subwoofer volume returns P1VSsxx.x (returns P1VS +0.0 if no signal)
P1VL?      query current main zone LFE volume returns P1VLsxx.x (returns P1VL +0.0 if no signal)
P1LM?      query Main zone master balance returns P1LMsxx.x
P1LF?      query Main zone front balance returns P1LFsxx.x
P1LR?      query Main zone surround balance returns P1LRsxx.x
P1LB?      query Main zone back/rear balance returns P1LBsxx.x
P1BM?      query Main zone master bass returns P1BMsxx.x
P1BC?      query Main zone center bass returns P1BCsxx.x
P1BF?      query Main zone front bass returns P1BFsxx.x
P1BR?      query Main zone surround bass returns P1BRsxx.x
P1BB?      query Main zone rear/back bass returns P1BBsxx.x
P1TM?      query Main zone master treble returns P1TMsxx.x
P1TC?      query Main zone center treble returns P1TCsxx.x
P1TF?      query Main zone front treble returns P1TFsxx.x
P1TR?      query Main zone surround treble returns P1TRsxx.x
P1TB?      query Main zone rear/back treble returns P1TBsxx.x
P1TE?      query Main zone tone controls enabled returns P1TEx
P1?      query main zone status: returns P1SxVsyy.yMnDuEv (or P1XxzVsyy.yMnDuEv if in simulcast where x is audio source and z is video source) where x is source, syy.y is volume, n is mute state, u is decoder status (see P1D? command) and v is stereo effect
P1E?      query current main zone stereo input surround effect: returns P1Eyx
P1EF?      query current main zone Dolby Digital 2.0 surround encoded (i.e. flagged) input surround effect: returns P1EFyx
P1EE?      query current main zone Dolby Digital EX encoded (i.e. flagged) input effect status: returns P1EEyx
P1ES?      query current main zone DTS ES Matrix encoded input effect status: returns P1ESyx
P1ET?      query current main zone stereo input THX status: returns P1ETyx
P1EU?      query current main zone Dolby Digital 2.0 surround encoded (i.e. flagged) input THX status: returns P1EUyx
P1EX?      query current main zone DD-5.1 input effect status: returns P1EXyx. Note that for older firmware that did not have a "P1EY?" command, this returns the 6.0 input effect for source 6-Ch SE.
P1EY?      query current main zone 6.0 input (analog or PCM) effect status: returns P1EXyx.
P1ED?      query current main zone DTS-5.1 input effect status: returns P1EDyx
P1EMP?      query current main zone Dolby Prologic Music Mode panorama: return P1EMPyx
P1EMC?      query current main zone Dolby Prologic Music Mode center width: return P1EMCyx
P1EMD?      query current main zone Dolby Prologic Music Mode dimension: return P1EMDyx
P1EMG?      query current main zone DTS Neo:6 center gain: return P1EMGyx
P1ED?      query current main zone DTS-5.1 THX Ultra2 status: returns P1EDyx
P1ER?      query current main zone THX front channel RE-EQ status when THX is on: returns P1ERyx
P1EN?      query current main zone THX front channel RE-EQ status when THX is off: returns P1ENyx
P1C?      query current main zone dynamic range compression in Dolby Digital modes: returns P1Cx
P1D?      query main zone decoder status: returns P1Dnx where current decoder mode for source n is x
      where x = 0,1,2,3…6 (0=stereo source, 1=Dolby AC-3 source, 2=DTS source,3=MPEG source,4=6-ch source,5=2-ch analog direct source,6=no signal) NOTE - shift of decoder mode index relative to setting values eg:P1VSysxxx where y = 0,1,2,…6 (0=current mode, 1=stereo source, 2=Dolby AC-3 source, 3=DTS source, 4=MPEG source,5=6-ch source,6=2-ch analog direct source)
P1DF?      query main zone decoder surround flagged status: returns P1DFnx where current decoder mode for source n is x
      where x=0,1,2…8 (0=no signal, 1=mono,2=2ch not surround flagged, 3=2ch flagged eg DD-2.0 flagged for PL on, 4=more than 2 ch not flagged DD eg DD-5.1, 5=DD-5.1 EX flagged, 6=more than 2 ch not flagged DTS eg DTS-5.1, 7=DTS ES Matrix flagged, 8=DTS ES Discrete, 9=6ch analog)
P1A?      query main zone AC3 status: returns P1Anx where current AC3 status for source n is x
      and x=0,1,2(0=source not AC3,1=source 2 channel AC3,2=source multichannel (surround) AC3)
P1AD?      query main zone AC3 dialog normalization status: returns P1ADnx where current AC3 status for source n is x
      and x=dialog normalization in dB (0=source not AC3...)
P1Q?      returns an ASCII string description of the current processing mode for current source in main (i.e. the string on left hand side of lower line of LCD display)
Attachments
Screen Shot 2015-09-04 at 10.11.55 PM.PNG
Device Configuration
Screen Shot 2015-09-04 at 10.11.55 PM.PNG (86.88 KiB) Viewed 16486 times
Screen Shot 2015-09-04 at 9.51.29 PM.PNG
Trigger to try to Grab the correct value
Screen Shot 2015-09-04 at 9.51.29 PM.PNG (95.74 KiB) Viewed 16488 times
Screen Shot 2015-09-04 at 9.55.50 PM.PNG
What to put in so the Value is correctly passed to a Variable>
Screen Shot 2015-09-04 at 9.55.50 PM.PNG (85.43 KiB) Viewed 16488 times

--
Korey

Posted on
Fri Sep 04, 2015 11:24 pm
Korey offline
User avatar
Posts: 813
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Plugin Formulas (aka "field expressions")

Well bit closer, seems I needed to have a "Newline UNIX" in the device configuration.. :shock:


Code: Select all
Action Group                    Zone 1 Volume ?
  Cynical Network                 scanning 'P1VM-34.5\n'
  Cynical Network                  trying <RE('(.*P1VM.*)\\n')0> <IOM+ 321270181=D1 Zone 1 Volume Status>
  Cynical Network                  matched 'P1VM-34.5\n' | ''
  Cynical Network                  Anthem D1 Serial recognized D1 Zone 1 Volume Status 'P1VM-34.5'
  Trigger                         D1 Zone 1 Volume Status



Code: Select all
Action Group                    Zone 1 Processing mode ? | Serial
  Cynical Network                 scanning 'P1Q5.1 \n'
  Cynical Network                  trying <RE('(.*P1Q.*)\\n')0> <IOM+ 636008595=D1 Zone 1 Processing mode>
  Cynical Network                  matched 'P1Q5.1 \n' | ''
  Cynical Network                  Anthem D1 Serial recognized D1 Zone 1 Processing mode 'P1Q5.1 '
  Trigger                         D1 Zone 1 Processing mode


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.

--
Korey

Who is online

Users browsing this forum: No registered users and 2 guests