Announcement

Collapse
No announcement yet.

Set Device to Expression - If-Then-Else (Conditional Event Actions)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Set Device to Expression - If-Then-Else (Conditional Event Actions)

    I have been using the If-Then-Else functionality in the "Set Device to Expression" EasyTrigger action with great success. In my opinion this is a real "hidden gem" that allows event actions to be executed conditionally (functionality that HS3 should probably have natively).

    The EasyTrigger User Guide explains the functionality like this...

    another interesting function is "if(condition, value if condition is true, value if condition is false)" that allows us to use conditional expression like
    Code:
     if($$DVR:123: > $$DVR:234:, 60, 70)
    which means if device #123 has a value greater than device #234 then returns 60 else 70
    I've recently come across a use case where I would like to omit the "Else" part of the expression, so that the action executes if the "If" part is True, but does nothing if the "If" part is false.

    Using the example above, what I would like to do is omit the "else 70" part, so something like this:

    Code:
    if($$DVR:123: > $$DVR:234:, 60)
    But when I try using this expression, the plugin complains in the log:

    Code:
      EasyTrigger     ERROR if() takes exactly 3 arguments
    Is it possible to omit the "Else"?

    BTW, I am aware that it is possible to accomplish the end result using other methods in HS3. But I am specifically interested if it is possible with this EasyTrigger "Set Device to Expression" functionality.

    #2

    Code:
    if($$DVR:123: > $$DVR:234:, 60, $$DVR:123:)

    Comment


      #3
      Originally posted by baudi View Post
      Code:
      if($$DVR:123: > $$DVR:234:, 60, $$DVR:123:)
      Thanks, baudi....That does indeed work for the example in the User Guide, but it doesn't work for my use case. I should have specified that I am actually using the "Set Group of Devices to Expression" EasyTrigger action in this use case, which makes things more complex. (I tried to edit the thread title to indicate this distinction, but that is apparently not possible on this board.) So when setting a group of devices, the destination device is now many devices, and as such cannot be specified in the expression.

      The event action looks like this:

      Click image for larger version  Name:	Screenshot 2019-02-17 15.37.57.png Views:	1 Size:	78.7 KB ID:	1285784

      $$DVR:1458: is a virtual device that indicates if my Apple TV is ON (100) or OFF (0). So if the Apple TV is ON ($$DVR:1458: = 100), then I want to turn on all of the TVs (TVsOnOff). But if the AppleTV is OFF, then the TVs should all remain in their current state, whether they are on or off.

      But way the action is in the screenshot, if the Apple TV is OFF, the current state of the TV is not taken into consideration, and all TVs will simply be turned off.

      Hopefully that clarifies why the "Else" action needs to be omitted in this situation.

      Comment


        #4
        As an FYI - The new beta (0.61) of Easy Trigger now evaluates the expression part separately for each device in the group, and you also have access to each device's current value using the variable $DEVICEVALUE which you can use in the expression. So, to get the effect you are seeking, you could use the expression:

        IF ($$DVR:1458: = 100, 100, $DEVICEVALUE)

        In other words, if your Apple TV is on, then for each device in the group TVsOnOff, set the TV device to 100, otherwise, if the Apple TV was off, leave each device in TVsOnOff at its current value (i.e., set it to its existing value of $DEVICEVALUE)

        See these post for more information on this new feature and examples: https://forums.homeseer.com/forum/ul...13#post1293313 and https://forums.homeseer.com/forum/ul...66#post1293466

        Comment


          #5
          Originally posted by jvm View Post
          As an FYI - The new beta (0.61) of Easy Trigger now evaluates the expression part separately for each device in the group, and you also have access to each device's current value using the variable $DEVICEVALUE which you can use in the expression. So, to get the effect you are seeking, you could use the expression:

          IF ($$DVR:1458: = 100, 100, $DEVICEVALUE)

          In other words, if your Apple TV is on, then for each device in the group TVsOnOff, set the TV device to 100, otherwise, if the Apple TV was off, leave each device in TVsOnOff at its current value (i.e., set it to its existing value of $DEVICEVALUE)

          See these post for more information on this new feature and examples: https://forums.homeseer.com/forum/ul...13#post1293313 and https://forums.homeseer.com/forum/ul...66#post1293466
          Very nice! This does indeed appear to provide the functionality I am looking for. Thanks for pointing this out, jvm, I'll test it out.

          Comment

          Working...
          X