"If" statement help

PhoenixF15E's Avatar
User User
  • Posts: 91
  • Thanks: 3

Re: "If" statement help

2 years 5 months ago
#2130
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 or Create an account to join the conversation.

bowlingbeeg's Avatar
User User
  • Posts: 248
  • Thanks: 33

Re: "If" statement help

2 years 5 months ago
#2131
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 or Create an account to join the conversation.

bitzerjd's Avatar Topic Author
User User
  • Posts: 375
  • Thanks: 3

Re: "If" statement help

2 years 5 months ago
#2133
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 or Create an account to join the conversation.

davep's Avatar
Admin Admin
  • Posts: 371
  • Thanks: 98

Re: "If" statement help

2 years 5 months ago - 2 years 5 months ago
#2136
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 5 months ago by davep.

Please Log in or Create an account to join the conversation.

bitzerjd's Avatar Topic Author
User User
  • Posts: 375
  • Thanks: 3

Re: "If" statement help

2 years 5 months ago - 2 years 5 months ago
#2137
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 5 months ago by bitzerjd.

Please Log in or Create an account to join the conversation.

Time to create page: 0.325 seconds