Announcement

Collapse
No announcement yet.

Simple PluginFunction example please - sob!

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

    Simple PluginFunction example please - sob!

    Have a plugin HS3 (Paraphrase which gives a random response back to commands) and it worked fine. Porting and converting to HS4 and I can't get the PluginFunction to work (Legacy or HS4).

    What it gets is simple an [Ini] file section - like 'Motion Detect' and an Arrary of Ini style replacement markers (Location=Study, Time=14:00).

    Here's the call line I used to have -
    Dim Plugin As New HomeSeerAPI.PluginAccess(CType(hs, HomeSeerAPI.IHSApplication), "Paraphrase", "")
    Return CType(Plugin.PluginFunction(ID, Replacements.Split("|"c)), String)
    Here is what I've tried for the new HS4 -
    Return("" & hs.PluginFunction("HSPI-Paraphrase", "PluginFunction", Replacements.Split("|"c)))


    In the plugin (which is initialized), I tried both of these -
    Protected Overloads Function PluginFunction(procName As String,params As Object()) As Object
    Console.WriteLine("Called PlugIn " & procName)
    Return (myParaphrase.Action(procName, params))
    End Function

    Public Function Response(procName As String,params As Object()) As Object
    'Console.WriteLine("Called PlugIn " & procName)
    Return (myParaphrase.Action("action", params))
    End Function

    Breakpoints on these never get reached (unlike Intiialize/InitIO).

    Any idea what I'm doing wrong - or even better a simple example!

    (There aren't any in the sample plugins.)

    Help appreciate, thank you.

    James



    #2
    Here's one from HS3. I havent tested it with HS4 yet:

    PHP Code:
    Public Function PluginFunction(ByVal proc As StringByVal parms() As Object) As Object Implements IPlugInAPI.PluginFunction
    Try
    Dim ty As Type Me.GetType
    Dim mi 
    As MethodInfo ty.GetMethod(proc)
    If 
    mi Is Nothing Then
    Log
    ("Method " proc " does not exist in this plugin."LogType.LOG_TYPE_ERROR)
    Return 
    Nothing
    End 
    If
    Return (
    mi.Invoke(Meparms))
    Catch 
    ex As Exception
    Log
    ("Error in PluginProc: " ex.MessageLogType.LOG_TYPE_ERROR)
    End Try

    Return 
    Nothing
    End 
    Function 
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment


      #3
      Here is what I am using in my HS4 plugin for both scripting and html pages. It works. In essence not much different from HS3:

      Code:
      Public Overloads Function PluginFunction(ByVal procName As String, ByVal params As Object()) As Object
      Try
      Dim ty = [GetType]()
      Dim mi = ty.GetMethod(procName)
      Return mi?.Invoke(Me, params)
      Catch exception As Exception
      
      If LogDebug Then
      Console.WriteLine(exception.Message)
      End If
      End Try
      
      Return Nothing
      End Function
      -- Wim

      Plugins: JowiHue, RFXCOM, Sonos4, Jon00's Perfmon and Network monitor, EasyTrigger, Pushover 3P, rnbWeather, BLBackup, AK SmartDevice, Pushover, PHLocation, Zwave, GCalseer, SDJ-Health, Device History, BLGData

      1210 devices/features ---- 392 events ----- 40 scripts

      Comment


        #4
        Thanks for the responses, but both of those address (no pun) the plugin side - the (literally) pluginfunction isn't being called.

        I know that the instance is now redundant (never used it anyway), but somehow HomeSeer isn't linking the Script call (hs.PluginFunction) to get to the actual plugin function.

        I must be doing something wrong/stupid - but I've tried various combinations of (plugin) names/id and nothing seem to work.

        Really strange because getting this to work on HS3 was a doddle.

        Comment


          #5
          This sample call from a script addresses the HSPI.PluginFunction from my earlier sample fine here.It did not change going from HS3 to HS4 versions of the plugin.

          Code:
          DimChanged = hs.PluginFunction("JowiHue", "", "SetLightsHueSat", {True, "Bank", 30, Nothing, Nothing, 10})
          -- Wim

          Plugins: JowiHue, RFXCOM, Sonos4, Jon00's Perfmon and Network monitor, EasyTrigger, Pushover 3P, rnbWeather, BLBackup, AK SmartDevice, Pushover, PHLocation, Zwave, GCalseer, SDJ-Health, Device History, BLGData

          1210 devices/features ---- 392 events ----- 40 scripts

          Comment


            #6
            w.vuyk - I think I love you <grin>, JUST what I needed, thank you very, very much.

            I had a couple of missing items (no ByVal and the additional. empty, instance parameter) - I've mangled these routines so many times and haven't been back to the original [working] code

            I am always amazed by how helpful people are, you're all grand.

            Comment


              #7
              Great! Thanks. Alway glad to give some help back to the forum.... to be honest I missed the empty instance myself too while reading your initial post

              Glad it is solved!

              One nosy question left though, what is the plugin paraphasing?
              -- Wim

              Plugins: JowiHue, RFXCOM, Sonos4, Jon00's Perfmon and Network monitor, EasyTrigger, Pushover 3P, rnbWeather, BLBackup, AK SmartDevice, Pushover, PHLocation, Zwave, GCalseer, SDJ-Health, Device History, BLGData

              1210 devices/features ---- 392 events ----- 40 scripts

              Comment


                #8

                OK two things - solved it for the HS4 call (after peering at docs/XML, VS autocomplete, etc. zzzzz).

                1) Here's the HS4 call in the script, not legacy -
                Dim s As Object = hs.IHsController_PluginFunction("HSPI-Paraphrase", "Motion Record", Replacements.Split("|"c))


                2) HSPI_Paraphrase returns a random phrase back, with the responses being in a Cfg file, but also replaces <<markers>>.

                So I have a (Data/HSPI-Paraphrase\) file with Ini sections like -
                [Motion Info]
                I saw movement in the <<Location>>.
                Check out the <<Location>>, I thought I saw something.
                At <<Time>> there was movement in the <<Location>> area.
                Something moved in the <<Location>> at <<Time>>.
                I think something moved by the <<Location>>.

                I call Paraphrase and send it an array of Key=Value (c above) pairs BSV separated, so something like
                Location=Study|Time=Now|Duration=10 seconds
                ->
                Location=Study
                Time=Now
                Duration=10 seconds

                (and anything else I feel like putting in).

                What I get back is one of the phrases with the <<..>> markers replaced, which my (Microsoft Agent & DesktopMates head) then speaks on one of my room [netbook] clients.

                The funniest is when we tell HomeSeer 'Goodnight' then HomeSeer responds, sometimes Google [mis]understands and replies to that!

                We've had Google responses like "my developers are very good at keeping me free of bugs' (from 'Don't let the bedbugs bite') Playing a lullaby station (from 'Shall I sing you a lullaby') etc.

                Quite funny and keeps it interesting, I also use if with my timed schedule script to wish my other half happy birthday or whatever.


                I wrote to Google once (couple of years ago) saying that they should do something similar and they do now - not that I can take credit, never got a response.

                If you want it just ask (homeseer@athame.net) - source too - NOW it even comes with a real HS installer (since they made that easy now).

                Again, thank you to all that read and those that replied. Help is always welcome.

                Comment


                  #9
                  Originally posted by w.vuyk View Post
                  Here is what I am using in my HS4 plugin for both scripting and html pages. It works. In essence not much different from HS3:

                  Code:
                  Public Overloads Function PluginFunction(ByVal procName As String, ByVal params As Object()) As Object
                  Try
                  Dim ty = [GetType]()
                  Dim mi = ty.GetMethod(procName)
                  Return mi?.Invoke(Me, params)
                  Catch exception As Exception
                  
                  If LogDebug Then
                  Console.WriteLine(exception.Message)
                  End If
                  End Try
                  
                  Return Nothing
                  End Function
                  Is it even necessary to override PluginFunction in your plugin under HS4? It looks to me as though that exact same code is the default implementation.
                  tenholde

                  Comment


                    #10
                    It is different from the one in the PluginSDK last time I checked. And when I created the routine, it was very rudimentary in the PluginSDK. That was last year November. So it may not be needed, but back then it was not documented and not complete. And now it is working just fine.
                    -- Wim

                    Plugins: JowiHue, RFXCOM, Sonos4, Jon00's Perfmon and Network monitor, EasyTrigger, Pushover 3P, rnbWeather, BLBackup, AK SmartDevice, Pushover, PHLocation, Zwave, GCalseer, SDJ-Health, Device History, BLGData

                    1210 devices/features ---- 392 events ----- 40 scripts

                    Comment

                    Working...
                    X