Jeg har laget ett script for Multiroom Audio. Jeg har basert det på 3 chromcast, to til radio, og en som er dedikert til å spille Spotify, Tidal eller annen streaming. Jeg har laget events som kobler opp inngang mot utgang, og som stopper, muter og justerer volum. Tilkobling til matrisa mi, som er en ClearOne PSR1212, er gjort ved hjelp av Drules IP plugin. Devicene er foreløpig laget manuelt, og det er kun enveis til matrisa. Dette er ting som sannsynligvis kommer i forbedringer av skriptet.
 
	 
 
	Dette er mitt første nogenlunde fornuftige program i vb.net, så det er lov å komme med forslag til forbedring. Sikkert mange plasser dette kunne vært gjort smartere. 
 
	 
 
	Koden er vist under.
 
	 
 
   Dim Inngangskorreksjon As Integer = 6
    Dim Rooms() As String = {"Bad", "Kjøkken", "Forside", "Vaskerom", "Garasje", "Stue", "Soverom", "Kjellergang", "Forside"}
    Dim Kanaler() As String = {"NRK P1", "NRK P1+", "P4", "NRJ", "Radio Norge"}
    Dim Player As String = "Chromecast_kanal_"
    Dim NumberOfPlayers As Integer = 2
    Dim Parameter1 As String
    Dim Room As String
    Dim Roomstatus As String
    Dim index As Integer
    Dim Utgang As Integer
    Public Sub Main(ByVal Parms As Object)
        Dim input() As String = SplitParameters(Parms)
        Room = Input(1)
        Parameter1 = input(0)
        ActionChoice(Parameter1, Room)
    End Sub
    Public Sub TouchMain(ByVal Parms As Object)
        Parameter1 = Parms(0).ToString
        Room = Parms(1).ToString
        ActionChoice(Parameter1, Room)
    End Sub
    'Setter Action etter hva Parameter1 er 
    Public Sub ActionChoice(ByVal Parameter1 As String, ByVal Room As String)
        Dim Utgang As Integer = Array.IndexOf(Rooms, Room) + 1
        Select Case Parameter1
            Case "VOL UP"
                hs.TriggerEvent("Volum Opp Utgang " & Utgang)
            Case "VOL DWN"
                hs.TriggerEvent("Volum ned Utgang " & Utgang)
            Case "Slå av Rom"
                hs.WriteLog("slå av rom", "Slå av Rom")
                Stop_Room(Room)
            Case "Mute"
                hs.TriggerEvent("Mute Utgang " & Utgang)
            Case "Media"
                hs.TriggerEvent("Koble ned Utgang " & Utgang)
                hs.TriggerEvent("Koble inngang 1 til utgang " & Utgang)
            Case "Lyd fra TV"
                hs.TriggerEvent("Koble ned Utgang " & Utgang)
                hs.TriggerEvent("Koble inngang 2 til utgang " & Utgang)
            Case Else
                SetPlayer(Parameter1)               'Sender verdier til Homeseer
                Sett_Utgang()
                SetHSValues()
        End Select
    End Sub
    'Splitter Parms inn i de to parameterne som den skal være
    Public Function SplitParameters(ByVal Params As Object) As String()
        Dim SplitString As String
        SplitString = Params.ToString
        Dim Parameters As String() = SplitString.Split(New Char() {"|"c})
        Return Parameters
    End Function
    'Setter hvilken spille som skal spille
    Public Sub SetPlayer(ByVal Radiokanal As String)
        Dim Channelplay As Integer = ChannelPlaying(Parameter1)
        'Sjekker hvilken spiller som har spilt lengst - Returnerer Setplayer til ActionChoice
        Dim Timers(NumberOfPlayers) As String
        Dim RadioChannel(NumberOfPlayers) As String
        Dim t, i, Max As Integer
        For t = 1 To NumberOfPlayers
            Timers(t) = hs.DeviceValueByName(Player & "timer_" & t)
            If Timers(t) = 0 Then
                index = t
                Exit For
            Else
                If Channelplay = 0 Then
                    For i = 1 To UBound(Timers)
                        If Timers(i) > Timers(Max) Then
                            Max = i
                        End If
                    Next
                    index = Max
                    Disconnect_playing()
                Else
                    index = Channelplay
                End If
            End If
        Next
    End Sub
    'Setter hvilken utgang som skal brukes
    Public Sub Sett_Utgang()
        Dim Checkparameter As Integer = Array.IndexOf(Rooms, Parameter1) + 1
        If Checkparameter = 0 Then
            Utgang = Array.IndexOf(Rooms, Room) + 1
        Else
            If Roomstatus = "Off" Then Exit Sub
            'index = Right(Roomstatus, 1)
            Utgang = Array.IndexOf(Rooms, Parameter1) + 1
        End If
    End Sub
    'skriver Verdier til HS3
    Public Sub SetHSValues()
        Dim Playing As Integer = ChannelPlaying(Parameter1)
        Dim Inngang As Integer = index + Inngangskorreksjon
        Dim kanal As Integer
        kanal = Array.IndexOf(Kanaler, Parameter1) + 1
        If Playing = False Then
            hs.SetDeviceValueByName(Player & index, kanal)
        End If
        hs.WriteLog("etst", "Koble Inngang " & Inngang & " til Utgang " & Utgang)
        hs.SetDeviceValueByName("Utgang " & Utgang & " - " & Room, index)
        hs.TriggerEvent("Koble ned Utgang " & Utgang)
        hs.TriggerEvent("Start Chromecast Timer " & index)
        hs.TriggerEvent("Koble Inngang " & Inngang & " til Utgang " & Utgang)
    End Sub
    'Sjekker om kanalen spiller i noen av spilerne
    Public Function ChannelPlaying(ByVal Channel As String) As Integer
        Dim t As Integer
        For t = 1 To 2
            Dim Channelstatus = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName(Player & t), hs.DeviceValueByName(Player & t), 1)
            If Channel = Channelstatus Then
                ChannelPlaying = t
                Exit For
            End If
        Next
        Return ChannelPlaying
    End Function
    'Sjekker om noen av utgangene spiller den kanalen fra før
    Public Function SpotiPlaying() As Boolean
        Dim Roomstatus = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Utgang " & Utgang & " - " & Room), hs.DeviceValueByName("Utgang " & Utgang & " - " & Room), 1)
        Dim SpotiPlay As String = Right(Roomstatus, 1)
        For t = 1 To 9
            If t = Utgang Then
                Continue For
            End If
            Dim SpotiPlaytestValue = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Utgang " & t & " - " & Rooms(t - 1)), hs.DeviceValueByName("Utgang " & t & " - " & Rooms(t - 1)), 1)
            If SpotiPlaytestValue <> "Off" Then
                Dim spotiplaytest As String = Right(SpotiPlaytestValue, 1)
                If SpotiPlay = spotiplaytest Then
                    SpotiPlaying = True
                    Exit For
                End If
            End If
        Next
        Return SpotiPlaying
    End Function
    'Slå av Rom
    Public Sub Stop_Room(ByVal Room As String)
        Sett_Utgang()
        Dim Playing As Boolean = SpotiPlaying()
        Dim Roomstatus = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Utgang " & Utgang & " - " & Room), hs.DeviceValueByName("Utgang " & Utgang & " - " & Room), 1)
        If Playing = False Then
            hs.WriteLog("Roomstatus", Roomstatus)
            If Right(Roomstatus, 1) <= NumberOfPlayers Then
                hs.TriggerEvent("Stopp Chromecast Timer " & Right(Roomstatus, 1))
                hs.SetDeviceValueByName(Player & Right(Roomstatus, 1), 0)
                hs.SetDeviceValueByName("ChromeCast status " & Right(Roomstatus, 1), 1)
            End If
        End If
        hs.TriggerEvent("Koble ned Utgang " & Utgang)
        hs.SetDeviceValueByName("Utgang " & Utgang & " - " & Room, 0)
    End Sub
    Public Sub Disconnect_playing()
        For t = 0 To 8
            Dim Status = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Utgang " & t + 1 & " - " & Rooms(t)), hs.DeviceValueByName("Utgang " & t + 1 & " - " & Rooms(t)), 1)
            If Status <> "Off" Then
                If Right(Status, 1) = index Then
                    hs.TriggerEvent("Koble ned Utgang " & t + 1)
                    hs.SetDeviceValueByName("Utgang " & t + 1 & " - " & Rooms(t), 0)
                    hs.WriteLog("Utgang", "Utgang " & t + 1 & " - " & Rooms(t))
                End If
            End If
        Next
    End Sub