Announcement

Collapse
No announcement yet.

HS4 migration issue: HS3:works, tenScripting4/HS4:works, but HS4 fails!

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

    #31
    Thank you very much for the proposed assistance!
    For the time being I now feel confident enough that this a a bug/inconsistency related to HS4 and have called on HS support. If that fails I might consider the exe path, but have no reason to rush into HS4.

    The script is used for syncing and typically runs for a minute to a few minutes depending on the task: A specific playlist sync or a weekly sync. Because of the duration, it is nice to get some status updates in the log file and I was curious to which method would be best to use to have an external app write/trigger writing to HS log?

    Comment


      #32
      I think the best (the only?) way is to use HTTP/JSON API to talk to HS. However even better is to do it in a plugin.

      Comment


        #33
        Originally posted by alexbk66 View Post
        I think the best (the only?) way is to use HTTP/JSON API to talk to HS. However even better is to do it in a plugin.
        It is fairly easy to write a console app that connects to HS without all of the plugin complexity.
        tenholde

        Comment


          #34
          Originally posted by tenholde View Post

          It is fairly easy to write a console app that connects to HS without all of the plugin complexity.
          How?

          Comment


            #35
            I'll post code later today
            tenholde

            Comment


              #36
              This code will connect to either HS3 or HS4, write "Hello World" to the HS log, and disconnect.

              Code:
              Imports HSCF.Communication.Scs.Communication
              Imports HSCF.Communication.Scs.Communication.EndPoints.Tcp
              Imports HSCF.Communication.ScsServices.Client
              
              Module MainModule
              Friend IpAddress As String = "192.168.1.170"
              Friend hs, HS3Host As HomeSeerAPI.IHSApplication
              Public HS3Client As HSCF.Communication.ScsServices.Client.IScsServiceClient(Of HomeSeerAPI.IHSApplication)
              Public Sub Main()
              Dim ConnectedToHs As Boolean = False
              '' Write to Output Window
              Log("Hello World")
              '' Connect to HS
              ConnectedToHs = ConnectToHS3()
              If ConnectedToHs Then
              '' Connected Successfully. Write to HS log
              hs.WriteLog("My Prog", "Hello World")
              Else
              Log("Connection Failed. Check IP Address")
              End If
              '' Disconnect from HS
              HS3Client.Disconnect()
              End Sub
              
              Private Function ConnectToHS3() As Boolean
              ''
              '' Connect to HS3/HS4 and Retrieve HS3 (hs) Object
              ''
              Try
              HS3Client = ScsServiceClientBuilder.CreateClient(Of HomeSeerAPI.IHSApplication)(New ScsTcpEndPoint(IpAddress, 10400))
              Catch ex As Exception
              Log("Exception creating HS3 Client=" & ex.Message)
              Return False
              End Try
              If HS3Client Is Nothing Then
              Log("Could not create HS3Client")
              Return False
              End If
              Try
              HS3Client.Connect()
              Catch ex As Exception
              Log("Exception connecting to HS3Client=" & ex.Message)
              Return False
              End Try
              If Not (HS3Client.CommunicationState = CommunicationStates.Connected) Then
              Log("Failed to connect to HS3Client, State=" & HS3Client.CommunicationState.ToString)
              Return False
              End If
              Try
              HS3Host = HS3Client.ServiceProxy
              hs = HS3Host
              ApiVersion = hs.APIVersion
              Catch ex As Exception
              Log("Exception retrieving hs object=" & ex.Message)
              Return False
              End Try
              If hs Is Nothing Then Return False
              Log("Successfully obtained hs object from either HS3 or HS4")
              Return True
              End Function
              Friend Sub Log(msg)
              Console.WriteLine(msg)
              End Sub
              End Module
              Most of the code is error checking
              tenholde

              Comment


                #37
                You can download the VS project here. http://tenholder.net/temp/ConnectToHs.zip
                tenholde

                Comment


                  #38
                  Brilliant! Thank you.
                  Works very nicely.

                  Comment


                    #39
                    Tenholde’s script enables a minimum overhead to a .exe compilation.
                    Together with a function to set device values and a function for e.g. command line input, it could be a small framework for a “plug-in light”.

                    I finally found a place in the Sample plug-in to insert my code.
                    Debugging with VS provides much richer information than HS4 error log, as we normally enjoy with tenScripting.

                    In my particular case however, I did not get any errors with tenScript4 but do within the plug-in.
                    Do you think that the Sample plug-in environment/assemblies is more comparable to native HS4?
                    - my first impression is that the chosen .NET assemblies are different compared to initial Console VS. Any thoughts? Is this a path forward to adapt my script to native HS4?

                    Comment


                      #40
                      Anyone understand why I can't add the SQLIte.Interop.dll to the HS4 Sample plugin?
                      It's taken directly from the original HS4/bin folder.
                      Attached Files

                      Comment


                        #41
                        Because it's not a .NET DLL. You can try to use NuGet from Visual Studio to add reference, if you are sure that's what you need.

                        Click image for larger version  Name:	Screenshot 2020-11-24 003344.jpg Views:	0 Size:	79.7 KB ID:	1435612

                        Comment


                          #42
                          Originally posted by tenholde View Post
                          You can download the VS project here. http://tenholder.net/temp/ConnectToHs.zip
                          OK, for those of us less astute... how and why is this used?
                          HomeSeer Version: HS4 Pro Edition 4.2.19.0 (Windows - Running as a Service)
                          Home Assistant 2024.3
                          Operating System: Microsoft Windows 11 Pro - Desktop
                          Z-Wave Devices via two Z-Net G3s
                          Zigbee Devices via RaspBee on RPi 3b+
                          WiFi Devices via Internal Router.

                          Enabled Plug-Ins
                          AK GoogleCalendar 4.0.4.16,AK HomeAssistant 4.0.1.23,AK SmartDevice 4.0.5.1,AK Weather 4.0.5.181,AmbientWeather 3.0.1.9,Big6 3.44.0.0,BLBackup 2.0.64.0,BLGData 3.0.55.0,BLLock 3.0.39.0,BLUPS 2.0.26.0,Device History 4.5.1.1,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,HSBuddy 4.51.303.0,JowiHue 4.1.4.0,LG ThinQ 4.0.26.0,ONVIF Events 1.0.0.5,SDJ-Health 3.1.1.9,TPLinkSmartHome4 2022.12.30.0,UltraCID3 3.0.6681.34300,Z-Wave 4.1.3.0

                          Comment


                            #43
                            . You could write a standalone .exe program to do whatever you want with HS from any computer on your network. This VS program just shows you how to connect and gain access to the hs object. The rest is up to your imagination.
                            tenholde

                            Comment


                              #44
                              So... still no response on my support ticket. 😮 ☹

                              I thought that I had made some progress on developing a PI, before I tried to install it!
                              My approach was to modify the SamplePlugin and trigger on different messages:

                              My mods in green.

                              Code:
                              Public Overrides Function OnRunAction() As Boolean[INDENT]Dim iLogType = If((TryCast(ConfigPage?.GetViewById(LogTypeSelectListId), SelectListView))?.Selection, 0)
                              Dim logType As ELogType
                              
                              Select Case iLogType[/INDENT][INDENT=2]Case 0
                              logType = ELogType.Trace
                              Case 1
                              logType = ELogType.Debug
                              Case 2
                              logType = ELogType.Info
                              Case 3
                              logType = ELogType.Warning
                              Case 4
                              logType = ELogType.[Error]
                              Case Else
                              logType = ELogType.Info[/INDENT][INDENT]End Select
                              
                              Dim message = If(ConfigPage?.GetViewById(LogMessageInputId)?.GetStringValu e(), "Error retrieving log message")
                              Listener?.WriteLog(logType, message)
                              
                              [COLOR=#16a085]If message = "UpdateSyncTable" Or message = "UpdateSyncAll" Then[/COLOR][/INDENT][INDENT=2][COLOR=#16a085]MySpotifyStart(message)[/COLOR][/INDENT][INDENT][COLOR=#16a085]End If[/COLOR]
                              Return True[/INDENT]
                               End Function
                              This runs fine in VS, but nothing happens when installed as a PI (status = "OKAY").
                              I put MySpotifyStart in the same class.

                              Edit:
                              I fixed it. It was my deployment error (assembly folder)

                              Still, is this an OK way to do this?

                              Comment

                              Working...
                              X