Announcement

Collapse
No announcement yet.

HSDesigner

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

  • Guest
    Guest replied
    Originally posted by Sic789 View Post
    So if this is my script how do i put the parameter in from hstouch?
    You actually have to use the CAPI control API in order to control a device.

    I use the following two "helper" functions in my scripts to make my coding life easier. See below:

    Code:
    Private Function SetVirtualVal(ByVal sDevName As String, ByVal dVal As Double) As Integer
    ' Sets the value of a device using CAPI Control
      Dim iRef As Integer = hs.GetDeviceRefByName(sDevName)
      For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(iRef)
        If objCAPIControl.ControlValue = dVal Then
          hs.CAPIControlHandler(objCAPIControl)
          Return 0
        End If
      Next
      hs.WriteLog("error", sDevName + ": " + CStr(dVal))
      Return 1
    End Function
    Private Function TouchParseStr(ByVal parms As Object, ByVal sSep As String, Optional sDef As String = "") As String()
    ' Takes the input parameter, and returns an array of strings.
    ' If called from event, parms is a single string, so does a split on the specified delimiter.
    ' If called from HS Touch, just returns the string array.
    ' Usage: Sub Main(parms As Obect)
    '          Dim p() As String = TouchParseStr(parms, ",") ' p(0) now contains first, p(1) second, etc
      Dim buff() As String
      If parms Is Nothing Then parms = ""
      If parms.GetType().ToString = "System.String" Then
        If parms.ToString() = "" Then parms = sDef
        parms = Trim(parms.ToString())
        buff = parms.Split(sSep)
      Else
        buff = parms
      End If
      Return buff
    End Function
    Sub Main (parms As Object)
      Dim p() As String = TouchParseStr(parms, ",")
      SetVirtualVal("DeviceName", CDbl(p(0)), True) ' Convert string to Double
    End Sub
    Hope this helps.

    Leave a comment:


  • AllHailJ
    replied
    Events pass parameters to subroutines as 1 long string. You have to use a character (delimiter) to split the parameters apart. HSTouch sends multiple parameters and these need to be concatenated to be able to handle the same. I use "|" as the delimeter. If you are only passing one parameter then you can delete everything after the red. Parm becomes your parameter in the single parameter case. you can convert the type from string to Integer by using CInt(). If you need other conversions then look here -https://docs.microsoft.com/en-us/dot...sion-functions. I have no idea why HS decided to do it this way as it seems anti-intuitive to use two methods.

    Sub Main(ByVal parms As Object) 'ByVal Means the parameters will be passed on the stack.

    Dim parm, sParm() As String 'All parameters will start life as a String

    If parms.GetType().ToString = "System.String" Then 'Called from an Event

    parm = parms.ToString() 'Parm is set to a concatenated string

    Else ' Called from HSTouch

    parm = parms(0).ToString() & "|" & parms(1).ToString() & "|" & parms(2).ToString() & "|" & parms(3).ToString() ' create concatenated string so can handle both calls the same

    End If 'Now use parm as your input variable...

    sParm = Split(parm, "|", -1, 1) 'Split into array of parameters. This is not necessary if you only passing one parameter.

    Leave a comment:


  • Sic789
    replied
    So if this is my script how do i put the parameter in from hstouch?


    Main(ByVal Parms As object)

    hs.SetDeviceValueByRef(287, "ScriptParameter1", TRUE)

    End Sub

    Leave a comment:


  • Sic789
    replied
    I have very little coding skills I have no clue how to format the script to get it to use the parameters from HSTouch.

    Originally posted by aa6vh View Post
    Be aware that parameters are passed differently from HS Touch than when called from an Event Action. The Event Action passes a single string, HS Touch passes an array of strings (even if there is only one parameter). The best way to handle this is to declare the parameter in your subroutine declaration as type "Object". Then check within your code as to whether it is a single string or an array of strings.

    Leave a comment:


  • Guest
    Guest replied
    Be aware that parameters are passed differently from HS Touch than when called from an Event Action. The Event Action passes a single string, HS Touch passes an array of strings (even if there is only one parameter). The best way to handle this is to declare the parameter in your subroutine declaration as type "Object". Then check within your code as to whether it is a single string or an array of strings.

    Leave a comment:


  • Sic789
    replied
    I get that but how do I format the script to use the element?

    Leave a comment:


  • AllHailJ
    replied
    On the element you want to activate when pressed, Choose on of the actions and select Run a HomeSeer script with values from elements
    Choose your script and save.

    When an element is pressed the script will run. See screenshot

    Click image for larger version

Name:	Screenshot from 2020-04-02 15-34-32.png
Views:	209
Size:	367.0 KB
ID:	1374638

    Leave a comment:


  • Sic789
    started a topic HSDesigner

    HSDesigner

    I posted this in the designer section but it may be better here. How do you run a script in HSTouch? I want to be able to enter text into a box and have it update a device value.
Working...
X