Announcement

Collapse
No announcement yet.

Sequence of events 15 min apart

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

  • puma
    replied
    jon00

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

    Leave a comment:


  • jon00
    replied
    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

    Leave a comment:


  • puma
    replied
    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)

    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
    jon00

    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.

    Regards,

    Leave a comment:


  • puma
    replied
    Implemented everything per jon00 instructions above. Direct messaging with Big6 and Slack. No crappy Verizon service. Works like a charm.

    Thanks again Jon.

    Best,

    puma

    Leave a comment:


  • puma
    replied
    Understood. Will play with it and let everyone know how it paned out.

    Thanks a lot for the cooperation.

    Leave a comment:


  • jon00
    replied
    A global variable can store anything......

    Leave a comment:


  • puma
    replied
    It says here https://help.homeseer.com/help/HS3/s...ment_variables that

    $$GLOBALVAR passes along the value of the variable whereas it passes the string in your example. Will it work ?

    Leave a comment:


  • jon00
    replied
    I would use a global variable which stores information in memory:

    Under Ref = 3610 add:

    Code:
    hs.CreateVar("zoneinfo")
    Then instead of the email code lines, you would save your text to the global variable. Example:

    Code:
    hs.SaveVar("zoneinfo","Zone ON FAILED:" & ZoneNumber)
    Then use the global replacement variable in your event message:

    Code:
    $$GLOBALVAR[B]:[/B]zoneinfo[B]:[/B]
    In the example given it would display Zone ON FAILED: 2 for zone 2


    This all depends if global variables are supported by the plugin you are using to push the message.

    Leave a comment:


  • puma
    replied
    jon00

    Thanks a lot. I can certainly manage the event triggering. Still not clear to me how to pass the value of the script's variable "Zone Number" to the event. If we forget about the plug-in and assume that "Zone Number" needs to dim a dimmer that is HS4 device and has range from 0 to 100. How do I do that?

    Leave a comment:


  • jon00
    replied
    Delays in received text messages sent via email has been reported many times on this board.

    It's easy to trigger an event from a script. You just use:

    Code:
    hs.Triggerevent ("StartMessage")
    
    hs.Triggerevent ("StopMessage")
    To pass information to an event, you need the plugin you are using to accept Replacement Variables You need to find out/test if they can be used (use $date in the message to see if you see the actual date).

    Some plugins such as pushover notifications (referring to the original one) can be operated directly via a script command.

    Leave a comment:


  • puma
    replied
    jon00

    I can use alternative messaging. In order to do so I need for you to call two special events in lieu of current email sending

    StartMessage
    StopMessage

    and somehow to pass the Zone Number to these events. Unless you know of a better way, just put Zone Number as a value in HS4 device created for this very purpose with ref#3620.

    Leave a comment:


  • puma
    replied
    jon00

    ... wait I just received 2 of the missing messages with delay. One is still missing but this is a good indication that the problem is with Verizon.

    edited later: I received the last message from Verizon with 30+ minutes delay. Wondering if Verizon has problems today as I've never seen such delays before, but I'm not a regular Verizon text messaging user either.

    Leave a comment:


  • puma
    replied
    jon00

    This one works better as it reports both start and stop in HS4 logs. However it skipped 3 out of six messages. It could be Verizon's problem but the original script never skipped messages. Could be some timing issue as well. Attached is screen shot from my iPhone of the messages that I received.

    Testing pattern 17/1, 18/1, 27/1

    HS4 log (in reverse order)
    12/10/2021 10:49:34 AM


    Script
    IrrbyText
    Stopping Zone: 27
    12/10/2021 10:48:34 AM


    Script
    IrrbyText
    Starting Zone: 27
    12/10/2021 10:48:14 AM


    Script
    IrrbyText
    Stopping Zone: 18
    12/10/2021 10:47:14 AM


    Script
    IrrbyText
    Starting Zone: 18
    12/10/2021 10:46:54 AM


    Script
    IrrbyText
    Stopping Zone: 17
    12/10/2021 10:45:54 AM


    Script
    IrrbyText
    Starting Zone: 17

    Click image for larger version

Name:	Screenshot 2021-12-10 at 11.04.33 AM.png
Views:	149
Size:	407.5 KB
ID:	1513372

    Leave a comment:


  • jon00
    replied
    Please try the following script (don't modify your existing).

    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)
                    hs.SendEmail("77777777777@vtext.com", "homeseer", "", "", "Irrigation", "Zone STOPPED:" & ZoneNumber, "")
    
                    Result = hs.GetURL("192.168.1.202", "/control?sta=" & ZoneNumber & "&time=0&action=OFF", False, 80)
                    hs.WriteLog("IrrbyText", "Controller Off Response: " & Result)
                    If Result = "" Then hs.SendEmail("7777777777777@vtext.com", "homeseer", "", "", "Irrigation", "Zone OFF FAILED:" & ZoneNumber, "")
    
    
                    ' ******************************************
    
                    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)
                        hs.SendEmail("7777777777777@vtext.com", "homeseer", "", "", "Irrigation", "Zone STARTED:" & ZoneNumber, "")
    
                        Result = hs.GetURL("192.168.1.202", "/control?sta=" & ZoneNumber & "&time=" & ZoneMins, False, 80)
                        hs.WriteLog("IrrbyText", "Controller On Response: " & Result)
                        If Result = "" Then hs.SendEmail("7777777777777@vtext.com", "homeseer", "", "", "Irrigation", "Zone ON FAILED:" & ZoneNumber, "")
    
                        ' ******************************************
    
                    End If
                End If
            Catch Ex As Exception
                hs.WriteLog("Error", "Error in Irrigation Zone Control: " & Ex.ToString)
            End Try
        End Sub

    Leave a comment:


  • puma
    replied
    Yes, the old version works well with everything proper log and proper messaging. Here is the script with my phone number masked

    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.WriteLog("IrrbyText", "Stopping Zone: " & ZoneNumber)
    hs.SendEmail("77777777777@vtext.com", "homeseer", "", "", "Irrigation", "Zone STOPPED:" & ZoneNumber, "")
    
    ' ******************************************
    
    hs.TimerReset("IrrigationRC")
    hs.CounterIncrement("IrrigationRC")
    
    Else
    If Start = Count Then
    hs.CounterIncrement("IrrigationStart")
    hs.WriteLog("IrrbyText", "Starting Zone: " & ZoneNumber)
    hs.SendEmail("7777777777777@vtext.com", "homeseer", "", "", "Irrigation", "Zone STARTED:" & 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

    Leave a comment:

Working...
X