Announcement

Collapse
No announcement yet.

HOW TO? - Have multiple If/THEN statements in one event

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

    HOW TO? - Have multiple If/THEN statements in one event

    Hi, not sure this is the correct forum, however...

    I notice in an Event i can have an IF / THEN, i cant see how to add "ELSE" meaning how to add multiple If / THEN statements

    IF ....
    THEN ....
    ELSE - IF ......
    THEN ......

    I have a plug, i need to control its LED status, meaning to read another device and change the LED color based on that, so this will be a sub routine that is called from other events (i hope).

    Is the above logic possible?
    Last edited by SFX Group; April 20, 2016, 09:59 PM.

    #2
    Originally posted by SFX Group View Post
    Hi, not sure this is the correct forum, however...

    I notice in an Event i can have an IF / THEN, i cant see how to add "ELSE" meaning how to add multiple If / THEN statements

    IF ....
    THEN ....
    ELSE - IF ......
    THEN ......

    I have a plug, i need to control its LED status, meaning to read another device and change the LED color based on that, so this will be a sub routine that is called from other events (i hope).

    Is the above logic possible?
    A trigger is by design "a moment in time", an else would be all the time except that moment in time - not useful as a trigger. I'll challenge you with showing how such an event structure could ever work.

    In HomeSeer you can have multiple triggers sharing an action or group of actions, but you cannot have multiple paths to different actions within a single event.

    The solution is multiple events, each with their own trigger and actions or a single event with a trigger that branches of into multiple events, each with their own conditions and actions. This thread shows how to branch off into multiple events while honoring their conditions.

    This thread
    shows how to provide multiple triggers, each with their own conditions, sharing common action(s).
    HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

    Comment


      #3
      Originally posted by rprade View Post
      an else would be all the time except that moment in time
      Thanks, i'll read up on the links, however your above statement although true in real life, we are not talking about real life, talking about a "IF / THEN" statement structure so its very valid in this situation which is based on an "event" driven system (such as HS).

      CALL EVENT (the action that calls the below chain of tests and actions)
      IF light = ON
      THEN MAKE LED = GREEN
      ELSE IF light = OFF
      THEN make LED = RED

      The above explains a chain of basic IF / THEN / ELSE statements, the "chain" is only ever called once (there is no loop), and only ONE "THEN" statement is actioned, as IF light = ON then the "ELSE" statement never gets called, such as if the light = DIM (neither ON or OFF) then nothing happens, the above chain ends with no action.

      Ive yet to read your links, however the above is very basic logic methods and would surprise me if HS did not support this. The above would negate the need to have multiple IF THEN events which would over complicate a event / logic driven program.

      Comment


        #4
        One of the reasons there is no ELSE logic is that it's more difficult to accidentally create a trigger that would trigger continuously. You're not the first to raise this and yes, if you want to use ELSE logic you need to use multiple events. Takes a slightly different mind-set than programming logic, but the event engine is not meant to be a "programming interface".

        Cheers
        Al
        HS 4.2.8.0: 2134 Devices 1252 Events
        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

        Comment


          #5
          Originally posted by sparkman View Post
          Takes a slightly different mind-set than programming logic, but the event engine is not meant to be a "programming interface".

          Cheers
          Al
          Kind of worried about that, it appeared to be a "this happened, do this" rather than a "this happened, heres some nice items to test, and based on the outcome do this, OR this, OR this".

          I basically was trying to create a subroutine that would test the light and based on that do something with an LED, that would have been called from every light change event, however it appears the LED status will need to be actioned in every light change If / THEN area event rather than have ONE routine to do it for me.

          Comment


            #6
            Originally posted by SFX Group View Post
            Thanks, i'll read up on the links, however your above statement although true in real life, we are not talking about real life, talking about a "IF / THEN" statement structure so its very valid in this situation which is based on an "event" driven system (such as HS).

            CALL EVENT (the action that calls the below chain of tests and actions)
            IF light = ON
            THEN MAKE LED = GREEN
            ELSE IF light = OFF
            THEN make LED = RED

            The above explains a chain of basic IF / THEN / ELSE statements, the "chain" is only ever called once (there is no loop), and only ONE "THEN" statement is actioned, as IF light = ON then the "ELSE" statement never gets called, such as if the light = DIM (neither ON or OFF) then nothing happens, the above chain ends with no action.

            Ive yet to read your links, however the above is very basic logic methods and would surprise me if HS did not support this. The above would negate the need to have multiple IF THEN events which would over complicate a event / logic driven program.
            It is a little nuanced. The real logic is:

            IF light changes and becomes ON
            THEN MAKE LED = GREEN
            ELSE IF light changes and becomes OFF
            THEN make LED = RED

            HomeSeer's event engine can't do that. I understand your desire, but I am not convinced that it is more complicated to have multiple paths within an event vs multiple events. Regardless, you can't do it the way you want to, but you can do this:

            Event 1
            IF light changes and becomes ON
            THEN MAKE LED = GREEN

            Event 2
            IF light changes and becomes OFF
            THEN make LED = RED

            The only difference is that it is in two containers instead of one.
            HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

            Comment


              #7
              Originally posted by SFX Group View Post
              Kind of worried about that, it appeared to be a "this happened, do this" rather than a "this happened, heres some nice items to test, and based on the outcome do this, OR this, OR this".

              I basically was trying to create a subroutine that would test the light and based on that do something with an LED, that would have been called from every light change event, however it appears the LED status will need to be actioned in every light change If / THEN area event rather than have ONE routine to do it for me.
              I don't think it's anything to worry about. I've been using HS for over 15 years and that's the way it has been designed and works fine. Just create event groups and name the events so that you can follow the logic.

              Cheers
              Al
              HS 4.2.8.0: 2134 Devices 1252 Events
              Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

              Comment


                #8
                Originally posted by SFX Group View Post
                Kind of worried about that, it appeared to be a "this happened, do this" rather than a "this happened, heres some nice items to test, and based on the outcome do this, OR this, OR this".

                I basically was trying to create a subroutine that would test the light and based on that do something with an LED, that would have been called from every light change event, however it appears the LED status will need to be actioned in every light change If / THEN area event rather than have ONE routine to do it for me.
                As inelegant as it might seem you can do this with events as follows

                Event 1
                IF the light has a value that just changed
                THEN If the event conditions are true run event 2
                THEN If the event conditions are true run event 3

                Event 2
                IF This event is manually triggered
                AND IF the light is ON
                THEN Set LED to green

                Event 3
                IF This event is manually triggered
                AND IF the light is OFF
                THEN Set LED to red

                It may not work the way you want it to, but the design is what it is and is capable of doing almost anything you ask of it.
                HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

                Comment


                  #9
                  Originally posted by rprade View Post
                  The only difference is that it is in two containers instead of one.
                  This will be re-visited when i start looking at the logic path, as it means chain calling events, you say "no big deal" when you have 200 NODES with 3 events for each item, you have 600 events, that doesn't sound like your going to keep track of it.

                  When in real life if 100 of those devices are the same, i could have ONE for each item, ive dropped the count by a factor of 3, makes tracking events way easier.

                  When you have written code, your goal is to keep all events to a minimum and "function call" as much as possible. However i need to test what i have seen above and see how this all sits.

                  The amount of time this will take could mean i move to a Pharos LPC2 Controller, although more expensive (about $2000) might be cheaper as i spend 4 weeks less writing code for it. Its logic and integration is astounding.

                  Thanks for the input.

                  Comment


                    #10
                    Originally posted by SFX Group View Post
                    This will be re-visited when i start looking at the logic path, as it means chain calling events, you say "no big deal" when you have 200 NODES with 3 events for each item, you have 600 events, that doesn't sound like your going to keep track of it.

                    When in real life if 100 of those devices are the same, i could have ONE for each item, ive dropped the count by a factor of 3, makes tracking events way easier.

                    When you have written code, your goal is to keep all events to a minimum and "function call" as much as possible. However i need to test what i have seen above and see how this all sits.

                    The amount of time this will take could mean i move to a Pharos LPC2 Controller, although more expensive (about $2000) might be cheaper as i spend 4 weeks less writing code for it. Its logic and integration is astounding.
                    If you have 100 that are the same, then a single event based upon the change of each device passing parameters to a short script controlling the LED would be the answer. If you have 100 items affecting 100 different LEDs then you would need to pass two parameters to a common script.

                    While I try to avoid scripting, the situation you describe is a perfect place to use a short script.

                    And I know about managing a bunch of devices and events - it is daunting at times. Currently I am at:

                    Number of Devices: 1378
                    Number of Events: 1329
                    HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

                    Comment


                      #11
                      HOW TO? - Have multiple If/THEN statements in one event

                      You can create a script that you can do your else in and pass the values thru it. One event created to reference the same script and pass the values.

                      I do this for a few things and it works fine. Mainly for my energy monitoring I do for every device.

                      The event engine is powerful, best I have seen in any home automation software. But some things I am learning are better to do with scrpits, especially when you have to do the same thing to multiple devices.

                      Comment


                        #12
                        Originally posted by rprade View Post
                        If you have 100 items affecting 100 different LEDs then you would need to pass two parameters to a common script.
                        Number of Devices: 1378
                        Number of Events: 1329
                        I'll look in to this, as it appears i'll need to write the same set of actions to multiple items, a lot of mouse clicks. Should i go down this road, i'll open a new thread.

                        Comment


                          #13
                          Hi

                          I have a further question, based on the above, the below works, except DIM% (if i set DIM to 50% in the event it works at 50%, if i remove and have no DIM% (no tick box) then YELLOW does not work.

                          This works and i have one EVENT GROUP per device for its global status LEDs, however any ideas on the below DIM % thing?

                          Single EVENT with multiple events names:

                          Event : GREEN
                          This device had is value set to = ON
                          RED = OFF
                          GREEN = ON
                          BLUE = OFF

                          Event : RED
                          This device had is value set to = OFF
                          RED = ON
                          GREEN = OFF
                          BLUE = OFF

                          Event : YELLOW (doesn't work)
                          This device had is value set to = DIM% (no value set)
                          RED = ON
                          GREEN = ON
                          BLUE = OFF


                          As i bug fix to the above, YELLOW has been set to:

                          Event : YELLOW
                          This device had is value set and not equal to OFF
                          This device had is value set and not equal to ON
                          RED = ON
                          GREEN = ON
                          BLUE = OFF
                          Last edited by SFX Group; April 21, 2016, 12:40 AM.

                          Comment


                            #14
                            Originally posted by phsubscribenl
                            Well written/explained.
                            In the hopes of reducing load to system, I sometimes make the current device state a condition of the trigger. For example, If "Motion becomes On" and "Desk Lamp is OFF", then "Turn Desk Lamp on".

                            Do events evaluate Conditions prior to the Triggers? It seems if a Condition is not met then why spend the CPU cycles on capturing the trigger?

                            Am I over-thinking this or is there any merit in attempting to reduce CPU load via condition testing?

                            Thanks!
                            Since on one answered this, I will (albeit 4 years later). No, the event can only be raised by a single trigger, not by conditions. There are far more conditions in everyone's event engine than triggers. Watching 300 triggers versus 1500 conditions would be, well illogical. How would it know what to do or when to do it. An event has to first be triggered...
                            HS4 Pro Edition 4.2.5.0 running on Lenovo ThinkCenter & Debian Linux
                            Plugins: Z-Wave (via Nortek USB stick

                            Home Assistant 2021.10.6 running on HA "Blue" ODROID-N2
                            Add-ons: Android Debug Bridge, Duck DNS, ESPHome, File Editor, Glances, HA Google Drive Backup, InfluxDB, Log Viewer, MariaDB, Mosquitto broker, NGINX SSL Proxy, Node-RED, Portainer, SSH & Web Terminal, Samba, TasmoAdmin, UniFi Controller, Visual Studio Code, WireGuard, Zigbee2mqtt, Z-Wave JS to MQTT
                            Integrations: AccuWeather, Alexa Media Player, Glances, Google Nest, HACS, HomeSeer, Insteon, IPP, Life360, Local IP, Logitech Harmony Hub, Mobile App, MQTT, My Garage, OpenWeather, Spotify, Tuya Local. Ubiquiti UniFi, Z-Wave JS
                            Insteon: 2413S Dual Band PLM
                            Zigbee: zzh! CC2652R Rev A
                            Z-Wave: RaZberry daughtercard on RPi 1B via ser2net

                            Comment


                              #15
                              The easiest way I've found to implement IF, THEN, ELSE, is using the EasyTrigger plugin with "Set device to expression", implementing nested IF statements and replacement variables. I have one event that periodically adjusts the speed of my fan at night based on the temperature in the room. $$DVR:246: is my Ecobee temperature sensor that sits in my bedroom. This combines what would be at least 4 events into 1.

                              Click image for larger version

Name:	Screen Shot 2021-02-15 at 4.59.35 PM.png
Views:	181
Size:	97.7 KB
ID:	1456500
                              Attached Files

                              Comment

                              Working...
                              X