No announcement yet.

Sequence of events 15 min apart

  • Filter
  • Time
  • Show
Clear All
new posts

    Originally posted by jon00 View Post
    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)


    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.

     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 = ""
    ' 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)
    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
    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("", "/control?sta=" & ZoneNumber & "&time=0&action=OFF", False, 80)
    ' ******************************************
    If Start = Count Then
    hs.WriteLog("Test", "Starting Zone: " & ZoneNumber)
    ' ****** Code to Trigger Zone ON below *****
    hs.GetURL("", "/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

    Thanks again for the script. It runs great and keeps my wife happy with her irrigation chores. I followed your recommendations above and use the value as a trigger to the recurring event so that it doesn't trigger every 20 sec. all the time but only as needed. "As needed" however means 3 - 4 hours per day. HS4 log is clogged by messages about irrigation script running every 20 sec. during that time and 20 sec. recurring event adds to the workload of HS4.

    I was wondering if you can make this 20 sec. (or less) cycle internal within the script so that I don't need to run the script every 20 sec. from HS4 event.
    I can take care of starting the script appropriately when the message arrives and the script is self sufficient to "know" when to stop after completion of a task.



      Using the Event engine is the most efficient use of HS resources and running scripts continuously over a long period of time is not recommended.

      My advice is to leave it as-is but disable logging for the event. Just go to the advanced options under the script action and tick the do not log checkbox.

      Click image for larger version

Name:	Capture.PNG
Views:	93
Size:	34.9 KB
ID:	1523304



        ​​​​​​​Thanks for the prompt response. Will do.