Announcement

Collapse
No announcement yet.

Parse device string and update as the value of a virtual device

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

    Parse device string and update as the value of a virtual device

    How would I take this device string, parse the 66 from the "Heat: 66" portion and save it as the value of a virtual device?

    String

    #2
    Something like this may work;

    PHP Code:
    Sub Main(ByVal Parms As Object)

    Dim DevStr As String hs.devicestring("X1")
    'change this to the thermostat code

    If Instr(DevStr, "Heat: ") > 1 Then

    Dim ValTherm As String
    ValTherm = DevStr.SubString(Instr(DevStr, "Heat: ") + 5, 2)

    hs.writelog("TestStr", "Temperature Is: " & ValTherm)
    hs.setdevicevalue("Y1", CInt(ValTherm))
    hs.setdevicestring("Y1", "New Temp: " & ValTherm, True)

    '
    update Y1 with your virtual device code

    Else

    hs.writelog("TestStr""Check the device, no string found")

    End If

    End Sub 
    Not sure if its the best code or not and may need some tweaking as I don't have the same device to test it on..

    Comment


      #3
      I just used the zwave thermostat API and populated my own values. I got the main part of the code from the forums somewhere. There's probably something similar for other tstats....

      PHP Code:
      Sub Main(parm as object
      Dim pi As Object 
      Dim fanm
      ,setpc,setph,setp,mode,modeset,temp As String

      Try
      pi hs.Plugin("ZWave Thermostats"
      temp pi.GetTemp(1
      setpc pi.GetCoolSet(1)
      setph pi.GetHeatSet(1)

                  If(
      pi.GetModeSet(1)=0Then
                      modeset
      ="Off"
                  
      ElseIf (pi.GetModeSet(1)=1Then
                      modeset
      ="Heat"
                      
      hs.setdevicestring ("t2",setph,true)
                      
      setp=setph
                  
      ElseIf(pi.GetModeSet(1)=2Then
                      modeset
      ="Cool"
                      
      hs.setdevicestring ("t2",setpc,true)
                      
      setp=setpc
                  
      ElseIf(pi.GetModeSet(1)=3Then
                      modeset
      ="Auto"
                  
      ElseIf(pi.GetModeSet(1)=4Then
                      modeset
      ="Aux"
                  
      End If 


                  If(
      pi.GetCurrentMode(1)=0Then
                      mode
      ="Off"
                  
      ElseIf (pi.GetCurrentMode(1)=1Then
                      mode
      ="Heating"
                  
      ElseIf(pi.GetCurrentMode(1)=2Then
                      mode
      ="Cooling"
                  
      ElseIf(pi.GetCurrentMode(1)=3Then
                      mode
      ="Auto"
                  
      ElseIf(pi.GetCurrentMode(1)=4Then
                      mode
      ="Aux"
                  
      End If 

                  If(
      pi.GetFanMode(1)=0then 
                      fanm
      ="Auto"
                  
      ElseIf(pi.GetFanMode(1)=1then 
                      fanm
      ="On"
                  
      End If

        
      hs.writeLog("debug""Mode Set=[" modeset "] temp=[" temp "]  cool set pt=[" setpc "] heat set pt=[" setph "] mode=[" mode "] fan mode=[" fanm "]"

              Catch 
      As Exception
                  hs
      .WriteLog("debug"e.Message)
              Finally
                  
      pi Nothing
              End 
      Try 

      hs.setdevicestring ("t1","Set to " modeset " - " mode ":Temp " temp ":Fan " fanm ":Set Point " setp,true)


      End Sub 

      Comment


        #4
        Thanks for the help.

        MrHappy,

        I am getting the following error in the script sample you provided when I run it...

        12/13/2010 9:30:27 PM Error Running script, script run or compile error in file: Get Heat SetPoint1006:Expected ')' in line 1 More info: Expected ')'

        -------------------------------------
        Sub Main(ByVal Parms As Object)

        Dim DevStr As String = hs.devicestring("Q19")
        'change this to the thermostat code

        If Instr(DevStr, "Heat: ") > 1 Then

        Dim ValTherm As String
        ValTherm = DevStr.SubString(Instr(DevStr, "Heat: ") + 5, 2)

        hs.writelog("TestStr", "Temperature Is: " & ValTherm)
        hs.setdevicevalue("A17", CInt(ValTherm))
        hs.setdevicestring("A17", "New Temp: " & ValTherm, True)

        'update Y1 with your virtual device code

        Else

        hs.writelog("TestStr", "Check the device, no string found")

        End If

        End Sub
        -------------------------------------------
        Last edited by ccat; December 13, 2010, 10:53 PM.

        Comment


          #5
          I've tested it and I can't get that fault here (however as I say I don't have a thermostat to test with), do you have it running as a .vb file rather than .txt? Its just the error (on line 1) is unusual as I thought Lines1-13 were reserved for HS commands/declarations. And someguysname does make a valid point, picking it from the middle of a device string is possibly the last resort, if there is a thermostat API available i'd have a look for it and see if it gives the option you are after.

          Comment


            #6
            Thanks, I'll take another look when I get home tonight. I'll also try to spend some time on the recommendation from someguysname. Thanks again for your help.

            Comment

            Working...
            X