Announcement

Collapse
No announcement yet.

Create an event with a script

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

    Create an event with a script

    Hello,

    I use a script function to create a timed event.
    However this event as created will trigger at a specific time. Instead I want to trigger if it's past this time. How can I do this?

    This is what i use now.

    Code:
    Sub SetAudioEvent(ByVal TriggerTime As Integer, ByVal Location As String, ByVal strActionScriptName As String, ByVal strSub As String, ByVal strParms As String)
    
        Dim EvRef As Integer
        Dim OldEvRef As Integer
        Dim EvTime As Date
        Dim strTimerName As String
    
        strTimerName = Location + " " + VOLUME
    
        'Delete event if already exists
        oldEvRef = hs.GetEventRefByName(strTimerName)
         If oldEvRef > 0 Then 'event does exist
            hs.DeleteEventByRef(oldEvRef)
        End If
    
        ' Create the new Event
        EvRef = hs.NewEventEx(strTimerName, AUDIOSYSTEM, "")
    
        ' Enable the Event
        hs.EnableEventByRef(EvRef)
    
        ' Set the trigger time
        dim d as Date = new DateTime(1, 1, 1,   DateTime.Now.Hour,DateTime.Now.Minute, DateTime.Now.Second)
         EVTime = DateAdd("s", TriggerTime, d)
         hs.EventSetTimeTrigger(EvRef, EVTime)
    
        'Delete the event after triggering
        hs.DeleteAfterTrigger_Set(EvRef)
    
        'Script [OFF event]
        strParms = Location & ";" & EVENT_OFF & ";0" 'Time is a dummy value
        hs.AddActionRunScript(EvRef, strActionScriptname, "Main", strParms)
    End Sub
    - Bram

    Send from my Commodore VIC-20

    Ashai_Rey____________________________________________________________ ________________
    HS3 Pro 3.0.0.534
    PIugins: ZMC audio | ZMC VR | ZMC IR | ZMC NDS | RFXcom | AZ scripts | Jon00 Scripts | BLBackup | FritzBox | Z-Wave | mcsMQTT | AK Ikea
Working...
X