Announcement

Collapse
No announcement yet.

How to determine if tomorrow is not a school day?

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

    #31
    Originally posted by jon00 View Post
    I'm not sure what you mean by dynamically? The text file is used for exception dates only. Without any entries in the file, running the script on a Sun-Thur would mark the virtual device as a school day (tomorrow).
    What I would like is for the script to calculate the observed dates for New Years, Memorial Day, Fourth of July, Labor Day, Thanksgiving Day and the following day and Christmas. These would be calculated for any given year we are in.

    Then, the only exception dates would be in addition to these days and would be in the txt file.

    Is this possible?
    Last edited by Rvtravlr; December 18, 2017, 11:54 PM.
    Michael

    Comment


      #32
      I'm sure its possible but calculating holiday dates on a yearly basis is not a quick script change.

      All this work has been done before so checkout the following threads:

      https://forums.homeseer.com/showpost...03&postcount=2

      https://forums.homeseer.com/showthread.php?t=179143
      Jon

      Comment


        #33
        Thanks
        Michael

        Comment


          #34
          Originally posted by jon00 View Post
          You have to put the day before the text file i.e. if tomorrow is not a school day, the date entered would be today 12/17/2017.

          The script can be modified to use the actual day if you want.

          Change the line:

          If DateTime.Now.ToString.Contains(Data) Then

          To

          If DateTime.Now.AddDays(1).ToString.Contains(Data) Then
          Hi Jon00,
          I added this line to the script, and it did seem to work, all week, until Friday, when running the script should have resulted in "NO SCHOOL Tomorrow"
          The script still thinks Saturday is a school day.

          Do you think this little change to the script is throwing off the weekends?

          Comment


            #35
            Odd, I cannot see how that could happen unless there is a match in the text file.

            I've added some debug code to the script.

            If it happens again, post the debug entries so we can see where the problem lies:

            Code:
            Imports System.IO
            
                Sub Main(ByVal Parm As Object)
            
                    Try
                        Dim Path As String = ""
                        Dim FileReader As StreamReader
                        Dim Data As String = ""
                        Dim DayOfWeek As Integer
                        Dim SchoolDayTomorrow As Boolean = True
                        Dim DVRef As Integer = 8668
            
            
                        Path = hs.GetAppPath & "\data\NoSchoolTomorrowDates.txt"
                        FileReader = New StreamReader(Path)
                        DayOfWeek = DateTime.Now.DayOfWeek
            
                        Select Case DayOfWeek
                            Case 1 To 5 'Sunday To Thursday
                                SchoolDayTomorrow = True
                            Case 6 To 7 ' Friday & Saturday
                                SchoolDayTomorrow = False
                        End Select
                        hs.Writelog("Debug", "Day of Week: " & DayofWeek)
                        hs.Writelog("Debug", "School Tomorrow1: " & SchoolDayTomorrow)
                        Do While FileReader.Peek >= 0
                            Data = FileReader.ReadLine()
                            If Data <> "" Then
                                If DateTime.Now.AddDays(1).ToString.Contains(Data) Then
                                    hs.Writelog("Debug", "Match in text file: " & DateTime.Now.AddDays(1).ToString & " " & Data)
                                    SchoolDayTomorrow = False
                                    Exit Do
                                End If
                            End If
                        Loop
                        FileReader.Close()
                        hs.Writelog("Debug", "School Tomorrow2: " & SchoolDayTomorrow)
            
                        If hs.DeviceExistsRef(DvRef) Then
                            If SchoolDayTomorrow Then
                                hs.SetDeviceValueByRef(DvRef, 1, True)
                                hs.SetDeviceString(DVref, "School Tomorrow", True)
                            Else
                                hs.SetDeviceValueByRef(DvRef, 0, True)
                                hs.SetDeviceString(DVref, "No School Tomorrow", True)
                            End If
                        End If
            
                    Catch Ex As Exception
                        hs.WriteLog("Error", "Error in SchoolTomorrow.vb: " & Ex.ToString)
                    End Try
                End Sub
            Jon

            Comment


              #36
              Thanks Jon00,
              I replaced the original script, with the debugging script. Changed (8668) to my device number of (336), and saved it as version 2.

              I have an event set up to run the script at 5pm, every day. That same event sends me a text, with the newly updated device value. (School Tomorrow / No School Tomorrow).

              I verified the date 12-23-2017(Saturday) was NOT in the list of dates.
              Before I changed the script, I manually ran it today, (Saturday, 12/23/2017), and the script did correctly decide that tomorrow (Sunday 12/24/2017) was not a school day.

              It seems it only made the mistake on Friday, when looking at Saturday.

              Kids are out of school now for 2 weeks, so it will be a little while before the script should change back to (School Tomorrow)

              Comment


                #37
                When you ran it today (sat), what day of the week number did it display in the log?
                Jon

                Comment


                  #38
                  Originally posted by jon00 View Post
                  When you ran it today (sat), what day of the week number did it display in the log?
                  This is what is in the log when I ran the event manually

                  Dec-23 3:12:02 PM email Email successfully sent......
                  Dec-23 3:12:00 PM Event Event Trigger "Email Routines - Xymon School - Email Notification"
                  Dec-23 3:11:55 PM Debug School Tomorrow2: False
                  Dec-23 3:11:55 PM Debug School Tomorrow1: False
                  Dec-23 3:11:55 PM Debug Day of Week: 6
                  Dec-23 3:11:55 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/SchoolTomorrow-v2.vb
                  Dec-23 3:11:55 PM Event Event Trigger "Xymon Routines School Tomorrow / No School Tomorrow"
                  Dec-23 3:11:55 PM Event Event Xymon Routines School Tomorrow / No School Tomorrow triggered by the event page 'Run' button.
                  Dec-23 3:11:43 PM Device Control Device: Floor-2 Xymon's Bedroom School Tomorrow (yes/no) to On (1) by/from: CAPI Control Handler
                  Dec-23 3:10:39 PM email Email successfully sent......
                  Dec-23 3:10:38 PM Event Event Trigger "Email Routines - Xymon School - Email Notification"
                  Dec-23 3:10:33 PM Debug School Tomorrow2: False
                  Dec-23 3:10:33 PM Debug School Tomorrow1: False
                  Dec-23 3:10:33 PM Debug Day of Week: 6
                  Dec-23 3:10:32 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/SchoolTomorrow-v2.vb
                  Dec-23 3:10:32 PM Event Event Trigger "Xymon Routines School Tomorrow / No School Tomorrow"
                  Dec-23 3:10:32 PM Event Event Xymon Routines School Tomorrow / No School Tomorrow triggered by the event page 'Run' button.


                  Does that help?

                  OK, that is the full log....

                  Comment


                    #39
                    Thanks,

                    It looks like your Day of week starts on a Monday rather than Sunday.

                    Change:

                    Code:
                                Select Case DayOfWeek
                                    Case 1 To 5 'Sunday To Thursday
                                        SchoolDayTomorrow = True
                                    Case 6 To 7 ' Friday & Saturday
                                        SchoolDayTomorrow = False
                                End Select
                    To

                    Code:
                                Select Case DayOfWeek
                                    Case 5 To 6 ' Friday & Saturday
                                        SchoolDayTomorrow = False
                                    Case Else
                                        SchoolDayTomorrow = True
                                End Select
                    Jon

                    Comment

                    Working...
                    X