Parsing an expression
-
Yes, and there's a straightforward way to do it within a Rule in MSR.
Suppose the variabletemp
= 789 (number) // it could also be "789" (string) and this technique should work fine
Just let another variableextract
be defined by:
substr( temp , 1 , 1 )
// equals 8Substr()
function takes three arguments: a number or string, a (zero-based) starting position, and a number of characters to keep.
Acting ontemp
here, I've asked for a substring starting at position1
(second character) with length1
(so just the "8").See this page for full Docs on using the lexpjs language (more functions coming soon!).
PRO TIP: If you anticipate
temp
may grow to have more digits, but you always wantextract
to pull the "2nd from last digit", use this expression instead, which starts from the right instead:
substr( temp , -2 , 1 )
-
So this would have to be lua on the vera side that populates the extract variable which I can then define as an expression in MSR? I am using the multi-string plugin which gets populated with a 3 digit string on multistrings variable1 and I want to perform 3 different reactions based on the varying values of characters 1 2 and 3. One reaction for each character. It sounds like I would need 3 variables extract1, extract2 and extract3.
-
So this would have to be lua on the vera side that populates the extract variable which I can then define as an expression in MSR? I am using the multi-string plugin which gets populated with a 3 digit string on multistrings variable1 and I want to perform 3 different reactions based on the varying values of characters 1 2 and 3. One reaction for each character. It sounds like I would need 3 variables extract1, extract2 and extract3.
-
It does not have to be on the Vera side. I can get the 3 digit variable into a MSR expression I just don't fully understand how to parse the characters into 3 separate entities for MSR to evaluate in a 3 seperare rules.i do follow what you suggested but just not sure how to implement it in MSR These are for TV channel.IR codes. I am using a lua routine on the Vera side for this and it often causes luup restarts. And I am just looking for a different approach.
-
It does not have to be on the Vera side. I can get the 3 digit variable into a MSR expression I just don't fully understand how to parse the characters into 3 separate entities for MSR to evaluate in a 3 seperare rules.i do follow what you suggested but just not sure how to implement it in MSR These are for TV channel.IR codes. I am using a lua routine on the Vera side for this and it often causes luup restarts. And I am just looking for a different approach.
-
It does not have to be on the Vera side. I can get the 3 digit variable into a MSR expression I just don't fully understand how to parse the characters into 3 separate entities for MSR to evaluate in a 3 seperare rules.i do follow what you suggested but just not sure how to implement it in MSR These are for TV channel.IR codes. I am using a lua routine on the Vera side for this and it often causes luup restarts. And I am just looking for a different approach.
@tarkus Start by creating a global variable in MSR that uses a getEntity() to fetch the variable contents. Click the
icon and it will build the expression for you when you pick the multistring entity and the attribute that contains the value.
Then, in each rule, create a variable, perhaps called
character
(for my lack of a deeper understanding of its meaning here), and put the expression LibraSun has given you in it. Hit Save. Then add a trigger condition using the Expression Value condition type to test for the character that should match. -
T toggledbits locked this topic on