Announcement

Collapse
No announcement yet.

HSTOUCH CLIENT IDENTIFICATION

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

    HSTOUCH CLIENT IDENTIFICATION

    I have created a way to identify each HSTouch Client without deploying a different version to each client

    The first step was to create a text element that would accept html text.

    Here is how I configured the element in HSTouch:



    The key point is to set the text element IsHTML to true. It is basically a shell to hold what we need. It can be visible or not per your preference.

    The next step is to create a html file for each client. Below is an example:

    [CODE][<html>
    <head>
    <head>
    <body>
    <p> YOUR-CLIENT-NAME </p>
    <body>
    <html>
    /CODE]

    Substitute YOUR-CLIENT-NAME as you see fit.

    Create an Event for each client that looks similar to this: Obviously yours will have different client names, Element Names and URL. The URL is referring to your homeseer server.



    The following script is used to process the data and write the HTML to the client.

    Code:
    REM GetInstance.vb - 5/31/2020 - JLG
    REM The purpose of this routine is to populate the HSTouch Client to allow each Client to be recognized as unique
    REM There are no parameters that are passed to this routine
    
    IMPORTS System.Core
    
    Sub Main(ByVal parms As Object)
    
    Dim myList As String = "Test"
    Dim myClients() As String
    Dim i As Integer
    Dim iReturn As Integer
    
    myList = hs.GetInstanceList
    
    If myList Is Nothing Then
    Exit Sub
    End If
    
    hs.WriteLog("Instance", myList)
    
    myClients = myList.Split(",")
    
    For i = 0 To myClients.Length-1
    Select Case myClients(i)
    Case "HOMESEER-SERVER:MAIN FLOOR"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementMainFloor")
    If iReturn = 0 Then
    hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementMainFloor")
    End If
    Case "HOMESEER-SERVER:MEDIA"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementMedia")
    If iReturn = 0 Then
    hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementMedia")
    End If
    Case "HOMESEER-SERVER:UPSTAIRS"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementUpstairs")
    If iReturn = 0 Then
    hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementUpstairs")
    End If
    Case "HOMESEER-SERVER:BAR"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementBar")
    If iReturn = 0 Then
    hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementBar")
    End If
    Case "HOMESEER-SERVER:GPHONE"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementGPhone")
    If iReturn = 0 Then
    hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementGPhone")
    End If
    Case "HOMESEER-SERVER:JPHONE"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementJPhone")
    If iReturn = 0 Then
    hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementJPhone")
    End If
    Case "HOMESEER-SERVER:DAD"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementDad")
    If iReturn = 0 Then' hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementDad")
    End If
    Case "HOMESEER-SERVER:TV-NETFLIX"
    iReturn = hs.TriggerEventAndWait("SetHSTouchElementTV")
    If iReturn = 0 Then
    hs.WriteLog("Instance", "There was an error triggering the event: SetHSTouchElementTV")
    End If
    Case Else
    hs.WriteLog("Instance", "No Clients available " & myList)
    End Select
    Next
    
    End Sub
    The process is kicked off by an event. I have it set to run manually now but I will make it run on a recurring trigger.



    I also think I can write the last Instance List to a global variable and check if they are the same so you don't execute when nothing has changed.


    Here are the files to download

    Media.html.txt

    GetInstance.vb.txt


    Here is the log printout when Get Instance is run
    Jun-01 05:53:33 Event DONE WAIT
    Jun-01 05:53:33 Event Event Trigger "HSTouch SetHSTouchElementUpstairs"
    Jun-01 05:53:33 Event START WAIT
    Jun-01 05:53:33 Event DONE WAIT
    Jun-01 05:53:33 Event Event Trigger "HSTouch SetHSTouchElementBar"
    Jun-01 05:53:33 Event START WAIT
    Jun-01 05:53:33 Event DONE WAIT
    Jun-01 05:53:33 Event Event Trigger "HSTouch SetHSTouchElementMainFloor"
    Jun-01 05:53:33 Event START WAIT
    Jun-01 05:53:33 Event DONE WAIT
    Jun-01 05:53:33 Event Event Trigger "HSTouch SetHSTouchElementMedia"
    Jun-01 05:53:33 Event START WAIT
    Jun-01 05:53:33 Instance HOMESEER-SERVER:MEDIA,HOMESEER-SERVER:MAIN FLOOR,HOMESEER-SERVER:BAR,HOMESEER-SERVER:UPSTAIRS
    Key points - There is one html file and one event per client.


    I also wrote a script to test the parameter send

    Code:
    '06/1/2020 TestParm.vb JLG
    'Pass one parameter and print to log
    
    IMPORTS System.Core
    
    Sub Main(ByVal parms As Object) 'There is 1 parameter
    
    Dim parm As String
    
    If parms.GetType().ToString = "System.String" Then 'Called from an Event
    parm = parms.ToString()
    Else ' Called from HSTouch
    parm = parms(0).ToString()
    End If 'Now use parm as your input variable...
    
    hs.WriteLog("TestParm", parm)
    
    End Sub

    This is what it returns
    Jun-01 05:53:50 TestParm http://HS-Server.gentlan.net/Media.html
    Not the clean resulting text I would have liked but unique and usable.

    Hope others find this useful
    Last edited by AllHailJ; June 1, 2020, 08:58 AM. Reason: Attachements did not load properly

    #2
    https://forums.homeseer.com/forum/ho...16#post1390216

    Comment


      #3
      After noodling on this for awhile, I have written a single script and single event to hit and name all the clients irrespective of origin.

      Code:
      REM HSTouchClientID.vb - JLG
      REM Replacement Script to identify each client uniquely and without user intervention
      REM Started 6-1-2020, First Testing 6-4-2020.
      REM Logic Breakdown
      REM Set Client Text, Client Number, Screen Used For setup.
      REM Get Current Speaker List
      REM Retrieve Saved Speaker List
      REM If Current List is nothing or unchanged - Exit Routine
      REM Split the List into clients
      REM Compare list to clients specified
      REM When Client found set client name
      REM Save most current speaker list to global var
      
      IMPORTS System.Core
      IMPORTS System.IO
      
      Sub Main(ByVal parms As Object)
      
      '--------------------------------------
      'Variable Declaration
      '--------------------------------------
      Dim parm As String
      Dim myList As String
      Dim gList As String
      Dim gVar As String
      Dim i As Integer
      Dim j As Integer
      Dim ListElement As Integer
      Dim ClientName As String
      Dim myClients() As String
      Dim HostClient() As String
      Dim ListClient() As String
      Dim Found As Boolean
      Dim err
      Dim err1
      
      '--------------------------------------
      'User Setup for HSTOUCH Clients
      ' The user should change the three lines below to
      ' The Number of HStouch Clients - 1 --->MaxClients
      ' The HSTouch Screen name where the corresponding elements were created ---> Screen
      ' The names of the Clients ---> Clients " _" must have no characters following or won't compile
      '--------------------------------------
      
      Dim MaxClients As Integer = 9 ' Arrays start at element 0 so Count - 1
      Dim Screen As String = "Setup:" ' The hstouch screen used for setup must have :
      Dim Clients(9) As String
      
      If parms.GetType().ToString = "System.String" Then 'Called from an Event
      parm = parms.ToString()
      Else ' Called from HSTouch
      parm = parms(0).ToString()
      End If 'Now use parm as your input variable...
      
      ' hs.WriteLog("Names", parm)
      
      gvar = "instances"
      Clients(0) = "Android:Main Floor"
      Clients(1) = "Android:Bar"
      Clients(2) = "Android:Media"
      Clients(3) = "Android:Upstairs"
      Clients(4) = "Android:TV-Netflix"
      Clients(5) = "Android:Dad"
      Clients(6) = "Android:JPhone"
      Clients(7) = "Android:GPhone"
      Clients(8) = "AcerLaptop:AcerLaptop"
      Clients(9) = "VirtualDad-Win7:VirtualDad-Win7"
      
      '--------------------------------------
      'Determine the Client List
      ' Please note that the speaker list is serving as a proxy for the client list.
      ' The two are not necessarily the same and there has to be modifications to deal with different sources.
      ' The list is stored in a Global variable named "instances". This is used to check against current list
      ' and if there are no changes to exit the routine. This is an efficiency measure to allow more frequent
      ' calls.
      '--------------------------------------
      
      
      myList = hs.GetInstanceList
      gList = hs.GetVar(gvar)
      ' hs.WriteLog("Names", myList)
      
      If myList = gList Then
      Exit Sub
      End If
      
      If myList Is Nothing Then
      Exit Sub
      End If
      
      '--------------------------------------
      'Find the appropriate Client to Send release element command
      '--------------------------------------
      
      myClients = Split(myList, ",", -1, 1) 'Split InstanceList into individual clients.
      ' hs.WriteLog("Names", myList)
      
      For i = 0 To myClients.Length-1
      
      HostClient = Split(myClients(i), ":", -1, 1) 'Element 1 of HostClient is the hstouch client
      
      ' hs.WriteLog("Names", HostClient(1))
      
      Found = False
      
      For j = 0 to MaxClients
      
      ListClient = Split(Clients(j), ":", -1, 1)
      
      If HostClient(1) = UCase(ListClient(1)) Then
      ListElement = j
      Found = True
      Exit For
      End If
      
      Next
      
      '--------------------------------------
      'Send release element to Tablet Found
      '--------------------------------------
      
      If Found Then
      ' hs.WriteLog("Names", ListClient(1))
      Dim ArrString = New Object() {35, Clients(ListElement), Screen & ListClient(1), ""}
      err1 = hs.PluginFunction("HSTouch Server", "", "ClientAction", ArrString)
      If err1 <> "" then
      hs.WriteLog("Names", "Error from hs.PluginFunction = " & err)
      End If
      Else
      hs.WriteLog("Names", "Client " & myClients(i) & "Not Found - No Action Taken. Client Remains Unnamed")
      End If
      
      Next
      
      err = hs.SaveVar(gvar, myList) 'Save to the Global Variable so minimize runtime
      
      If err <> "" then
      hs.WriteLog("Names", "Error Saving List to Global Variable")
      End If
      
      End Sub
      Here is the file:

      HSTClientID.vb.txt


      Here is a screenshot of the Event that drives the script

      Click image for larger version  Name:	Screenshot from 2020-06-04 22-13-36.png Views:	0 Size:	52.8 KB ID:	1391399

      In HSTouch I created a screen called setup
      Click image for larger version  Name:	Screenshot from 2020-06-04 22-21-39.png Views:	0 Size:	298.5 KB ID:	1391400
      Each Element is the name of a client and the text, Element name and Release action have the same string. The Yellow Box holds the name of the client.

      Here is a shot of the action for an element.

      Click image for larger version  Name:	Screenshot from 2020-06-04 22-24-17.png Views:	0 Size:	5.6 KB ID:	1391401

      The script finds out what is out there and populates it every minute. If the clients don't change, it terminates based on an if check.

      This also requires you to create a global variable.




      Comment

      Working...
      X