Announcement

Collapse
No announcement yet.

HS3 scripting transcoding

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

    HS3 scripting transcoding

    Hello,

    I used a simple script within HS2 to check an oregon temp sensor value, compare this with the value of a virtual device (settemp) and control a X10 appliance (floorheater relay):

    HS2:

    Code:
    Sub Main(Byval parm as object)
    
    dim realtemp As Single
    dim settemp As Single
    realtemp = hs.devicevalue("\14")/10
    settemp = hs.devicevalue("V6")
    
    If realtemp > settemp Then
    hs.execX10("A1", "Off", 0, 0)
    End if
    
    If realtemp < settemp Then
    hs.execX10("A1", "On", 0, 0)
    End If
    
    End Sub
    I've tried to convert this script to HS3:

    Code:
    Public Sub Main(parms as object)
    
    dim realtemp As Single
    dim settemp As Single
    
    realtemp = hs.DeviceValueEx("T1")
    settemp = hs.DeviceValueEx("v1")
    
    If realtemp > settemp Then
    hs.setDeviceValue("A1", 100)
    End if
    
    If realtemp < settemp Then
    hs.setDeviceValue("A1", 100)
    End If
    
    End Sub
    And now I get this log-result:

    Running script C:\Program Files (x86)\HomeSeer HS3\scripts\Controleer temperatuur woonkamer en stel bij.vb :Het doel van een aanroep heeft een uitzondering veroorzaakt.De conversie van tekenreeks T1 naar type Integer is ongeldig

    translation:

    conversion from string T1 to type Integer is not valid

    What am I doing wrong?

    #2
    hs.DeviceValueEx expects a reference not a code (a reference is a number not a device code) so you need to replace it with the reference and then try again...whether or not setting the value of the device as a means to turn it on/off will work or not will depend on how the plugin is written but if it does not work search around for the CAPI thread.

    Comment


      #3
      Thanks MrHappy,

      I used your advice and got the script working like a charm. For others who would like an example, this is my working script:

      Public Sub Main(parms as object)

      dim realtemp As Single
      dim settemp As Single
      dim objCAPIControl As CAPIControl
      dim dvRef as Integer

      realtemp = hs.DeviceValueEx("40")
      settemp = hs.DeviceValueEx("91")
      dvRef = hs.GetDeviceRefByName("Vloerverwarming")

      If realtemp > settemp Then
      objCAPIControl = hs.CAPIGetSingleControl(3,true,"off",false,true)
      hs.CAPIControlHandler(objCAPIControl)
      hs.writelog("Temperatuur woonkamer is:",hs.DeviceValueEx("40")&" Graden")
      hs.writelog("Ingestelde temperatuur woonkamer is:",hs.DeviceValueEx("91")&" Graden")
      hs.writelog("Vloer verwarming woonkamer is:",hs.DeviceValueEx("3")&" (100= aan, 0= uit)")

      End if

      If realtemp < settemp Then
      objCAPIControl = hs.CAPIGetSingleControl(3,true,"on",false,true)
      hs.CAPIControlHandler(objCAPIControl)
      hs.writelog("Temperatuur woonkamer is:",hs.DeviceValueEx("40")&" Graden")
      hs.writelog("Ingestelde temperatuur woonkamer is:",hs.DeviceValueEx("91")&" Graden")
      hs.writelog("Vloer verwarming woonkamer is:",hs.DeviceValueEx("3")&" (100= aan, 0= uit)")

      If objCAPIControl IsNot Nothing Then
      hs.CAPIControlHandler(objCAPIControl)

      End if

      End If

      End Sub

      I still need to figure out to write a nice log output for a X10 device status (on/off) so that is the reason for the text description 100=aan, 0=uit (100=on, 0=off) :-)

      Comment

      Working...
      X