Announcement

Collapse
No announcement yet.

set event last run time to never

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

  • set event last run time to never

    Hi, it is possible to set the last run time of an event to „never“ by script ?
    I use it for events that run very rarely.

    Regards,
    Fischi

  • #2
    The time is set as follows. The variable type is date. This means it can't be string. It could be a defined date that you can use as a trigger. You would also have to check the update for the device to not update unless values change.

    Click image for larger version

Name:	Screenshot from 2019-12-01 13-59-57.png
Views:	75
Size:	11.6 KB
ID:	1343760

    From help file: Purpose

    This function sets the last change time of a device. Parameters

    Parameter: dvRef
    Type: Integer
    Description: This is the device reference ID number.

    Parameter: date-time
    Type: date
    Description: This is the date and time to set the last change to. Returns

    Return value: none Example

    hs.SetDeviceLastChange(5678, Now)
    hs.SetDeviceLastChange(5678, Convert.ToDateTime("1/1/13 4:00 PM"))

    Hope this is helpful

    Comment


    • #3
      He wants to change an Event Last Triggered Date, not a Device. I have been trying to find that function and had no luck. As far as I know Event info is stored in the database as a "blob", which I think must be deserialized, edited then stored again. Perhaps Jon00 or one of the other developers can answer. Here is the Event data string structure.

      Click image for larger version

Name:	capture.png
Views:	80
Size:	129.1 KB
ID:	1343762
      Randy Prade
      Aurora, CO
      Prades.net

      PHLocation - Pushover - EasyTrigger - UltraECM3 - Ultra1Wire3 - Arduino

      Comment


      • #4
        Mea culpa. The type of Last_Triggered is still date so no string.

        I think this is how you get the event structure:

        ------
        Function Event_Info(ByVal evRef As Integer) As strEventData Purpose

        This function returns information about a single event using its Event Reference ID number. Parameters

        Parameter: evRef
        Type: integer
        Description: This is the event reference ID number for the event you want to return information about. Returns

        Return value: strEventData
        Type: structure
        Description: This structure is described in this section.

        Comment


        • #5
          Yep, I found that. That will return the data as an object. The question that he needs answered is how to write it back.
          Randy Prade
          Aurora, CO
          Prades.net

          PHLocation - Pushover - EasyTrigger - UltraECM3 - Ultra1Wire3 - Arduino

          Comment


          • #6
            I did some investigation and in HS3, I don't think you can write it back with any readily available functions/subroutines. It appears that in HS2 you could. Seems odd that you can't get the object by reference. There have been many posts of frustration on this in the forum.

            My only thought on a workaround is to create a device that is a proxy for the event and use that for triggering as needed. It seems inconsistent in design to prevent modification of this when you have control of most things via script.

            I wrote a script to show the behavior: hs.SaveEventsDevices only saves script created events.

            '-------------------------------------------
            'Set the last time an event was triggered
            '12/2/2019 Parm should be the EventID if you are passing
            '-------------------------------------------

            IMPORTS System.IO
            IMPORTS System.Net
            IMPORTS System.Threading

            Sub Main(ByVal Parm As Object)

            Dim evRef As Integer '= Parm 'Event Reference - remove 1st single quote to pass value
            Dim MyEventData as strEventData

            evRef = hs.GetEventRefByName("Turn Off Comm Closet Lights") 'Get the event by name

            hs.writelog("Script", "The event Reference number is " & CStr(evRef)) 'Write it to the log for debug

            MyEventData = hs.Event_Info(evRef) 'Get the Event Data Structure

            hs.writelog("Script", "The Date-Time now is: " & CStr(DateTime.Now)) 'Write 2 log for debug

            hs.writelog("Script", "The Date-Time of event is: " & CStr(MyEventData.Last_Triggered)) 'Write 2 log for debug

            MyEventData.Last_Triggered = DateTime.Now 'Set to Now

            hs.writelog("Script", "The Date-Time is: " & CStr(MyEventData.Last_Triggered)) 'Write 2 log for debug

            hs.SaveEventsDevices() 'Force the save - This does not save an Existing event.

            hs.writelog("Script", "Forced the save for events") 'Write it to the log for debug

            'Debugging ----------------------------------------------

            MyEventData = hs.Event_Info(evRef) 'Get the Event Data Structure
            hs.writelog("Script", "The Date-Time is: " & CStr(MyEventData.Last_Triggered)) 'Write 2 log for debug

            End Sub

            Comment

            Working...
            X