"If" statement help

More
2 years 4 months ago #2130 by PhoenixF15E
Replied by PhoenixF15E on topic "If" statement help

I saw this example in your docs.

If|isEQ##{{variable_x}}{{variable_y}}##onoff##do something interesting

In the example variable_x = on and variable_y=off   

How does it know to parse ##onoff##  Shouldn't there be a delimiter between the values?  In my case the variables are 0 and 1 so it would be some combo of that. 00, 01,10 etc.

Thanks!




 
The example implies variable x and variable y are concatenated into one item, so the result of the concatenation would be 'onoff'.  At least that's the way I read it.  Most languages I've seen have an explicit operator for concatenation, but I guess it's implied here.

Kyle

Please Log in to join the conversation.

More
2 years 4 months ago #2131 by bowlingbeeg
Replied by bowlingbeeg on topic "If" statement help
My guess is that it's just a straight string comparison. So it replaces variable_x and variable_y with their values, concatenates them into a string, and then does the string comparison with the "onoff" string.

Please Log in to join the conversation.

More
2 years 4 months ago #2133 by bitzerjd
Replied by bitzerjd on topic "If" statement help
Thanks guys!  In my use case I created a Smart Volume Up and Down.  It evaluates the state of the variables and uses the appropriate Volume command.  If the Home Theater is on, use the Anthem.  If Sonos is on, use it, and if it's just the TV, use it.  This is on the opening screen on the remote so if someone picks it up, the volume works on whatever is playing.

I'm trying to make the remote idiot proof so anyone who picks it up can use it without a training course :-)

Please Log in to join the conversation.

More
2 years 4 months ago - 2 years 4 months ago #2136 by davep
Replied by davep on topic "If" statement help
Logically

If Anthem = on then
     AV|<anthem id>~Volume~<P1>
else if Sonos = on then
     AV|<sonosid>~Volume~<P1>
else
   AV|<tv id>~Volume~<P1>

To do this in myServer we need to use nested if statements. If statements are nested by using different sets of delimiters at each nesting level. Here we use pairs of ## and %%

If|isEQ##{{av_<anthemid>_power}}##on##          <<<< if Anthem is on
    AV|<anthemid>~Volume~<P1>##                     <<<< then Anthem volume
    If|isEQ%%{{av_<sonosid>_power>%%on%%  <<<< else if Sonos is on
           AV|<sonosid>~Volume~<P1>%%              <<<< then Sonos volume
           AV|<tvid>~Volume~<P1>                           <<<< else TV volume

If Anthem id = 22, and Sonos id = 33 and TV id is = 44 the command becomes

If|isEQ##{{av_22_power}}##on##AV|22~Volume~<P1>##If|isEQ%%{{av_33_power>%%on%%AV|33~Volume~<P1>%%AV|44~Volume~<P1>

Valid delimiters for nesting ifs are ##, @@, $$, %% and &&

Alternately you could use the Switch command to do things based on the active source. The Switch command acts just like the Switch statement in programming languages

Switch|<reference variable>##
case1##command 1##
case2##command 2##
case3##command 3##
default##default command

Using the above example
Switch|{{activesource_sourcename_{{clientname}}}}##
anthem##AV|22~Volume~<P1>##
sonos##AV|33~Volume~<P1>##
default##AV|44~Volume~<P1>


 
Last edit: 2 years 4 months ago by davep.

Please Log in to join the conversation.

More
2 years 4 months ago - 2 years 4 months ago #2137 by bitzerjd
Replied by bitzerjd on topic "If" statement help
Here is what I did:
Macro|
If|isEQ##{{sonos}}{{htstatus}}##01##AV|7~Volume~Up!
If|isEQ##{{sonos}}{{htstatus}}##00##AV|4~Volume~Up!
If|isEQ##{{sonos}}{{htstatus}}##10##AV|6~Volume~Up~3!

It's not pretty, but it works :-). I will probably rewrite it in the format you suggested, but for now, it works!

Again, Thanks for the help, this has been a bit of a learning curve, but things are falling in place.
Last edit: 2 years 4 months ago by bitzerjd.

Please Log in to join the conversation.

Time to create page: 0.256 seconds