Announcement

Collapse
No announcement yet.

Monprice Amp Script

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

    Monprice Amp Script

    I wrote up a script for my monoprice amp. I have 5 of these split across 3 locations. So i needed to have 3 com posts listed over my 28 zones.
    I have 3 functions on this script. First is adjusting the turning on and off each zone and adjusting volume in 1 portion. Second to adjust the The channels. Third to query the zones to update the devices. Unfortunately Each running of the script opens and closes the comp ports. So if you try to do too many functions at the same time it will not work. I don't know how to keep the comports open for the scripts to run over and over on short notice. The only parameter needed is to Address the virtual address as A1-18 for volume, C 1 - 18 for channel. Then also modify the Comports as needed.

    Code:
    Imports System.Threading
    Imports System.IO.Ports 
    Public COMPort As New SerialPort()
    Public Sub Main(ByVal Parms as Object)
    
    Dim ParmArray() As String= Parms.tostring.split(",")
            Dim DevRef as String = CStr(ParmArray(0))
            Dim Com as String
        Com = ""
        Dim DevVal as String
        DevVal = hs.DeviceExistsCode(DeVRef)
        Dim Zone as String
        Dim Command as string
        Dim Vol as Object
        Dim Comm as String
        Comm = ""
        Dim Power as String
        Dim rxBuff as String
    
    hs.writelog("Audio", "Starting script: Device is set to " & DevRef)
    
        If  StrComp (DevRef, "A1", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com4"
        Elseif StrComp (DevRef, "A2", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com4"
        Elseif StrComp (DevRef, "A3", vbTextCompare) = 0 Then
            Zone = 13
            Com = "Com4"
        Elseif StrComp (DevRef, "A4", vbTextCompare) = 0 Then
            Zone = 14
            Com = "Com4"
        Elseif StrComp (DevRef, "A5", vbTextCompare) = 0 Then
            Zone = 15
            Com = "Com4"
        Elseif StrComp (DevRef, "A6", vbTextCompare) = 0 Then
            Zone = 16
            Com = "Com4"
        Elseif StrComp (DevRef, "A7", vbTextCompare) = 0 Then
            Zone = 21
            Com = "Com4"
        Elseif StrComp (DevRef, "A8", vbTextCompare) = 0 Then
            Zone = 22
            Com = "Com4"
        Elseif StrComp (DevRef, "A9", vbTextCompare) = 0 Then
            Zone = 23
            Com = "Com4"
        Elseif StrComp (DevRef, "A10", vbTextCompare) = 0 Then
            Zone = 24
            Com = "Com4"
        Elseif StrComp (DevRef, "A11", vbTextCompare) = 0 Then
            Zone = 25
            Com = "Com4"
        Elseif StrComp (DevRef, "A12", vbTextCompare) = 0 Then
            Zone = 26
            Com = "Com4"
        Elseif StrComp (DevRef, "A13", vbTextCompare) = 0 Then
            Zone = 31
            Com = "Com4"
        Elseif StrComp (DevRef, "A14", vbTextCompare) = 0 Then
            Zone = 32
            Com = "Com4"
        Elseif StrComp (DevRef, "A15", vbTextCompare) = 0 Then
            Zone = 33
            Com = "Com4"
        Elseif StrComp (DevRef, "A16", vbTextCompare) = 0 Then
            Zone = 34
            Com = "Com4"
        Elseif StrComp (DevRef, "A17", vbTextCompare) = 0 Then
            Zone = 35
            Com = "Com4"
        Elseif StrComp (DevRef, "A18", vbTextCompare) = 0 Then
            Zone = 36
            Com = "Com4"
        Elseif StrComp (DevRef, "A19", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com3"
        Elseif StrComp (DevRef, "A20", vbTextCompare) = 0 Then
            Zone = 12
            Com = "Com3"
        Elseif StrComp (DevRef, "A21", vbTextCompare) = 0 Then
            Zone = 13
            Com = "Com3"
        Elseif StrComp (DevRef, "A22", vbTextCompare) = 0 Then
            Zone = 14
            Com = "Com3"
        Elseif StrComp (DevRef, "A23", vbTextCompare) = 0 Then
            Zone = 15
            Com = "Com3"
        Elseif StrComp (DevRef, "A24", vbTextCompare) = 0 Then
            Zone = 16
            Com = "Com3"
        Elseif StrComp (DevRef, "A25", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com1"
        Elseif StrComp (DevRef, "A26", vbTextCompare) = 0 Then
            Zone = 12
            Com = "Com1"
        Elseif StrComp (DevRef, "A27", vbTextCompare) = 0 Then
            Zone = 13
            Com = "Com1"
        Elseif StrComp (DevRef, "A28", vbTextCompare) = 0 Then
            Zone = 14
            Com = "Com1"
        Elseif StrComp (DevRef, "C1", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com4"
        Elseif StrComp (DevRef, "C2", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com4"
        Elseif StrComp (DevRef, "C3", vbTextCompare) = 0 Then
            Zone = 13
            Com = "Com4"
        Elseif StrComp (DevRef, "C4", vbTextCompare) = 0 Then
            Zone = 14
            Com = "Com4"
        Elseif StrComp (DevRef, "C5", vbTextCompare) = 0 Then
            Zone = 15
            Com = "Com4"
        Elseif StrComp (DevRef, "C6", vbTextCompare) = 0 Then
            Zone = 16
            Com = "Com4"
        Elseif StrComp (DevRef, "C7", vbTextCompare) = 0 Then
            Zone = 21
            Com = "Com4"
        Elseif StrComp (DevRef, "C8", vbTextCompare) = 0 Then
            Zone = 22
            Com = "Com4"
        Elseif StrComp (DevRef, "C9", vbTextCompare) = 0 Then
            Zone = 23
            Com = "Com4"
        Elseif StrComp (DevRef, "C10", vbTextCompare) = 0 Then
            Zone = 24
            Com = "Com4"
        Elseif StrComp (DevRef, "C11", vbTextCompare) = 0 Then
            Zone = 25
            Com = "Com4"
        Elseif StrComp (DevRef, "C12", vbTextCompare) = 0 Then
            Zone = 26
            Com = "Com4"
        Elseif StrComp (DevRef, "C13", vbTextCompare) = 0 Then
            Zone = 31
            Com = "Com4"
        Elseif StrComp (DevRef, "C14", vbTextCompare) = 0 Then
            Zone = 32
            Com = "Com4"
        Elseif StrComp (DevRef, "C15", vbTextCompare) = 0 Then
            Zone = 33
            Com = "Com4"
        Elseif StrComp (DevRef, "C16", vbTextCompare) = 0 Then
            Zone = 34
            Com = "Com4"
        Elseif StrComp (DevRef, "C17", vbTextCompare) = 0 Then
            Zone = 35
            Com = "Com4"
        Elseif StrComp (DevRef, "C18", vbTextCompare) = 0 Then
            Zone = 36
            Com = "Com4"
        Elseif StrComp (DevRef, "C19", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com3"
        Elseif StrComp (DevRef, "C20", vbTextCompare) = 0 Then
            Zone = 12
            Com = "Com3"
        Elseif StrComp (DevRef, "C21", vbTextCompare) = 0 Then
            Zone = 13
            Com = "Com3"
        Elseif StrComp (DevRef, "C22", vbTextCompare) = 0 Then
            Zone = 14
            Com = "Com3"
        Elseif StrComp (DevRef, "C23", vbTextCompare) = 0 Then
            Zone = 15
            Com = "Com3"
        Elseif StrComp (DevRef, "C24", vbTextCompare) = 0 Then
            Zone = 16
            Com = "Com3"
        Elseif StrComp (DevRef, "C25", vbTextCompare) = 0 Then
            Zone = 11
            Com = "Com1"
        Elseif StrComp (DevRef, "C26", vbTextCompare) = 0 Then
            Zone = 12
            Com = "Com1"
        Elseif StrComp (DevRef, "C27", vbTextCompare) = 0 Then
            Zone = 13
            Com = "Com1"
        Elseif StrComp (DevRef, "C28", vbTextCompare) = 0 Then
            Zone = 14
            Com = "Com1"
        End If
    
    hs.writelog("Audio", "Zone is " & Zone & " Com is " & Com)
    
    Dim Type as String
    Type = DevRef.Substring(0, 1)
    
    hs.writelog("Audio", "Type is " & Type)
    
    If  StrComp (Type, "A", vbTextCompare) = 0 Then
    
    Vol = hs.DeviceValue(DevVal)
    
    If Vol <10 and
        Vol >0 then
        Vol = "0" & Vol
    
    End if
    
    If Vol <37 and
        Vol >0 then
        command = "<" & Zone & "VO" & Vol
    
    Elseif vol < 1 
        Vol = "0" & Vol
        command = "<" & Zone & "PR00"
    
    End if
    
    hs.writelog("Audio", "Volume is " & Vol)
    
        COMPort.PortName = Com
        COMPort.BaudRate = 9600
        COMPort.Parity = System.IO.Ports.Parity.None
        COMPort.DataBits = 8
        COMPort.StopBits = System.IO.Ports.StopBits.One
        Comport.ReadTimeout = 1000
    
        hs.writelog("Audio", "Main() Called - Attempting To Open")
    
        If COMPort.IsOpen = False Then 
            COMPort.Open() 
        End If
        Comm = "?" & Zone & "PR" & vbCr
        hs.writelog("Audio", "Sending: " & Comm)
    
        'writes to com port
        COMPort.Write(Comm)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        hs.writelog("Audio", "Port Open - Sending Data")
    
        Comm = "<" & Zone & "PR01" & vbCr
        hs.writelog("Audio", "Sending: " & Comm)
    
        'writes to com port
        COMPort.Write(Comm)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        If rxBuff <> "" Then
            hs.writelog("Audio", "Received:" & rxBuff)
            rxBuff = ""
        End If
    
        hs.writelog("Audio", "Port Open - Sending Data")
    
        Comm = Command & vbCr
        hs.writelog("Audio", "Sending: " & Comm)
    
        'writes to com port
        COMPort.Write(Comm)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        If rxBuff <> "" Then
            hs.writelog("Audio", "Received:" & rxBuff)
            rxBuff = ""
    
        End If
    
    COMPort.close()
    
    hs.writelog("Audio", "Ended")
    
    
    Exit Sub
    
    Elseif StrComp (Type, "C", vbTextCompare) = 0 Then
    
    Vol = hs.DeviceValue(DevVal)
    
    If Vol <10 and
        Vol >0 then
        Vol = "0" & Vol
    
    End if
    
    If Vol <6 and
        Vol >0 then
        command = "<" & Zone & "CH" & Vol
    
    Elseif vol < 1 
        Vol = "0" & Vol
        command = "<" & Zone & "PR00"
    
    End if
    
    hs.writelog("Audio", "Volume is " & Vol)
    
        COMPort.PortName = Com
        COMPort.BaudRate = 9600
        COMPort.Parity = System.IO.Ports.Parity.None
        COMPort.DataBits = 8
        COMPort.StopBits = System.IO.Ports.StopBits.One
        Comport.ReadTimeout = 1000
    
        hs.writelog("Audio", "Main() Called - Attempting To Open")
    
        If COMPort.IsOpen = False Then 
            COMPort.Open() 
        End If
        Comm = "?" & Zone & "PR" & vbCr
        hs.writelog("Audio", "Sending: " & Comm)
    
        'writes to com port
        COMPort.Write(Comm)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        hs.writelog("Audio", "Port Open - Sending Data")
    
        Comm = "<" & Zone & "PR01" & vbCr
        hs.writelog("Audio", "Sending: " & Comm)
    
        'writes to com port
        COMPort.Write(Comm)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        If rxBuff <> "" Then
            hs.writelog("Audio", "Received:" & rxBuff)
            rxBuff = ""
        End If
    
        hs.writelog("Audio", "Port Open - Sending Data")
    
        Comm = Command & vbCr
        hs.writelog("Audio", "Sending: " & Comm)
    
        'writes to com port
        COMPort.Write(Comm)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        If rxBuff <> "" Then
            hs.writelog("Audio", "Received:" & rxBuff)
            rxBuff = ""
    
        End If
    
    COMPort.close()
    
    hs.writelog("Audio", "Ended")
    
    Exit Sub
    
    Elseif StrComp (Type, "B", vbTextCompare) = 0 Then
    
        hs.writelog("Audio", "Starting script: Updating all Devices")    
    
        COMPort.PortName = "COM4"
        COMPort.BaudRate = 9600
        COMPort.Parity = System.IO.Ports.Parity.None
        COMPort.DataBits = 8
        COMPort.StopBits = System.IO.Ports.StopBits.One
        Comport.ReadTimeout = 1000
    
        hs.writelog("Audio", "Main() Called - Attempting To Open")
    
        If COMPort.IsOpen = False Then 
            COMPort.Open() 
        End If
    
        hs.writelog("Audio", "Port Open - Sending Data")
    
        Com = "?10" & vbCr
        hs.writelog("Audio", "Sending: " & Com)
    
        'writes to com port
        COMPort.Write(Com)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
        Dim Volume as String
        Dim Channel as String
    
        Zone = rxBuff.Substring(7, 2)
        Power = rxBuff.Substring(11, 2)
        Volume = rxBuff.Substring(17, 2)
        Channel = rxBuff.Substring(25, 2)
    
            hs.writelog("Audio", "Received:" & rxBuff)
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A1")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C1")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A1")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
    
        Zone = rxBuff.Substring(34, 2)
        Power = rxBuff.Substring(38, 2)
        Volume = rxBuff.Substring(44, 2)
        Channel = rxBuff.Substring(52, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A2")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C2")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A2")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(61, 2)
        Power = rxBuff.Substring(65, 2)
        Volume = rxBuff.Substring(71, 2)
        Channel = rxBuff.Substring(79, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A3")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C3")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A3")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(88, 2)
        Power = rxBuff.Substring(92, 2)
        Volume = rxBuff.Substring(98, 2)
        Channel = rxBuff.Substring(106, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A4")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C4")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A4")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(115, 2)
        Power = rxBuff.Substring(119, 2)
        Volume = rxBuff.Substring(125, 2)
        Channel = rxBuff.Substring(133, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A5")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C5")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A5")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(142, 2)
        Power = rxBuff.Substring(146, 2)
        Volume = rxBuff.Substring(152, 2)
        Channel = rxBuff.Substring(160, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A6")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C6")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A6")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Com = "?20" & vbCr
        hs.writelog("Audio", "Sending: " & Com)
    
        'writes to com port
        COMPort.Write(Com)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        Zone = rxBuff.Substring(7, 2)
        Power = rxBuff.Substring(11, 2)
        Volume = rxBuff.Substring(17, 2)
        Channel = rxBuff.Substring(25, 2)
    
            hs.writelog("Audio", "Received:" & rxBuff)
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A7")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C7")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A7")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(34, 2)
        Power = rxBuff.Substring(38, 2)
        Volume = rxBuff.Substring(44, 2)
        Channel = rxBuff.Substring(52, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A8")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C8")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A8")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
    
        Zone = rxBuff.Substring(61, 2)
        Power = rxBuff.Substring(65, 2)
        Volume = rxBuff.Substring(71, 2)
        Channel = rxBuff.Substring(79, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A9")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C9")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A9")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(88, 2)
        Power = rxBuff.Substring(92, 2)
        Volume = rxBuff.Substring(98, 2)
        Channel = rxBuff.Substring(106, 2)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A10")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C10")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A10")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
        Zone = rxBuff.Substring(115, 2)
        Power = rxBuff.Substring(119, 2)
        Volume = rxBuff.Substring(125, 2)
        Channel = rxBuff.Substring(133, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A11")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C11")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A11")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(142, 2)
        Power = rxBuff.Substring(146, 2)
        Volume = rxBuff.Substring(152, 2)
        Channel = rxBuff.Substring(160, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A12")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C12")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A12")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
    
        Com = "?30" & vbCr
        hs.writelog("Audio", "Sending: " & Com)
    
        'writes to com port
        COMPort.Write(Com)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        Zone = rxBuff.Substring(7, 2)
        Power = rxBuff.Substring(11, 2)
        Volume = rxBuff.Substring(17, 2)
        Channel = rxBuff.Substring(25, 2)
    
            hs.writelog("Audio", "Received:" & rxBuff)
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A13")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C13")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A13")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(34, 2)
        Power = rxBuff.Substring(38, 2)
        Volume = rxBuff.Substring(44, 2)
        Channel = rxBuff.Substring(52, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A14")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C14")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A14")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(61, 2)
        Power = rxBuff.Substring(65, 2)
        Volume = rxBuff.Substring(71, 2)
        Channel = rxBuff.Substring(79, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A15")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C15")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A15")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(88, 2)
        Power = rxBuff.Substring(92, 2)
        Volume = rxBuff.Substring(98, 2)
        Channel = rxBuff.Substring(106, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A16")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C16")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A16")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(115, 2)
        Power = rxBuff.Substring(119, 2)
        Volume = rxBuff.Substring(125, 2)
        Channel = rxBuff.Substring(133, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A17")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C17")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A17")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(142, 2)
        Power = rxBuff.Substring(146, 2)
        Volume = rxBuff.Substring(152, 2)
        Channel = rxBuff.Substring(160, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A18")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C18")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A18")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        COMPort.close()
    
    System.Threading.Thread.Sleep(600)
    
    hs.writelog("Audio", "Starting script: Updating all Devices")    
    
        COMPort.PortName = "COM3"
        COMPort.BaudRate = 9600
        COMPort.Parity = System.IO.Ports.Parity.None
        COMPort.DataBits = 8
        COMPort.StopBits = System.IO.Ports.StopBits.One
        Comport.ReadTimeout = 1000
    
        hs.writelog("Audio", "Main() Called - Attempting To Open")
    
        If COMPort.IsOpen = False Then 
            COMPort.Open() 
        End If
    
        hs.writelog("Audio", "Port Open - Sending Data")
    
        Com = "?10" & vbCr
        hs.writelog("Audio", "Sending: " & Com)
    
        'writes to com port
        COMPort.Write(Com)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
        Zone = rxBuff.Substring(7, 2)
        Power = rxBuff.Substring(11, 2)
        Volume = rxBuff.Substring(17, 2)
        Channel = rxBuff.Substring(25, 2)
    
            hs.writelog("Audio", "Received:" & rxBuff)
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A19")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C19")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A19")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(34, 2)
        Power = rxBuff.Substring(38, 2)
        Volume = rxBuff.Substring(44, 2)
        Channel = rxBuff.Substring(52, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A20")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C20")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A20")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(61, 2)
        Power = rxBuff.Substring(65, 2)
        Volume = rxBuff.Substring(71, 2)
        Channel = rxBuff.Substring(79, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A21")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C21")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A21")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(88, 2)
        Power = rxBuff.Substring(92, 2)
        Volume = rxBuff.Substring(98, 2)
        Channel = rxBuff.Substring(106, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A22")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C22")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A22")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(115, 2)
        Power = rxBuff.Substring(119, 2)
        Volume = rxBuff.Substring(125, 2)
        Channel = rxBuff.Substring(133, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A23")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C23")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A23")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(142, 2)
        Power = rxBuff.Substring(146, 2)
        Volume = rxBuff.Substring(152, 2)
        Channel = rxBuff.Substring(160, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A24")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C24")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A24")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
    COMPort.close()
    
    
    System.Threading.Thread.Sleep(600)
    
    
    hs.writelog("Audio", "Starting script: Updating all Devices")    
    
        COMPort.PortName = "COM1"
        COMPort.BaudRate = 9600
        COMPort.Parity = System.IO.Ports.Parity.None
        COMPort.DataBits = 8
        COMPort.StopBits = System.IO.Ports.StopBits.One
        Comport.ReadTimeout = 1000
    
        hs.writelog("Audio", "Main() Called - Attempting To Open")
    
        If COMPort.IsOpen = False Then 
            COMPort.Open() 
        End If
    
        hs.writelog("Audio", "Port Open - Sending Data")
    
        Com = "?10" & vbCr
        hs.writelog("Audio", "Sending: " & Com)
    
        'writes to com port
        COMPort.Write(Com)
    
        System.Threading.Thread.Sleep(600)
    
        'Reading the com port:
        rxBuff = (COMPort.ReadExisting)
    
    If rxBuff = "" Then 
        COMPort.close()
        hs.writelog("Audio", "Gazebo Stero is Off")
    
    Elseif rxBuff <>"" then
        Zone = rxBuff.Substring(7, 2)
        Power = rxBuff.Substring(11, 2)
        Volume = rxBuff.Substring(17, 2)
        Channel = rxBuff.Substring(25, 2)
    
            hs.writelog("Audio", "Received:" & rxBuff)
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A25")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C25")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A25")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(34, 2)
        Power = rxBuff.Substring(38, 2)
        Volume = rxBuff.Substring(44, 2)
        Channel = rxBuff.Substring(52, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A26")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C26")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A26")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(61, 2)
        Power = rxBuff.Substring(65, 2)
        Volume = rxBuff.Substring(71, 2)
        Channel = rxBuff.Substring(79, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A27")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C27")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A27")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(88, 2)
        Power = rxBuff.Substring(92, 2)
        Volume = rxBuff.Substring(98, 2)
        Channel = rxBuff.Substring(106, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
    If Channel = 01 Then
        Channel = "Sonos"
    Elseif Channel = 02 Then 
        Channel = "Computer"
    Elseif Channel = 03 Then 
        Channel = "Tv"
    Elseif Channel = 04 Then 
        Channel = "Alexa"
    Elseif Channel = 05 Then 
        Channel = "Bluetooth"
    Elseif Channel = 06 Then 
        Channel = "Chromecast"
    End If
    
    If Power = 01 Then
    
        DevVal = hs.DeviceExistsCode("A28")
        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cc.ControlValue = Volume
            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
        DevVal = hs.DeviceExistsCode("C28")
            hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevVal,true ,Channel,false,true))
    
    Elseif Power = 00 Then 
    
        DevVal = hs.DeviceExistsCode("A28")
            Dim cd As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DevVal, True, "(Value)", False, False)
            cd.ControlValue = Power
            Dim cs As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cd)
    End If
        Zone = rxBuff.Substring(115, 2)
        Power = rxBuff.Substring(119, 2)
        Volume = rxBuff.Substring(125, 2)
        Channel = rxBuff.Substring(133, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    
        Zone = rxBuff.Substring(142, 2)
        Power = rxBuff.Substring(146, 2)
        Volume = rxBuff.Substring(152, 2)
        Channel = rxBuff.Substring(160, 2)
    
            hs.writelog("Audio", "Zone:" & Zone & " has power at " & Power & " Volume at " & Volume & " Channel at " & Channel)
    End If
    
    COMPort.close()
    
    Exit Sub
    End IF
    
    End Sub
Working...
X