Announcement

Collapse
No announcement yet.

Old callback Methods HS.CheckTrigger

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

    Old callback Methods HS.CheckTrigger

    With HS2 i could use callback CheckTrigger to pass in my trigger string and HS would check it and trigger the event.

    Now with HS3 sdk, i don't seem to be able to find anything similar to that, only things like getevents.

    So my question is, Does CheckTrigger exist or do i have to get a list of events myself, check and execute within my plugin?


    #2
    There is no longer a checktrigger function.

    The plugin handles the logic for the data it receives now.
    Wade

    "I know nothing... nothing!"

    Comment


      #3
      So lets assume for now my plugin is set to trigger on a timer every 30 second. What i need to do is get a list of all the events defined, find one that matches including checking all the sub conditions and if passed execute the event by name?

      or am i forced now to create virtual devices to reflect the condition of my plugin and allow HS to trigger events based on that?

      do you have an example ?

      Comment


        #4
        You need to call callback.TriggerFire(). The is an example in the sample plugin (in util.vb).

        Comment


          #5
          \HSPI_SAMPLE_BASIC_1_0_0_3
          is the version i have but I don't have any method called


          callback.TriggerFire()

          Comment


            #6
            Ok, if i hard code it for now i can fire an event, however hardcoding is not an option.

            Dim strTrig AsNew HomeSeerAPI.IPlugInAPI.strTrigActInfo
            strTrig.TANumber = 1
            strTrig.SubTANumber = -1
            strTrig.UID = 9559
            strTrig.evRef = 8634
            callback.TriggerFire(IFACE_NAME, strTrig)

            Do i have to keep track of the UID and evRef internally to my plugin so i can re-build the strTrigActInfo object to TriggerFire user defined events?

            I am sure this cannot be right because it seems like double work, HS keeps track of it and so does my plugin so I must be missing somthing. Any help anyone can offer would be great as I cannot find anything in this forum or in the docs.

            I also tried

            Dim pTestTrigger As New trigger
            Dim strTrig As New HomeSeerAPI.IPlugInAPI.strTrigActInfo
            pTestTrigger.Add(CObj("_PLUGINOBJECT"), "PARAMATER1VALUE")
            pTestTrigger.Add(CObj("_PLUGINOBJECT2"), "PARAMATER2VALUE")
            SerializeObject(TestTrigger, strTrig.DataIn)
            callback.TriggerFire(IFACE_NAME, strTrig)

            as i have configured an event to trigger on these however this does not seem to do anything.


            Comment


              #7
              The callback object has two methods for retrieving trigger info, TriggerMatches and GetTriggers.

              TriggerMatches lets you specify the trigger and subtrigger ID's for a more specific return, whereas GetTriggers returns all triggers for a plugin.

              You can use these to get the TrigActInfo used in the TriggerFire function.

              Since the plugin loads the triggers/actions into Homeseer on startup, it has the TANumbers and SubTANumbers (Adding a trigger or action to homeseer increments this) for you to keep track in the plugin.

              You can use this data to get a smaller list of triggers rather than looking through all of them.
              Wade

              "I know nothing... nothing!"

              Comment


                #8
                Sub callbackCheckTrigger(ByVal X10UnitCode As String, ByVal X10Housecode As String, ByVal X10Command As Integer)
                Dim TrigInfo As strTrigActInfo
                Dim TrigsToCheck As strTrigActInfo = Nothing
                Dim HouseCode As String = ""
                Dim UnitCode As String = ""
                Dim Command As String = ""
                Dim trigger As New trigger

                Try
                TrigsToCheck = callback.GetTriggers(IFACE_NAME)
                Catch ex As Exception
                End Try
                If TrigsToCheck IsNot Nothing Then
                For Each TrigInfo In TrigsToCheck

                DeSerializeObject(TrigInfo.DataIn, trigger)

                For Each sKey In trigger.Keys
                Select Case True
                Case InStr(sKey, "X10CodesT") > 0
                Command = trigger(sKey)
                Case InStr(sKey, "HouseCodesT") > 0
                HouseCode = trigger(sKey)
                Case InStr(sKey, "UnitCodesT") > 0
                UnitCode = trigger(sKey)
                End Select
                Next

                If Command = X10Command.ToString And HouseCode = X10Housecode And UnitCode = X10UnitCode Then 'We have a match, so continue
                callback.TriggerFire(IFACE_NAME, TrigInfo)
                End If
                Next
                End If
                End Sub
                Wade

                "I know nothing... nothing!"

                Comment


                  #9
                  Thanks, Now I understand, but what if the trigger I am going to fire has a condition.

                  If Command = X10Command.ToString And HouseCode = X10Housecode And UnitCode = X10UnitCode Then'We have a match, so continue
                  callback.TriggerFire(IFACE_NAME, TrigInfo)
                  EndIf

                  callback.TriggerFire cause homeseer to invalidate any conditions applied and just fire the event anyway. For example, I put a condition on my trigger to say only fire if the day of the week is sunday (today is Saturday) but homeseer did not check the conditions and ran the event anyway.



                  Comment


                    #10
                    HomeSeer will call into your plug-in calling TriggerTrue to determine if a trigger is true or not. TriggerFire is for when YOU have determined that an event has taken place for which triggers based upon it should be "fired" or made active. Since conditions are evaluated AFTER a trigger has happened, you would not call TriggerFire on a trigger that is in condition mode.

                    So to summarize....

                    You create a trigger and tell HomeSeer whether that trigger can also act as a condition.

                    The user selects the trigger, and if it is used as a trigger (IF) then HomeSeer will set Condition to False, but if it is used as a "condition" (AND) then HomeSeer sets Condition to True.

                    If an event trigger happens, and one of the conditions is a plug-in trigger (Condition=True) then HomeSeer will call TriggerTrue and will pass to the plug-in the trigger info and data (if you store the data with HomeSeer) so that your plug-in can tell HomeSeer whether it is true or not.

                    If your plug-in determines that an event has taken place for which your plug-in is providing triggers for, then it either calls GetTriggers to see if any of that trigger are used in the system, or perhaps it called it earlier so it already has a list it can check. Either way, if there is a trigger for that event configured, and that event is now true, then the plug-in calls TriggerFire to tell HomeSeer that the trigger happened. HomeSeer will then evaluate any conditions that may be present and if they are True, it will run the event actions.

                    Hopefully that will help clear things up!
                    Regards,

                    Rick Tinker (a.k.a. "Tink")

                    Comment


                      #11
                      sadly this is not made things more clear.

                      My plugin is what determines if a condition within the plugin is true. The plugin gets this information from an external source and at this point is completely unaware of the event conditions configured within homeseer.

                      Lets say for example (A=0) in my plugin.

                      An event configured within Homeseer3 let call it (EVENT_1) is set as following




                      My plugin is completely unaware of any additional conditions found in the (AND clause) and matches only those for which My Plugin is aware of.

                      Simply put, I am trying to replicate what HS2 CheckTrigger did.




                      Comment


                        #12
                        Duncan,

                        First of all, callback.CheckTrigger is still in HS3, it just works differently.

                        Second, you are right - your plug-in knows when your plug-in conditions are true, but you mentioning that has nothing to do with what I wrote.

                        In HS2 we had separate triggers and conditions. In HS3, we have only triggers, but one of the properties of a trigger is "Condition", and when HomeSeer sets that to True, it is used as a condition, not a trigger. After adding a trigger to an event (IF/OR IF), the next thing you add (AND IF) is a condition. If your trigger does not support being a condition, then HomeSeer does not even display it as a choice.

                        If your trigger is added in condition mode, telling HomeSeer that the trigger is true does not fire the event actions because it is a condition. When the trigger of an event happens, then the conditions are checked by HomeSeer calling TriggerTrue for each one.
                        Regards,

                        Rick Tinker (a.k.a. "Tink")

                        Comment

                        Working...
                        X