Announcement

Collapse
No announcement yet.

Device String date more than 24 hours

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

    Device String date more than 24 hours

    Hi Guys,

    Hoping someone might be able to help me with setting up a trigger, I have a device which is updated from my phone based on when a location was last received, I then use other devices to let the house know if I am home etc, anyway I was hoping I might be able to use the device below to let the user know (e.g. myself), if the device has not updated in less than 24 hours, which would then be used to prompt me to check that the app is running on my iphone through email.

    How can i set up a recurring script that looks at the string: 7/13/2013 9:42 PM, checks if it is more than 24 hours old, and if so then sends an email (but only sends one email every 24 hours). The last bit is probably the most important as I do want the script to be checking every 10 - 20 minutes etc, or on device value change so that downtime of the app is minimized, but I don't want it to end up sending an email every 10 minutes and bombarding me.

    Thanks for your help


    7/13/2013 9:42 PM Snevl Latitude Travis Last Updated
    Z8 Status Only Today 9:42:29 PM
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    Code:
    Const LT As String = "TimeSpan"
    Const DC As String = "Z1"
    
    Sub Main(ByVal Parms As Object)
    
        Dim TS As TimeSpan
        Dim dtOld As DateTime
    
        If DateTime.TryParse("12/07/2013 10:19", dtOld) Then ' try and put the device last changed at the start here
    
            hs.writelog(LT, "DateTime Parse Success")
            TS = DateTime.Now - dtOld
    
            hs.writelog(LT, "TimeSpan Hours: " & Math.Round(ts.TotalHours, 3))
    
            If ts.TotalHours >= 24 Then
                
                If hs.devicevalue(DC) = 0 Then 'hold the value in the device that is used for the time the last location
                    hs.triggerevent("Send Me An Email")
                    hs.setdevicevalue(DC, 1)
                End If
            Else
                hs.setdevicevalue(DC, 0)
            End If
    
        Else
            hs.writelog(LT, "DateTime Parse Error")
        End If
    
    
    
    End Sub
    ? Something like that anyway.
    Need somewhere for Z1 in this script, just a device to say whether it is already triggered or not.

    Comment


      #3
      Thanks for that, it seems to be working well in parsing the string, working out how many hours are there etc. My next question is what is the easiest way to reset the counter, should I just have a delayed device action in the event that after 24 hours sets the device value of Z1 back to zero so that it starts counting again?

      Thanks!
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment


        #4
        Will it never go above 24hrs? Not clear if it does or not but guess it would be possible, the Timespan object will sort that out and report however many hours have elapsed since it changed without a need to reset it at the end of the day to start counting again. I suggest a bit of testing though just so I got the last part right, V1 should be set to 0 every time you get a successful recent time update, it is only when it goes above 24hrs you get it set to 1.

        Comment


          #5
          Tavisdh,
          Fire the event(to send email) every time you check and it's more than say 24 hrs, then set the events 'don't retrigger' to 24 hrs. That way you will get the notice immediately after the first time the test fails, but won't get again for 24 hrs. The failing condition(>24hrs) will be self clearing(don't set a virtual device).

          Comment

          Working...
          X