Announcement

Collapse
No announcement yet.

Sequence of events 15 min apart

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

    Sequence of events 15 min apart

    Can someone help me creating sequence of HS4 events 15 min apart.

    It's about irrigation of several zones one after another.

    Here is what I have

    HS4 device - IrrigationZone holding zone number as value
    HS4 device - IrrigationTime holding irrigation time as value
    HSTouch interface allowing manual selection of Zone and Time and run "Start irrigation" HS4 event.
    Messaging service (bidirectional) in/out using Big6 PI and Slack
    HS4 event - "Start irrigation" - it will take the time and zone from above devices and run irrigation until time expires. Stops thereafter.
    HS4 event "Stop irrigation" - it is for manual use only if user wants to stop irrigation before time expires.

    Here is what I want to accomplish.

    a) simple plan

    Send a text message to HS4 like this

    7, 11, 14, 25, 2, 14, 3

    HS4 would irrigate each of the zones in the list for the pre-set time (typically 15 min).

    b) more complex plan

    7/15, 11/10, 14/5, 25/7, 2/11, 14/5, 3/10

    needless to say the idea here is for each zone to be followed by the time

    the number of zones that need irrigation will vary from 1 to say 16

    BTW parsing the above sequences is not a problem as Big6 can do that along with the receiving of the text message from Slack. Each one of the above values can be put in a dedicated HS4 device.

    #2
    Personally I would not "home automate" an irrigation system. Many systems have rain measurement systems built in (mine isn't very reliable, though) and they can be programmed as needed. In my opinion it is a bigger hassle to do this through HS than through the system itself. Email doesn't go through and you have an issue. Email authentication changes and you have a problem. Your network has a problem and it doesn't work, etc. So my recommendation is that you program your irrigation through your irrigation controller and then when you want to override it for some reason you do it through a plugin for your controller (assuming there is one).

    Comment


      #3
      My wife is the gardener and this is what she wants. Yes, I'm aware of the scheduling capabilities of the irrigation controller as well as rain sensors, link to weather services etc. My wife though doesn't like any of these. She walks around and touches the soil and decides individually per zone what to do.

      Comment


        #4
        I'm not sure what you are doing. Is HS sending a message or receiving it?

        To sequence events, the most direct approach would be to have a master event that runs the rest.
        If [this event is triggered]
        Then Run event 1 after a delay of 15 min
        Then Run event 2 after a delay of 30 min
        Then Run event 3 after a delay of 45 min
        . . .
        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


          #5
          Uncle Michael
          Thanks for the input. ​​​​​​​I said above "send text message to HS4" , which means that HS4 is receiving the text message that will contain the instructions of what to do as outlined above.
          With that said, your proposal makes a lot of sense. I see one problem though - it is a rigid structure. How to make it flexible to execute anywhere from 1 to 16 events depending on the input.

          Comment


            #6
            This one is a bit of a brain teaser. I cannot see a way to do this with events so I spent a bit of time trying to write a script to do this.

            I don't know your exact setup but you should be able to move forward with this code.

            1) Create a Counter called "Irrigation"
            2) Create a second Counter called "IrrigationStart"
            3) Create a timer called "Irrigation"
            4) Create a status only virtual device and store the incoming text message as a device string.
            5) Take a note of its device reference number
            6) Copy the script below and place in your scripts directory. Call it what you like with a .vb extension
            7) Change the Ref = 1234 with the Reference number of your device.
            8) Create a recurring event to run the script every 20 seconds

            On its own, it will only show messages in the log when a zone is triggered on/off.

            If you send a text message and it gets saved to the device string, it will work through the zones/times (to the nearest 20 seconds) and when complete, will clear the device string; ready for the next text message.

            If this all works for you, then it just needs a bit of work to trigger your actual events. Their names would be useful!


            Code:
                Sub Main(ByVal Direction As String)
            
                    Dim ts As TimeSpan
                    Dim Ref As Integer
                    Dim ZoneData As String = ""
                    Dim ZoneNumber As String = ""
                    Dim ZoneMins As String = ""
                    Dim Count As Double
                    Dim Start As Double
                    Dim Zones() As String
                    Dim TextMessage As String = ""
            
                    Try
                        ' Set the reference number of the device that contains the text message as a string
                        Ref = 1234
            
                        ' Get the zone/duration string
                        TextMessage = hs.DeviceString(Ref)
            
                        ' If device string is empty, exit the sub
                        If TextMessage = "" Then Exit Sub
            
            
                        Zones = TextMessage.Split(",")
            
                        Start = hs.CounterValue("IrrigationStart")
                        Count = hs.CounterValue("Irrigation")
            
                        If Count > Zones.GetUpperBound(0) Then ' No more data to process
                            hs.WriteLog("Test", "No more data - Exit")
                            ' Set devicestring to empty
                            hs.SetDeviceString(Ref, "", False)
                            hs.CounterReset("Irrigation")
                            hs.CounterReset("IrrigationStart")
                            Exit Sub
                        End If
            
                        If Start = 0 Then hs.TimerReset("Irrigation")
            
                        ts = hs.TimerValue("Irrigation")
            
                        ZoneData = Zones(Count).Trim
                        ZoneNumber = ZoneData.Substring(0, ZoneData.IndexOf("/")).Trim
                        ZoneMins = ZoneData.Substring(ZoneData.IndexOf("/") + 1).Trim
            
                        If ts.TotalSeconds >= CInt(ZoneMins) * 60 Then
                            hs.WriteLog("Test", "Stop Zone " & ZoneNumber)
            
                            ' ****** Code to Trigger Zone OFF below *****
            
                            ' hs.TriggerEvent("ZoneOff" & ZoneNumber)
            
                            ' ******************************************
            
                            hs.TimerReset("Irrigation")
                            hs.CounterIncrement("Irrigation")
                        Else
                            If Start = Count Then
                                hs.CounterIncrement("IrrigationStart")
                                hs.WriteLog("Test", "Start Zone " & ZoneNumber)
            
                                ' ****** Code to Trigger Zone ON below *****
            
                                ' hs.TriggerEvent("ZoneOn" & ZoneNumber)
            
                                ' ******************************************
            
                            End If
                        End If
                    Catch Ex As Exception
                        hs.WriteLog("Error", "Error in Irrigation Zone Control: " & Ex.ToString)
                    End Try
                End Sub
            Jon

            Comment


              #7
              jon00 This is so kind of you. I'll try it asap and let everyone know how it goes. I guess it could be adapted by others as well for different purposes than mine.

              Comment


                #8
                jon00

                P.S. I know scripting just enough to be dangerous. Would you please plug the following actions that are simply HTTP GET

                TO START Zone xx for time tt

                http://192.168.1.202/control?sta=xx&time=tt

                xx = digits from 00 to 99
                tt = digits from 1 to 99


                TO STOP Zone xx

                http://192.168.1.202/control?sta=xx&time=tt&action=OFF

                (time is irrelevant in the stop command but must be there any value from 1 to 99)

                the IP address is static I will make sure that I update the script if it ever changes.


                BTW I have created the HS4 device and tested messaging to it that works. Device ref number is 3610. Ready to test.

                Per your instructions created counters and timer but "Irrigation" was taken for the manual control so I created IrrigationRC instead.

                Counters

                IrrigationRC
                IrrigationStart

                Timer

                IrrigationRC

                Comment


                  #9
                  OK, thanks for the info. Please try the revised script with your information provided.

                  I've made the script a bit more fault tolerant and given the option not to specify the time (currently defaults to 15 min) so your wife can enter:

                  7, 11, 14, 25, 2, 14, 3 (default time is used)

                  or

                  7/15, 11/10, 14/5, 25/7, 2/11, 14/5, 3/10

                  or even:

                  7, 11/10, 14, 25, 2/5, 14/5, 3

                  When irrigation data is completed, I've also set the device value of the device holding the text message to 0. If you set this to 100 when you update the string with the zone/time data, you can use this as a condition in the recurring event to only run when this device value is set to 100.


                  The time period between a zone ending and the next zone starting will be 20 seconds (the recurring event time). If you want to reduce this, set the recurring event to run every 10 seconds.

                  Code:
                      Sub Main(ByVal Parm As String)
                  
                          Dim ts As TimeSpan
                          Dim Ref As Integer
                          Dim ZoneData As String = ""
                          Dim ZoneNumber As String = ""
                          Dim ZoneMins As String = ""
                          Dim Count As Double
                          Dim Start As Double
                          Dim Zones() As String
                          Dim TextMessage As String = ""
                          Dim DefaultTime As String = ""
                  
                          Try
                              ' Set the reference number of the device that contains the text message as a string
                              Ref = 3610
                  
                              ' Default time in minutes if no time is sent
                              DefaultTime = "15"
                  
                              ' Get the zone/duration from string
                              TextMessage = hs.DeviceString(Ref)
                  
                              ' If the device string is empty, then exit the sub
                              If TextMessage = "" Then Exit Sub
                  
                              Zones = TextMessage.Split(",")
                  
                              Start = hs.CounterValue("IrrigationStart")
                              Count = hs.CounterValue("IrrigationRC")
                  
                              If Count > Zones.GetUpperBound(0) Then ' No more data to process
                                  hs.WriteLog("Test", "No more data - Exit")
                                  ' Set devicestring to empty
                                  hs.SetDeviceString(Ref, "", False)
                                  hs.SetDeviceValueByRef(Ref, 0, True)
                                  hs.CounterReset("IrrigationRC")
                                  hs.CounterReset("IrrigationStart")
                                  Exit Sub
                              End If
                  
                              If Start = 0 Then hs.TimerReset("IrrigationRC")
                  
                              ts = hs.TimerValue("IrrigationRC")
                  
                              ZoneData = Zones(Count).Trim
                  
                              If Integer.TryParse(ZoneData, Nothing) Then
                                  'Only Zone number sent
                                  ZoneNumber = ZoneData
                                  ZoneMins = DefaultTime
                              Else
                                  ZoneNumber = ZoneData.Substring(0, ZoneData.IndexOf("/")).Trim
                                  If Not Integer.TryParse(ZoneNumber, Nothing) Then
                                      hs.Writelog("Error", "Invalid/Upspecified Zone Number " & ZoneNumber)
                                      Exit Sub
                                  End If
                  
                                  ZoneMins = ZoneData.Substring(ZoneData.IndexOf("/") + 1).Trim
                                  If Not Integer.TryParse(ZoneMins, Nothing) Then ZoneMins = DefaultTime
                              End If
                  
                              If ts.TotalSeconds >= CInt(ZoneMins) * 60 Then
                                  hs.WriteLog("Test", "Stopping Zone " & ZoneNumber)
                  
                                  ' ****** Code to Trigger Zone OFF below *****
                  
                                  hs.GetURL("192.168.1.202", "/control?sta=" & ZoneNumber & "&time=0&action=OFF", False, 80)
                  
                                  ' ******************************************
                  
                                  hs.TimerReset("IrrigationRC")
                                  hs.CounterIncrement("IrrigationRC")
                  
                              Else
                                  If Start = Count Then
                                      hs.CounterIncrement("IrrigationStart")
                                      hs.WriteLog("Test", "Starting Zone: " & ZoneNumber)
                  
                                      ' ****** Code to Trigger Zone ON below *****
                  
                                      hs.GetURL("192.168.1.202", "/control?sta=" & ZoneNumber & "&time=" & ZoneMins, False, 80)
                  
                  
                                      ' ******************************************
                  
                                  End If
                              End If
                          Catch Ex As Exception
                              hs.WriteLog("Error", "Error in Irrigation Zone Control: " & Ex.ToString)
                          End Try
                      End Sub
                  Jon

                  Comment


                    #10
                    jon00

                    Thanks a lot. This is awesome. I'm testing it now. Will report the results soon.

                    Comment


                      #11
                      jon00

                      Works like a charm :-)

                      Here is my testing pattern

                      14, 27/12, 29/17, 2

                      and here is the log (in reverse order)


                      12/8/2021 8:23:54 PM Script IrrbyText Stopping Zone: 2
                      12/8/2021 8:08:54 PM Script IrrbyText Starting Zone: 2
                      12/8/2021 8:08:34 PM Script IrrbyText Stopping Zone: 29
                      12/8/2021 7:51:34 PM Script IrrbyText Starting Zone: 29
                      12/8/2021 7:51:14 PM Script IrrbyText Stopping Zone: 27
                      12/8/2021 7:39:34 PM Script IrrbyText Starting Zone: 27
                      12/8/2021 7:39:14 PM Script IrrbyText Stopping Zone: 14
                      12/8/2021 7:24:14 PM Script IrrbyText Starting Zone: 14

                      everything works as expected. As you can see I changed the name of the log entries from "Test" to "IrrbyText" and I also added log entry for stopping as originally there was only one for starting. I also want to send notifications to my wife for starting and stopping as she doesn't look at HS logs. Verizon email to txt will be used. In order to do so I added the following lines where the HTTP GET action is

                      Code:
                      hs.SendEmail("1234567890@vtext.com", "homeseer", "", "", "Irrigation", "Zone STARTED:" & ZoneNumber, "")
                      Code:
                      hs.SendEmail("1234567890@vtext.com", "homeseer", "", "", "Irrigation", "Zone STOPPED:" & ZoneNumber, "")
                      (US users replace 1234567890 with your real Verizon 10 digit number, or find your provider's email to text service email address)

                      Comment


                        #12
                        Looks fine. The formatting is correct so won't break the script. Depending on your ISP, the MailFrom entry (shown as "homeseer") may need an actual email address.

                        You can always create a test script:

                        Code:
                            Sub Main(ByVal Parm As String)
                        
                                Dim ZoneNumber As String = "5"
                                hs.SendEmail("1234567890@vtext.com", "homeseer", "", "", "Irrigation", "Zone STOPPED:" & ZoneNumber, "")
                        
                            End Sub
                        Jon

                        Comment


                          #13
                          jon00

                          One last finishing touch to add if you don't mind.
                          Irrigation controller responds in plain text as shown below to HTTP GET command for ON and OFF (example is for zone #18 and time 11 min)

                          Code:
                          Starting zone #18 for time 11
                          Code:
                          Stopping zone #18
                          You should get the response as an indication that everything is O.K.

                          The controller does not report any exceptional conditions, however if there is no response at all than it means that the controller have lost power or WiFi connection and will not execute the command. This happens rarely but it's good to be caught if and when happens. Typically response is immediate when I test from a browser. I have no idea how long wait for a response is reasonable but shouldn't be more than 10 sec. IMHO. Correct me if you think otherwise.

                          If there is no response than it would be nice for the script to report an error in the log and send a message.

                          Thanks,
                          puma

                          Comment


                            #14
                            OK, I do not have your changes but you should be able to work with the following:

                            Code:
                            
                                Sub Main(ByVal Parm As String)
                            
                                    Dim ts As TimeSpan
                                    Dim Ref As Integer
                                    Dim ZoneData As String = ""
                                    Dim ZoneNumber As String = ""
                                    Dim ZoneMins As String = ""
                                    Dim Count As Double
                                    Dim Start As Double
                                    Dim Zones() As String
                                    Dim TextMessage As String = ""
                                    Dim DefaultTime As String = ""
                                    Dim Result As String = ""
                            
                                    Try
                                        ' Set the reference number of the device that contains the text message as a string
                                        Ref = 3610
                            
                                        ' Default time in minutes if no time is sent
                                        DefaultTime = "15"
                            
                                        ' Get the zone/duration from string
                                        TextMessage = hs.DeviceString(Ref)
                            
                                        ' If the device string is empty, then exit the sub
                                        If TextMessage = "" Then Exit Sub
                            
                                        Zones = TextMessage.Split(",")
                            
                                        Start = hs.CounterValue("IrrigationStart")
                                        Count = hs.CounterValue("IrrigationRC")
                            
                                        If Count > Zones.GetUpperBound(0) Then ' No more data to process
                                            hs.WriteLog("Test", "No more data - Exit")
                                            ' Set devicestring to empty
                                            hs.SetDeviceString(Ref, "", False)
                                            hs.SetDeviceValueByRef(Ref, 0, True)
                                            hs.CounterReset("IrrigationRC")
                                            hs.CounterReset("IrrigationStart")
                                            Exit Sub
                                        End If
                            
                                        If Start = 0 Then hs.TimerReset("IrrigationRC")
                            
                                        ts = hs.TimerValue("IrrigationRC")
                            
                                        ZoneData = Zones(Count).Trim
                            
                                        If Integer.TryParse(ZoneData, Nothing) Then
                                            'Only Zone number sent
                                            ZoneNumber = ZoneData
                                            ZoneMins = DefaultTime
                                        Else
                                            ZoneNumber = ZoneData.Substring(0, ZoneData.IndexOf("/")).Trim
                                            If Not Integer.TryParse(ZoneNumber, Nothing) Then
                                                hs.Writelog("Error", "Invalid/Upspecified Zone Number " & ZoneNumber)
                                                Exit Sub
                                            End If
                            
                                            ZoneMins = ZoneData.Substring(ZoneData.IndexOf("/") + 1).Trim
                                            If Not Integer.TryParse(ZoneMins, Nothing) Then ZoneMins = DefaultTime
                                        End If
                            
                                        If ts.TotalSeconds >= CInt(ZoneMins) * 60 Then
                            
                                            ' ****** Code to Trigger Zone OFF below *****
                            
                                            hs.WriteLog("IrrbyText", "Stopping Zone " & ZoneNumber)
                                            Result = hs.GetURL("192.168.1.202", "/control?sta=" & ZoneNumber & "&time=0&action=OFF", False, 80)
                                            hs.WriteLog("IrrbyText", "Controller response: " &  Result)
                                            If Result = "" Then
                                                hs.SendEmail("1234567890@vtext.com", "homeseer", "", "", "Irrigation", "Zone OFF FAILED: " & ZoneNumber, "")
                                            Else
                                                hs.SendEmail("1234567890@vtext.com", "homeseer", "", "", "Irrigation", "Zone STOPPED: " & ZoneNumber, "")
                                            End If
                            
                            
                                            ' ******************************************
                            
                                            hs.TimerReset("IrrigationRC")
                                            hs.CounterIncrement("IrrigationRC")
                            
                                        Else
                                            If Start = Count Then
                                                hs.CounterIncrement("IrrigationStart")
                            
                                                ' ****** Code to Trigger Zone ON below *****
                            
                                                hs.WriteLog("IrrbyText", "Starting Zone: " & ZoneNumber)
                                                Result = hs.GetURL("192.168.1.202", "/control?sta=" & ZoneNumber & "&time=" & ZoneMins, False, 80)
                                                hs.WriteLog("IrrbyText", "Controller response: " &  Result)
                                                If Result = "" Then
                                                    hs.SendEmail("1234567890@vtext.com", "homeseer", "", "", "Irrigation", "Zone ON FAILED:" & ZoneNumber, "")
                                                Else
                                                    hs.SendEmail("1234567890@vtext.com", "homeseer", "", "", "Irrigation", "Zone STARTED:" & ZoneNumber, "")
                                                End If
                            
                                                ' ******************************************
                            
                                            End If
                                        End If
                                    Catch Ex As Exception
                                        hs.WriteLog("Error", "Error in Irrigation Zone Control: " & Ex.ToString)
                                    End Try
                                End Sub
                            Jon

                            Comment


                              #15
                              jon00

                              ​​​​​​​Oooops something is wrong with this version.

                              Here is my testing pattern: 17/1, 18/2, 27/1

                              And here is the log
                              12/9/2021 10:49:34 AM Script IrrbyText Starting Zone: 27
                              12/9/2021 10:47:34 AM Script IrrbyText Starting Zone: 18
                              12/9/2021 10:45:54 AM Script IrrbyText Starting Zone: 17


                              As you can see there are no entries in the log for stop and I never got any messages neither for start nor for stop.

                              I did copy and paste the code from above and the only change that I made was to replace 1234567890 with my phone number in 4 places.

                              Comment

                              Working...
                              X