Announcement

Collapse
No announcement yet.

Create an Event from a script

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

    Create an Event from a script

    Since there is no way to set a timer from a script, I'm left with building an event to turn off a device after a set amount of time. Has anyone done this?

    Thanks;

    Don
    Don

    #2
    Originally posted by donstephens View Post
    Since there is no way to set a timer from a script, I'm left with building an event to turn off a device after a set amount of time. Has anyone done this?

    Thanks;

    Don
    Hi Don,

    I have a script to create events to turn block heaters on and off. It creates two events, one to turn the device on at a specific time and then one to turn it off after a certain number of minutes. If that'll help you, let me know and I can post it.

    Cheers
    Al
    HS 4.2.8.0: 2134 Devices 1252 Events
    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

    Comment


      #3
      Perfect! If you could share, I'd be really thankful.

      Thanks.
      Don

      Comment


        #4
        Hi Don,

        See attached. It's not all that well documented, so if something is not clear, let me know.

        Cheers
        Al
        Attached Files
        HS 4.2.8.0: 2134 Devices 1252 Events
        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

        Comment


          #5
          Just Perfect. Appreciate it.
          Don

          Comment


            #6
            For reference, this should do to

            Code:
            '
            ' Triggertime in seconds
            '
            Sub MakeEvent(ByVal TriggerTime As Integer, ByVal strEventName As String, ByVal strEventGroup As String)
            
                Dim EvRef As Integer
                Dim OldEvRef As Integer
                Dim EvTime As Date
            
                'Delete event if already exists
                oldEvRef = hs.GetEventRefByName(strEventName)
                If oldEvRef > 0 Then 'event does exist
                    hs.DeleteEventByRef(oldEvRef)
                End If
            
                ' Create the new Event
                EvRef = hs.NewEventEx(strEventName, strEventGroup, "")
            
                ' Enable the Event
                hs.EnableEventByRef(EvRef)
            
                ' Set the trigger time
                EvTime = DateAdd("s", TriggerTime, Now)
                hs.EventSetTimeTrigger(EvRef, EvTime)
            
                'Delete the event after triggering
                hs.DeleteAfterTrigger_Set(EvRef)
            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

            Comment


              #7
              Thanks for that. I must have missed all of it in the help file.
              Don

              Comment


                #8
                If you guys are up for one more question, how do I add a run event to my newly created script? And where are you two finding the docs for this? I looked all over the help file under scripting, and couldn't find it?

                Thanks for all your help.
                Don

                Comment


                  #9
                  Hi Don,

                  See here:

                  http://homeseer.com/support/homeseer...ing_events.htm

                  http://homeseer.com/support/homeseer...ing_events.htm

                  Cheers
                  Al
                  HS 4.2.8.0: 2134 Devices 1252 Events
                  Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                  Comment


                    #10
                    Thanks Al
                    Don

                    Comment


                      #11
                      Well Don, i don't think your answer will completely be answered..
                      The documentation is very incomplete at best.

                      I couldn't find an answer for that too. e.g. creating an event via scripting and let that even trigger another event. I solved it in two ways.

                      One, by adding hs.AddActionRunScript(EvRef,Scriptname,Sub,Parms) to your script to call another script that trigger the event for you. It can be a generic script where you pass the eventname into as parameter so it will fire on any event you want to.

                      Second, make a virtual device to turn on/off and add this device to the event as a trigger so when your newly created event turns the device on it also will trigger the even.
                      - 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

                      Comment


                        #12
                        Never thought of either of those approaches.

                        :-)
                        Don

                        Comment


                          #13
                          Hi guys,
                          I am newbie and to help out other newbies, I've dummied up an example. Hope it helps others learn the mystic and undocumented commands in HS.

                          Basically, it's a script to create an event that runs a script. You might use this to create lots of events to run drule's IR sender for example.

                          The script is as follows:
                          Code:
                          Sub Main(parm as object)
                              Const ScriptName = "CreateEvent"
                          
                              Dim strEventGroup            As String = "Test_Event_Group"
                              Dim strEventName             As String = "Test_Event_Name"
                              Dim strEventLaunchByRefProc  As String = "LaunchEventByRef"
                              Dim strEventLaunchScript     As String = "Launch_This_Script.vb"
                              Dim strEventLaunchByNameProc As String = "Calling_This_Procedure"
                              Dim strEventLaunchProcParams As String = "With_These_Parameters"
                          
                              Dim EvRef As Integer
                              Dim OldEvRef As Integer
                              Dim EvTime As Date
                          
                              'Delete event if already exists
                              oldEvRef = hs.GetEventRefByName(strEventName)
                              If oldEvRef > 0 Then 'event does exist
                                  hs.DeleteEventByRef(oldEvRef)
                              End If
                          
                              ' Create the new Event
                              EvRef = hs.NewEventEx(strEventName, strEventGroup, "")
                          
                              ' Enable the Event
                              hs.EnableEventByRef(EvRef)
                          
                               Try
                                  hs.AddActionRunScript(EvRef, strEventLaunchScript, strEventLaunchByNameProc, strEventLaunchProcParams)
                                  hs.WriteLog(ScriptName , "New Event Created." )
                                  hs.WriteLog(ScriptName , "Event Ref: " + Str(EvRef))
                                  hs.WriteLog(ScriptName , "Event Group: " + strEventGroup )
                                  hs.WriteLog(ScriptName , "Event Name: " + strEventName )
                                  hs.WriteLog(ScriptName , "Event Type: " + strEventLaunchByRefProc )
                                  hs.WriteLog(ScriptName , "Event Script: " + strEventLaunchScript )
                                  hs.WriteLog(ScriptName , "Event Calls this Procedure : " + strEventLaunchByNameProc )
                                  hs.WriteLog(ScriptName , "With These Parameters: " + strEventLaunchProcParams )
                          
                              Catch ex As Exception
                                  hs.WriteLog(ScriptName , String.Format("Error adding event action to event '{0}': {1}", strEventName, ex.Message))
                                  Throw Ex
                              End Try
                          
                          End Sub
                          The Event it creates, calls the below "dummy" script.
                          Code:
                          Sub Main(parm as object)
                          
                              hs.WriteLog("DummyScript" , "I am a dummy script. I do not do anything.")
                          
                          End Sub
                          
                          Sub Calling_This_Procedure(parm as String)
                              hs.WriteLog("DummyScript" , "I have been called with paramaters: " + parm)
                          
                          End Sub
                          Some pictures
                          Attached Files

                          Comment


                            #14
                            Nice job!
                            Don

                            Comment


                              #15
                              Set power fail recovery

                              Is there a parameter to set a created event to power fail recovery like the GUI?

                              Thanks

                              Comment

                              Working...
                              X