Announcement

Collapse
No announcement yet.

Plugin: Understanding how Triggers behave

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

    Plugin: Understanding how Triggers behave

    As you perhaps know, I'm starting to learn to write plugins, and I've stared writing TwittSeer.

    I've started using the Ultrajones template, and I've read the documentation.

    But I can't for the LOVE OF SOMETHING THAT IS PURE AND HOLY understand how I'm supposed to implement triggers!


    Yes, I understand that the trigger evaluates a given string, and that string needs a special format, but:
    1. How do I tell HomeSeer to check for triggers?
    2. How do I specify those triggers?
    3. And how is this connected to those attributes mentioned?


    I'm not sure I understand anything at all about triggers. Is there someone out there that can point me in the right direction?


    Thank you in advance!
    HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
    Running on Windows 10 (64) virtualized
    on ESXi (Fujitsu Primergy TX150 S8).
    WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

    Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

    #2
    What's a trigger? If you are talking about having the plugin react to device changes, etc. I believe you plugin needs to register a callback. Then, everytime there is a device change, information about the change is passed to the plugin. I know for scripts, you use RegisterStatusChangeCB which passes the device information to the script where you can evaluate what changed and whether or not the script should react to the change. Not sure how this is done in a plugin, you would have to check in the HST SDK (have you downloaded this?). It has an overly comprehensive example plugin and help information I believe (strike that, I see your link above is to the documentation).

    Comment


      #3
      Not sure if I am being helpful but is this what you are looking for (from the SDK help manual):

      CheckTrigger

      callback.CheckTrigger trigger As String



      When your plug-in detects an event that may cause a trigger, you need to call back into HS with a formatted trigger string.



      The trigger string passed to this function contains values that will be compared with the selected values of your trigger controls as added with the function TriggerUI(). In our example, we added 3 controls, so we therefore have to pass back 3 values which represent each control. HS will perform matches on the values and trigger the event if all the values match a trigger.
      Note that there may be times when you want HS to ignore a value. In our examples one of our controls is a text box which is being used to hold comments. We do not want HS to attempt a match on this value. In this case, pass back an �*� for the value and HS will not attempt a match on it.

      The trigger string is a Chr(2) separated list of values with the following format:

      Parameter 0: plugin name

      Parameter 1: trigger name (as given in TriggerUI)

      Parameter 2+N: list of trigger values for each control



      Following on the previous examples, the following trigger string would force HS to match our trigger that was previously configured:

      "ACME Security Panel" & Chr(2) & "Panel Trigger" & Chr(2) & "zone 1" & Chr(2) & "Closed" & Chr(2) & �*�



      If you have triggers using a range of values, see PreCheckTrigger.
      Note the �*� as the last parameter which tells HS to not perform a match on this value, as this is the position where the Notes field was on the TriggerUI definition.
      Tip: Using an EventEnumerator object in a script or program, look for events with non-empty pi_trigger property values, replace Chr(2) with a printable character, and write the trigger string to a file (or the HomeSeer log) if you want to see how some of the trigger strings are put together.

      Comment


        #4
        Originally posted by heatvent View Post
        What's a trigger?
        When I say "trigger", I mean the trigger you select when you create a new event. On the first tab, you select a name, loaction, other options, and so on. On the second tab, you select the trigger.

        What I want to achieve is this:
        Right now the plugin checks for new tweets every 5 minutes. If it finds anything it updates the Twitter device (which is created by the plugin).

        For now that's all good, but I'd like to create events that are triggered by the plugin, and preferably could have some conditions.

        Such as: "Trigger this event if TwittSeer finds new tweets, but only if any of them are from person XX and contains YY".
        HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
        Running on Windows 10 (64) virtualized
        on ESXi (Fujitsu Primergy TX150 S8).
        WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

        Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

        Comment


          #5
          OK, I have never had to do this before, but in an effort to help I looked at the documentation and it seems to me that you define the plugin's triggers using the TriggerUI function in you plugin (see Procedures -> Functions and Properties -> Trigger Related -> TriggerUI in the SDK documentation). Presumably this woudl be done when the plugin is initialized? Then, after the plugin finds the Tweats and wants to pass the trigger back to HS, you use the callback.CheckTrigger to pass back a string defining the trigger (see Procedures -> Functions and Properties -> Callback Related -> CheckTrigger in the SDK documentation). I am guessing at this but then I believe HS knows to execute any events based on the defined trigger.

          Comment


            #6
            Originally posted by heatvent View Post
            OK, I have never had to do this before, but in an effort to help I looked at the documentation and it seems to me that you define the plugin's triggers using the TriggerUI function in you plugin (see Procedures -> Functions and Properties -> Trigger Related -> TriggerUI in the SDK documentation). Presumably this woudl be done when the plugin is initialized? Then, after the plugin finds the Tweats and wants to pass the trigger back to HS, you use the callback.CheckTrigger to pass back a string defining the trigger (see Procedures -> Functions and Properties -> Callback Related -> CheckTrigger in the SDK documentation). I am guessing at this but then I believe HS knows to execute any events based on the defined trigger.
            I worked on this yesterday, and I believe that's what I'm doing now.
            I still have to figure something out.

            If I understand this correctly, each time the plugin checks for new tweets, I have to find the events using TwittSeer for triggers (should be easy using pi_trigger on an event), and check these pi_trigger strings if they are a match to any of the new tweets.

            As I'm all for sharing code here's what I got so far:

            Code:
                        WriteMessage("Creating enum...", MSG_DEBUG)
                        Dim evenum As New Scheduler.clsEventEnumeration
                        evenum.Restart()
            
                        Do While Not evenum.Finished
                            Dim ev As Scheduler.Classes.EventClass = evenum.GetNext()
            
                            WriteMessage("Checking event: " & ev.Name, MSG_DEBUG)
                            Dim s() As String = ev.pi_trigger.Split(Chr(2))
            
                            If s(0) = "New Twitter content" Then
                                WriteMessage("Found event: " & ev.Name, MSG_DEBUG)
            
                                Dim bolContainsOK As Boolean = False
                                Dim bolCreatorOK As Boolean = False
            
                                For Each t As TwitterVB2.TwitterStatus In tw.TweetList
            
                                    'Checking if the tweet conatins the desired word(s)
                                    If s(1).Length > 0 Then
                                        Dim contains() As String = s(1).Split
                                        Dim count As Integer
                                        For Each st As String In contains
                                            If t.Text.Contains(st) Then count += 1
                                        Next
            
                                        If count = contains.Length Then bolContainsOK = True
                                    Else
                                        bolContainsOK = True
                                    End If
            
            
                                    'Checking if the tweet is made (or not made) by the correct person
                                    Dim search As String = s(2).Replace("|", "")
                                    'If str(2).Contains("|") Then
                                    '    bolCreatorOK = True
                                    '    If t.User.ScreenName = search Then bolCreatorOK = False
                                    'Else
                                    If t.User.ScreenName = search Then bolCreatorOK = True
                                    'End If
                                Next
            
                                If bolContainsOK AndAlso bolCreatorOK Then
                                    WriteMessage("All is OK, trigging the event: " & ev.Name, MSG_DEBUG)
                                    DeviceTrigger(s(1), s(2))
                                End If
                            End If
                        Loop
            This code is plased in the Timer1.Elapsed event. As you see, if this code finds that triggers is OK, it calls DeviceTrigger which again is used to call callback.CheckTrigger.


            However, it seems like the loop never starts. I've tried other methods too, but they give me an error about type conversion.

            Code:
                        For Each ev As Scheduler.Classes.EventClass In hs.GetEventEnumerator
                            [...]
                        Next
            ...


            When I get home, I'll try this:
            Code:
                        Dim evenum As Scheduler.clsEventEnumeration = hs.GetEventEnumerator


            You should think iterating through a list of events was easy, but no...
            HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
            Running on Windows 10 (64) virtualized
            on ESXi (Fujitsu Primergy TX150 S8).
            WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

            Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

            Comment


              #7
              Hmmm! Doing some tesing on my live server. This seems to work OK!

              Code:
                  Sub Main()
              
                          Dim evenum As Scheduler.clsEventEnumeration = hs.GetEventEnumerator
                          Do Until evenum.Finished
                              Dim ev As Scheduler.Classes.EventClass = evenum.GetNext()
                              Dim s() As String = ev.pi_trigger.Split(Chr(2))
              
                              If s(0).Length > 0 Then
                                  hs.Writelog("Test","Checking event: " & ev.Name)
                                  For i as integer = 0 to s.Length - 1
                                      hs.Writelog("Test","s(" & i & "): " & s(i))
                                  Next
                              End if
                          Loop
                  End Sub

              So this might be possible after all...



              Oh, and heatvent: I've started looking into SageTV. The main problem is that I'm not a Java programmer, and haven't even looked at coding for SageTV. However, I've contacted the SageTV genious "nielm" and asked him if it's possible to modify his Dynamic Customizable Menu plugin for SageTV.
              Last edited by Moskus; March 4, 2010, 08:35 AM.
              HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
              Running on Windows 10 (64) virtualized
              on ESXi (Fujitsu Primergy TX150 S8).
              WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

              Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

              Comment


                #8
                Moskus, I'm still confused on how the triggers work and a bit surprised you need to cycle through events to find ones that use the trigger. I guess I would have thought the plugin checks for a Tweet, if there is one, it it passes it along to HS to evaluate. For example, if you had a trigger called "Tweet Received" and then you set up the some items under the trigger, one of those being "Contains" and then in a text box the user would type in the word Test. I would think your plugin, when it finds a Tweet, it simply sends the Tweet text in a string back to HS under the Tweet Received trigger name and then HS matches the callback string to the trigger "Tweet Received" with the "Contains" text of Test. If it's a match, then HS executes the event. What you wrote above looks like your plugin is evaluating the trigger and executing the event.

                On SageTV, yes that is a bit of the problem with this project. You have to become proficient in SageTV Studio to program the UI, Java programming to build functions/capabilities to communicate with HS as well as .Net or Visual Basic to program HS to respond. That's why I think it would be useful to use something existing for one of those components. There are some instructions on Sage's website on how to incorporate VB or C (I believe these two) into Sage. However it seems pretty complicated but may be worth a look. Another route I was exploring was I use the ISY which has a Java development SDK. It probably wouldn't be as large of a task to incorporate the ISY but you still need to learn Studio, SageMC possibly, Java and at the end I would just get access to my Insteon lighting.

                Comment


                  #9
                  Originally posted by heatvent View Post
                  I know for scripts, you use RegisterStatusChangeCB

                  REALLY? Is this a "simple" way of taking something that used to take me 1 event per device and setting an action to call a script?

                  Heatvent, where did you find out about this? I think I can cleanup almost 30 events by using this (as I want my code to be called on ANY change in said device). I'm at work or I'd poke into the help to see if that's in there.

                  --Dan
                  Tasker, to a person who does Homeautomation...is like walking up to a Crack Treatment facility with a truck full of 3lb bags of crack. Then for each person that walks in and out smack them in the face with an open bag.

                  Comment


                    #10
                    Moskus, here is the trigger code from the SDK example. It looks to me that HS does the matching. Now they are doing an optional precheck of the trigger information, but assuming that is OK the last call is back to HS with the string. Now I am not a programmer by any stretch and a lot of this makes not sense to me so it is very possible I am flat out wrong.

                    Code:
                    #Region "    Plug-In Supported Triggers Procedures    "
                    
                        ' called when HS builds trigger options in event properties
                        ' if this plugin supports custom triggers, return TRUE
                        Public ReadOnly Property SupportsTriggerUI() As Boolean
                            Get
                                Return True
                            End Get
                        End Property
                    
                        ' called when HS builds trigger options in event properties
                        ' if this plugin supports custom triggers, return the trigger options
                        ' the returned string is a list of controls that will be displayed on the trigger tab
                        '
                        ' Note that when HS saves a trigger from the event properties, it saves the index value for
                        ' drop list controls, not the string itself. This allows you to rename trigger entries and
                        ' not corrupt configured triggers
                        ' trig_str = currently configured trigger when displaying trigger in event properties
                        Public Function TriggerUI(ByRef trig_str As String) As String
                            Dim attributes As String = "0"
                            Dim i As Short
                            Dim sbTUI As New StringBuilder
                    
                            sbTUI.Append("Panel Trigger")
                            sbTUI.Append(vbTab & UI_DROP_LIST & vbTab & attributes & vbTab)
                            sbTUI.Append("Select Zone:")
                            For i = 0 To 5
                                sbTUI.Append(vbTab & gZoneNames(i))
                            Next
                            sbTUI.Append(vbCr)
                    
                            sbTUI.Append(vbTab)
                            sbTUI.Append(vbTab & UI_DROP_LIST & vbTab & attributes & vbTab)
                            sbTUI.Append("Select Trigger:")
                            sbTUI.Append(vbTab & gZoneActions(0) & vbTab & gZoneActions(1))
                            sbTUI.Append(vbCr)
                    
                            sbTUI.Append(vbTab)
                            sbTUI.Append(vbTab & UI_CHECK_BOX & vbTab & attributes & vbTab)
                            sbTUI.Append("Enabled")
                            sbTUI.Append(vbTab & "1")
                            sbTUI.Append(vbCr)
                    
                            sbTUI.Append(vbTab)
                            sbTUI.Append(vbTab & UI_LABEL & vbTab & attributes & vbTab)
                            sbTUI.Append("All Notes")
                            sbTUI.Append(vbTab)
                            sbTUI.Append(vbCr)
                    
                            sbTUI.Append(vbTab)
                            sbTUI.Append(vbTab & UI_TEXT_BOX & vbTab & attributes & vbTab)
                            sbTUI.Append("Notes:")
                            sbTUI.Append(vbTab)
                    
                            ' add another trigger type
                    
                            sbTUI.Append(Chr(1) & IFACE_NAME & vbTab)
                            sbTUI.Append("Panel Trigger2")
                            sbTUI.Append(vbTab & UI_DROP_LIST & vbTab & attributes & vbTab)
                            sbTUI.Append("Select Trigger:")
                            sbTUI.Append(vbTab & gZoneActions(0) & vbTab & gZoneActions(1))
                            sbTUI.Append(vbCr)
                    
                            Return sbTUI.ToString
                    
                        End Function
                    
                    
                        ' when HS needs to display a trigger to a user, this function is called if the event
                        ' is set to trigger using this plugin
                        ' the parameter passed here is a string of seperated values, seperated with a chr(2)
                        ' each setting is from each control on the trigger tab as it was entered from the
                        ' TriggerUI function. The string returned here will be displayed in the event list in HS
                        ' and on the web page in the event list
                        '
                        ' A sample trigger may look like:
                        ' ACME Sample Plug-In Chr(2) Panel Trigger Chr(2) kitchen Chr(2) Open Chr(2) notes here
                        Public Function TriggerUIFormat(ByRef trig As String) As String
                            Dim values() As String
                    
                            If trig Is Nothing Then Return "Bad trigger string passed to TriggerUIFormat."
                            If InStr(trig, Chr(2)) = 0 Then Return "Bad trigger string passed to TriggerUIFormat."
                    
                            values = Split(trig, Chr(2))
                            ' index
                            ' 0 = plugin name (not used here, but used in HS to identify owner of trigger)
                            ' 1 = trigger name (not needed here)
                            ' 2 = value of first control in trigger tab
                            ' 3 = value of second, etc.
                    
                            If values(1) = "Panel Trigger2" Then
                                Return "Motion status: " & values(2)
                            Else
                                Return "Zone " & values(2) & " detects " & values(3) & " Notes: " & values(5)
                            End If
                    
                        End Function
                    
                    
                        ' when a user clicks OK after editing a trigger, this function is called so
                        ' the data entry can be validated
                        ' the trigstr parameter is the actual trigger string that will be saved
                        ' return an empty string if no error, else return a string describing
                        ' which entry is bad. HS will pop up a dialog with this information
                        ' On the web interface, the page will be redisplayed with the error text
                        ' displayed in RED across the top
                        Public Function ValidateTriggerUI(ByRef trigstr As String) As String
                            Dim items() As String
                            Dim s As String
                    
                            If trigstr Is Nothing Then Return "Invalid trigger string passed to ValidateTriggerUI"
                            If trigstr.Trim = "" Then Return "Invalid trigger string passed to ValidateTriggerUI"
                            If InStr(trigstr, Chr(2)) = 0 Then Return "Invalid trigger string passed to ValidateTriggerUI"
                    
                            items = Split(trigstr, Chr(2))
                            If UBound(items) < 2 Then
                                ' The above test will vary depending upon how many controls are in YOUR trigger string.
                                Return "Invalid trigger string passed to ValidateTriggerUI"
                            End If
                    
                            s = Replace(trigstr, Chr(2), "-/-") ' Chr(2) is unprintable - make it show something.
                            hs.WriteLog(IFACE_NAME, "DEBUG ValidateTriggerUI trigstr: " & s)
                    
                            ' simulate and error if the user selects "Kitchen" as the zone
                            If items(2) = "Kitchen" Then
                                Return "Invalid entry, Kitchen"
                            Else
                                Return ""
                            End If
                    
                        End Function
                    
                    
                        ' when an event happens in this device, call back and pass a formatted string
                        ' that HS should match with a trigger. The string must match exactly to the trigger
                        ' as passed to the TriggerUIFormat function
                        ' HS will attempt to match the entire string taking into account other trigger
                        ' parameters such as conditions, dates, days, etc.
                        ' If there is a parameter that you do not want HS to match on, set its value to *
                        ' For example, in this sample the user may have created a trigger that is formatted
                        ' like:
                        ' ACME Sample Plug-In Chr(2) Panel Trigger Chr(2) kitchen Chr(2) Motion Chr(2) notes here
                        ' The trigger values are index numbers 2(kitchen), 3(Motion), and 4(notes here)
                        ' In this case, the last trigger parameter (4) is just a note, so we change that
                        ' to an * so HS does not attempt a match on it
                        '
                        ' THIS IS NOT A PLUG-IN REQUIRED PROCEDURE - IT IS FOR SAMPLE PLUG-IN FUNCTIONALITY ONLY
                        '
                        Private Sub DeviceTrigger(ByRef zone As String, ByRef action As String)
                            Dim trigstr As String
                            Dim result As Boolean
                            Dim chk_string() As String
                    
                            ' Do a little bit of verification first...
                            If zone Is Nothing Then Exit Sub
                            If action Is Nothing Then Exit Sub
                            If zone.Trim = "" Then Exit Sub
                            If action.Trim = "" Then Exit Sub
                    
                            ' build the trigger string based on the event and callback to HS
                            trigstr = IFACE_NAME & Chr(2) & "Panel Trigger" & Chr(2) & zone & Chr(2) & action & Chr(2) & "*"
                    
                            ' This next step is optional - it uses PreCheckTrigger to find matching triggers.
                            ' This is only needed when you have triggers with analog values and you want to see what
                            '   values the user entered when they created the trigger.  See the SDK reference for more detail.
                            chk_string = callback.PreCheckTrigger(trigstr)
                            If chk_string Is Nothing Then Exit Sub
                            Try
                                If UBound(chk_string) < 0 Then
                                    Exit Sub
                                End If
                            Catch ex As Exception
                                Exit Sub
                            End Try
                    
                            hs.WriteLog(IFACE_NAME, "PreCheckTrigger found " & (UBound(chk_string) + 1).ToString & " triggers that match - triggering events!")
                    
                            ' Since we ARE doing a pre-test with PreCheckTrigger and we have gotten to this point, then
                            '   we know there is at least one match, so let's call CheckTrigger.
                            ' Normally we would go directly to CheckTrigger since we have no triggers with values in a range.
                            callback.CheckTrigger(trigstr)
                    
                        End Sub
                    
                    #End Region

                    Comment


                      #11
                      Originally posted by heatvent View Post
                      Moskus, I'm still confused on how the triggers work and a bit surprised you need to cycle through events to find ones that use the trigger. I guess I would have thought the plugin checks for a Tweet, if there is one, it it passes it along to HS to evaluate. For example, if you had a trigger called "Tweet Received" and then you set up the some items under the trigger, one of those being "Contains" and then in a text box the user would type in the word Test. I would think your plugin, when it finds a Tweet, it simply sends the Tweet text in a string back to HS under the Tweet Received trigger name and then HS matches the callback string to the trigger "Tweet Received" with the "Contains" text of Test. If it's a match, then HS executes the event.
                      I'm a little surprised about that too, and I might of course be mistaken! It wouldn't be the first time.


                      This is what confuses me:
                      Originally posted by heatvent View Post
                      [...]then HS matches the callback string to the trigger "Tweet Received" with the "Contains" text of Test.
                      This makes perfect sense, but somehow somewhere there has to be some code that tells HomeSeer how it is supposed to compare the strings. HS cannot guess.

                      I'll look at it some more. I understand a little more by each time I scratch my head.


                      Originally posted by heatvent View Post
                      What you wrote above looks like your plugin is evaluating the trigger and executing the event.
                      Sadly it is exactly that.


                      Originally posted by heatvent View Post
                      On SageTV, yes that is a bit of the problem with this project. You have to become proficient in SageTV Studio to program the UI, Java programming to build functions/capabilities to communicate with HS as well as .Net or Visual Basic to program HS to respond. That's why I think it would be useful to use something existing for one of those components. There are some instructions on Sage's website on how to incorporate VB or C (I believe these two) into Sage. However it seems pretty complicated but may be worth a look. Another route I was exploring was I use the ISY which has a Java development SDK. It probably wouldn't be as large of a task to incorporate the ISY but you still need to learn Studio, SageMC possibly, Java and at the end I would just get access to my Insteon lighting.
                      That is why I've contacted nielm. He has already made 95% of the plugin, if we only can get him to add two features... He has not responed yet, and I see it's a long time since he was on the Sage forums.

                      I looked at the description for incorporating .NET dlls. It wasn't pretty at all. And that only covers the import, the UI I believe could be equally hard.

                      But I don't know...

                      I'll send you the PM that I sent nielm. Then you can see if you agree or not.
                      HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                      Running on Windows 10 (64) virtualized
                      on ESXi (Fujitsu Primergy TX150 S8).
                      WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                      Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                      Comment


                        #12
                        Originally posted by drozwood90 View Post
                        REALLY? Is this a "simple" way of taking something that used to take me 1 event per device and setting an action to call a script?

                        Heatvent, where did you find out about this? I think I can cleanup almost 30 events by using this (as I want my code to be called on ANY change in said device). I'm at work or I'd poke into the help to see if that's in there.

                        --Dan
                        It's in the Help files. Just to make sure I am clear (since this thread has taken a different direction) you can use RegisterStatusChangeCB to call your script whenever there is a device status change occurs. HS will pass certain information to the script function regarding the device that changed status. So you don't have to wait to get home, below is the help information. BTW, you can call this in your startup.txt script when HS starts.

                        RegisterStatusChangeCB

                        Purpose

                        HomeSeer has the ability to trigger events based on the status of a device changing. This is set in the event properties for the event. It may be useful to run a script when a device changes status. The RegisterStatusChangeCB function can be used to register your script with HomeSeer. When a device changes status, your script will be called. The script is passed the house code and unit code of the device that changed status, as well as the status the device changed to and the reference ID of the device.
                        To remove the callback script, call hs.UnRegisterStatusChangeCB. There are no parameters with this call.
                        Remarks
                        When a device changes status, the given script is called as follows:
                        script_name( parm )
                        The parms parameter is an array of parameters. The following parameters are available:
                        parm(0) = house code of the device that changed status
                        parm(1)
                        = device code of the device that changed status
                        parm(2)
                        = the X10 status that the device changed to.
                        parm(3)
                        = the device reference number. Can be used with GetDevice to find the DeviceClass of the specific device.
                        Note that since a function can be called in the callback script, the registration and actual callback can all reside in the same script file.
                        Parameters

                        Parameter: script
                        Type: string
                        Description: This is the file name of the script to run. Do not include the path in the script name; the script is assumed to be in the scripts directory (C:\Program Files\HomeSeer 2\Scripts by default).
                        Parameter: function
                        Type: string
                        Description: This is the function in the script to run, such as main.
                        Returns

                        None.
                        Example

                        Code:
                        [COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]' register a callback script[/COLOR][/SIZE][/FONT][/COLOR]
                        [COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]sub main()[/COLOR][/SIZE][/FONT][/COLOR]
                        [COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]hs.RegisterStatusChangeCB "stat_change.txt","statuscb"[/COLOR][/SIZE][/FONT][/COLOR]
                        [COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]end sub[/COLOR][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]
                        
                        ' the actual status change script that is called when a device changes status given the above register call[/COLOR][/SIZE][/FONT][/COLOR]
                        [COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]sub statuscb(parm)[/COLOR][/SIZE][/FONT][/COLOR]
                        [COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]dim hc[/COLOR][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]
                        dim dc[/COLOR][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]
                        dim status[/COLOR][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]
                        
                        hc = parm(0)[/COLOR][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]
                        dc = parm(1)[/COLOR][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]
                        status = parm(2)[/COLOR][/SIZE][/FONT][/COLOR]
                        [COLOR=#000000][FONT=Courier New][SIZE=1][COLOR=black]   end sub[/COLOR][/SIZE][/FONT][/COLOR]

                        Comment


                          #13
                          From the documentation:

                          After the user makes his selections for the trigger, a trigger string is built and saved in the HS config file for the specific event. This string is used by HS to determine if a trigger occurs. Your plug-in will call the callback function CheckTrigger(trigstr) when an event occurs.

                          Not sure where the "HS config file for the specific event" is?

                          Comment


                            #14
                            Originally posted by heatvent View Post
                            After the user makes his selections for the trigger, a trigger string is built and saved in the HS config file for the specific event. This string is used by HS to determine if a trigger occurs. Your plug-in will call the callback function CheckTrigger(trigstr) when an event occurs.
                            That is OK, but for HS to use CheckTrigger() the "trigstr" needs to be specified.

                            Let's say I have two text fields:
                            1. Tweet_has_to_contain
                            2. Tweet_made_by

                            In an example, I create an event and enter "Testing" and "Moskus" in the two text boxes respectively.

                            The example has a function called DeviceEvent and is defined as:
                            Code:
                            Private Sub DeviceTrigger(ByRef zone As String, ByRef action As String)
                            This sub takes the parameters and builds the "trigstr" string based on the input.


                            My DeviceTrigger is defined as:
                            Code:
                            Private Sub DeviceTrigger(ByVal tweet_contains As String, ByVal tweet_made_by As String)
                            So in the tmr.Elapsed sub I can call the DeviceTrigger. But what to put into the "tweet_contains"?

                            The tweet_made_by string is OK, as it's just one word. I can pass tweet.User.Displayname without problems. If it matches, it matches.

                            But if I pass the whole tweet text in the tweet_contains string, then the Tweet with the text "Testing this trigger" won't be the same as "Testing" which I entered in the Tweet_has_to_contain textbox.



                            EDIT: But wait! I'm an idiot! Isn't this what the PreCheckTrigger is for?
                            Hmm! Maybe I just saw the light!
                            HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                            Running on Windows 10 (64) virtualized
                            on ESXi (Fujitsu Primergy TX150 S8).
                            WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                            Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                            Comment


                              #15
                              I didn't think of it the way you explained but that makes sense. I in essence, you still need to have the plugin check to see if an event is triggered since checktrigger is basically dumb (it doesn't know to look for a specific word in the string). So I see your initial logic then. If you have to check to see if the word is there anyway, why pass it to HS to trigger the event when you could just execute the event from the plugin. Not sure but I would think the HST example is the best practice for some reason? It would be nice if someone with some plugin experience could chime in. Perhaps you should reach out to Blade or Jim Doolitte and run it by them. I think they are both pretty good about helping fellow developers out.

                              Comment

                              Working...
                              X