Announcement

Collapse
No announcement yet.

if-then-never

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

    if-then-never

    With 40yrs of programming I will not belabor the point that "else" logic is a requirement for tight code. Trying to figure out how to use the events GUI to toggle a z-wave door lock from a manual trigger has been frustrating.

    I have looked everywhere on this forum and I even RTFM.

    What does "never" do?
    Thanks
    Rod

    #2
    I think this has come up a few times. After a quick search this is one of the posts on it.

    http://board.homeseer.com/showthread.php?t=163818

    Jeff

    Comment


      #3
      FWIW, one way to use events to accomplish if-then-else logic is with three events.
      - The first event triggers the other two, checking their conditions.
      - One of those events has the If conditions.
      - The other has the inverse conditions.

      The approach can be extended to simulate select-case logic as well.

      The biggest drawback I've found is that the 'else' event conditions can be a challenge to craft in some cases.

      A script is usually much easier to construct and maintain.
      Mike____________________________________________________________ __________________
      HS3 Pro Edition 3.0.0.548, NUC i3

      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

      Comment


        #4
        Originally posted by rnzone View Post
        With 40yrs of programming I will not belabor the point that "else" logic is a requirement for tight code. Trying to figure out how to use the events GUI to toggle a z-wave door lock from a manual trigger has been frustrating.

        I have looked everywhere on this forum and I even RTFM.
        The "lack" of Else has been discussed many times before. As an example:

        If Light Changes to ON
        Then Do Something
        Else Do Something else

        In this case the Else would continually trigger if Light was Off. If it was available like that, it would get a lot of people in trouble with events triggering over and over again. Therefore HST set it up so that you would have to use a second event to accomplish the Else piece. It's there, just a different way of doing it.

        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
          As Jeff posted, "never" is a means of disabling an action without removing it from an event for the purposes of testing, troubleshooting or temporarily altering an event.

          As Al said, it would be pointless to have an else on a trigger. Since a trigger is a "moment in time", an else on a trigger would always be true if not at that moment in time. It is useful and possible to have an else on actions.

          Say you would like to:
          At sunset
          If the house is occupied turn the Driveway lights on and the front entry lights off
          Else turn the front entry lights on and the driveway lights off.


          This can be done easily by nesting events as in the screenshot below. The first event is the sunset trigger, the second event is the "if" and the third is the "else".

          Edit: I missed Uncle Michael's reply, saying exactly what I posted. Sorry for the redundancy, but now there are pictures
          .
          Attached Files
          Last edited by randy; March 24, 2016, 02:32 PM.
          HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

          Comment


            #6
            Originally posted by rnzone View Post
            With 40yrs of programming I will not belabor the point that "else" logic is a requirement for tight code. Trying to figure out how to use the events GUI to toggle a z-wave door lock from a manual trigger has been frustrating.

            I have looked everywhere on this forum and I even RTFM.

            What does "never" do?
            Thanks
            Rod
            I can't for the life of me think why you would ever want a toggle a door lock in an event.
            https://forums.homeseer.com/forum/de...plifier-plugin

            Comment


              #7
              haapnatious - I can't understand why you want a red car. Your comment is not productive. But, thanks for reading my post.

              I have 258 HS devices configured. I might be doing something outside the box. I am migrating from HAI, and Castle to HS.

              I have a HStouch icon that shows the state of the z-wave door on my home screen. If i want it flipped (locked or unlocked) i simply press the status image. I can instantly see the door status and change it with a press.

              rprade - Thanks for the clarification "never". Yes, I absolutely want to execute based on a moment in time since my trigger variable is the variable that I am going to change. Now I need to register my variable/ create pointer so I can track it through the stack.

              Also found out z-wave is not 999.99 and the instant status was imperative.

              I reverted to a lame hack to get this to work within the GUI.
              Screens attached.

              Thank you all for the prompt and helpful responses.
              Rod
              Attached Files

              Comment


                #8
                I was actually sincere when I stated -
                "Thank you all for the prompt and helpful responses."

                I started off with the red car and it probably sent the wrong tone via text.
                I am sure that within the 1000 posts there are some gems in there.

                I purchased the product a couple of weeks ago and I appreciate the assistance.

                My interpretive code is a hack and if anyone has another solution I would love to see it.

                Peace -
                rod

                Comment


                  #9
                  Originally posted by rnzone View Post
                  I was actually sincere when I stated -
                  "Thank you all for the prompt and helpful responses."

                  I started off with the red car and it probably sent the wrong tone via text.
                  I am sure that within the 1000 posts there are some gems in there.

                  I purchased the product a couple of weeks ago and I appreciate the assistance.

                  My interpretive code is a hack and if anyone has another solution I would love to see it.

                  Peace -
                  rod
                  I understand, it can get frustrating during the learning curve. If you could post exactly what you want to do, I'm sure one of us could get you pointed in the right direction.
                  HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

                  Comment


                    #10
                    Hi Rod,

                    I took a look at your PDF and not sure what the counter is intended to be used for. There should be no need to a counter for a toggle function, just the current state of the lock should be sufficient. It looks like you're on the right track, but should be able to simplify:

                    Event 1. Manually triggered and called by your HS Touch button. Actions are to run Events 2 and 3, respecting their conditions.

                    Event 2. Manually triggered with a condition of the door being unlocked. Action is to lock the door.

                    Event 3. Manually triggered with a condition of the door being locked. Action is to unlock the door.

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

                    Comment


                      #11
                      An alternate approach is to use a single event and a script. Here's a script I use to toggle lights on/off:

                      Code:
                      Sub Main(ByVal theDevice As String)
                      	' Toggle the Specified Device ON/OFF
                      	' DIM is considered ON
                      	' Specify the Device ID as the Parameter
                      	Dim devValue As Double
                      
                      	' Get the Device Status
                      	devValue = hs.DeviceValue(theDevice)
                      	' Toggle it
                      	Select Case devValue
                      		Case Is > 0
                      		' Device ON or DIM, turn it OFF
                      		hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,true ,"off",false,true))
                      		Case 0
                      		' Device OFF, turn it ON
                      		hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,true ,"on",false,true))
                      	End Select
                      End Sub
                      It could easily be modified to control a lock (by changing the "on" and "off" strings to the correct strings for the lock "lock" and "unlock").

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

                      Comment


                        #12
                        I think Al has perhaps the best approach with the Script, but if you want to do it purely with events, I believe this will do what you want (image attached).
                        Attached Files

                        Comment


                          #13
                          Thanks sparkman - given the lackadaisical documentation on the basics of system I am not ready to jump into scripting. Once I get the basics working I will be balz deep in coding.

                          I tried that yesterday sirmeili and the log file showed 'toggle lock' executed 3 consecutive, looping, times and the last to run event was always true hence i used the counter to track it. Maybe I did something wrong on my first pass at it. I will try it again.

                          Comment


                            #14
                            Originally posted by rnzone View Post
                            Thanks sparkman - given the lackadaisical documentation on the basics of system I am not ready to jump into scripting. Once I get the basics working I will be balz deep in coding.

                            I tried that yesterday sirmeili and the log file showed 'toggle lock' executed 3 consecutive, looping, times and the last to run event was always true hence i used the counter to track it. Maybe I did something wrong on my first pass at it. I will try it again.
                            Now that I think of it, yes, it will cause issues. it will run one than the other so it will either lock -> unlock or just unlock

                            Let me ponder on it.

                            Comment


                              #15
                              Ok, so I haven't tested this, but see if this works.


                              Delay the first one by 1 second. If the second one goes through, cancel the delay of the first one.. .otherwise the first one will still run 1 second later. I've attached an image. Perhaps someone can tell me if this is crazy or genius! LOL

                              I've attached an image of the modified events (i've circled my changes).

                              Edit: note that Al's script will simplify this greatly. I will see if I can modify the script to work with a lock.
                              Attached Files

                              Comment

                              Working...
                              X