Jump to content
  • Sign Up
Støtt hjemmeautomasjon.no!

SCRIPT: GrandbeingMX0404 - Styring av en 4x4 HDMI-matrise


Moskus

Recommended Posts

GrandbeingMX0404.vb

Script for å styre en Grandbeing MX0404 HDMI matrise. Lager en root med tilhørende child-devicer for hver utgang hvor man kan trykke på de forskjellige inngangene. Alt i et script, men dette blir nok en plugin på sikt (der er det lettere å få til en autorefresh, og sånt).

    '© Moskus 2014
    
    Dim Scriptname As String = "GrandbeingMX0404.vb"
    Dim hdmi_outputs() As String = {"None", "TV", "SageTV", "Xbox", "Extra"}
    Dim ip_address As String = "192.168.0.39"

    Public Sub Main(parm As Object)
    End Sub

    Public Sub Setup(parm As Object)
        'Setting up devices

        'Creating master device
        Dim dt As New HomeSeerAPI.DeviceTypeInfo
        Dim devref As Integer = hs.NewDeviceRef("Root")
        Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devref)
        Try
            dv.Location(hs) = "HDMI matrix"
            dv.Location2(hs) = "Media"
            dv.Device_Type_String(hs) = "HDMI root"
            dv.DeviceType_Set(hs) = New HomeSeerAPI.DeviceTypeInfo
            dv.Status_Support(hs) = True
            dv.Can_Dim(hs) = False
            hs.SaveEventsDevices()
            dv.MISC_Set(hs, HomeSeerAPI.Enums.dvMISC.SHOW_VALUES)
            dv.MISC_Clear(hs, HomeSeerAPI.Enums.dvMISC.STATUS_ONLY)

            'Adding a "Refresh" button to the root device
            hs.DeviceScriptButton_AddButton(devref, "Refresh", 0, Scriptname, "ButtonPress", "Refresh", 1, 1, 1)
            hs.SaveEventsDevices()

            Dim SVpair As New HomeSeerAPI.VSPair(HomeSeerAPI.ePairStatusControl.Status)
            SVpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue
            SVpair.Value = 0
            SVpair.Status = "HDMI matrix"
            hs.DeviceVSP_AddPair(devref, SVpair)

            Dim VGpair As New HomeSeerAPI.VGPair
            VGpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue
            VGpair.Set_Value = 0
            VGpair.Graphic = "images/Moskus/icon_hdmi.png"
            hs.DeviceVGP_AddPair(devref, VGpair)

            hs.WriteLog("HDMI matrix", "Root device for HDMI matrix created")
        Catch ex As Exception
            hs.WriteLog("HDMI matrix", "Error creating root device: " & ex.Message)
        End Try

        'Creating child devices
        dv.Relationship(hs) = HomeSeerAPI.Enums.eRelationship.Parent_Root
        For i As Integer = 1 To 4
            Dim childref As Integer = CreateOutputDevice(i, devref)
            If childref > 0 Then dv.AssociatedDevice_Add(hs, childref)
        Next

    End Sub

    Public Function CreateOutputDevice(ByVal output As Integer, masterdevice As Integer) As Integer
        'Creating device
        Dim dt As New HomeSeerAPI.DeviceTypeInfo
        Dim devref As Integer = hs.NewDeviceRef("Output " & output)
        Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devref)
        Try
            dv.Location(hs) = "HDMI matrix"
            dv.Location2(hs) = "Media"
            dv.Device_Type_String(hs) = "HDMI out " & output
            dv.DeviceType_Set(hs) = New HomeSeerAPI.DeviceTypeInfo
            hs.SaveEventsDevices()
            dv.Status_Support(hs) = True
            dv.Can_Dim(hs) = False
            dv.MISC_Set(hs, HomeSeerAPI.Enums.dvMISC.SHOW_VALUES)
            dv.MISC_Clear(hs, HomeSeerAPI.Enums.dvMISC.STATUS_ONLY)
            dv.Relationship(hs) = HomeSeerAPI.Enums.eRelationship.Child
            dv.AssociatedDevice_Add(hs, masterdevice)
            dv = Nothing

            hs.WriteLog("HDMI matrix", "Test Device for output " & output & " created")
        Catch ex As Exception
            hs.WriteLog("HDMI matrix", "Error creating devices: " & ex.Message)
            Return 0
        End Try

        Dim SVpair_off As New HomeSeerAPI.VSPair(HomeSeerAPI.ePairStatusControl.Status)
        SVpair_off.PairType = HomeSeerAPI.VSVGPairType.SingleValue
        SVpair_off.Value = 0
        SVpair_off.Status = "None"
        hs.DeviceVSP_AddPair(devref, SVpair_off)

        Dim VGpair_off As New HomeSeerAPI.VGPair
        VGpair_off.PairType = HomeSeerAPI.VSVGPairType.SingleValue
        VGpair_off.Set_Value = 0
        VGpair_off.Graphic = "images/Moskus/icon_hdmi_X.png"
        hs.DeviceVGP_AddPair(devref, VGpair_off)


        'Adding buttons, values and graphic
        For i As Integer = 1 To 4
            hs.DeviceScriptButton_AddButton(devref, output & "-" & i, i, Scriptname, "ButtonPress", output & "-" & i, 1, i, 1)

            Dim SVpair As New HomeSeerAPI.VSPair(HomeSeerAPI.ePairStatusControl.Status)
            SVpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue
            SVpair.Value = i
            SVpair.Status = "Input " & i
            hs.DeviceVSP_AddPair(devref, SVpair)

            Dim VGpair As New HomeSeerAPI.VGPair
            VGpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue
            VGpair.Set_Value = i
            VGpair.Graphic = "images/Moskus/icon_hdmi_" & i & ".png"
            hs.DeviceVGP_AddPair(devref, VGpair)
        Next

        Return devref
    End Function

    Public Sub ButtonPress(Input As Object)
        Dim devref As Integer = Input(0)
        Dim ButtonName As String = Input(1)
        Dim output As String = String.Empty 'Gets filled by GetURLIE

        Dim device As Integer = 0

        Dim master As Integer = hs.GetDeviceParentRefByRef(devref)
        If master = 0 Then master = devref

        Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(master)
        For Each devid As Integer In dv.AssociatedDevices(hs)
            Dim dev As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devid)
            Select Case dev.Device_Type_String(hs)
                Case Is = "HDMI root"
                    device = 0
                Case Is = "HDMI out 1"
                    device = 1
                Case Is = "HDMI out 2"
                    device = 2
                Case Is = "HDMI out 3"
                    device = 3
                Case Is = "HDMI out 4"

            End Select
        Next

        Dim command As String = "Refresh"

        If device > 0 Then
            Dim value As Integer = hdmi_outputs.ToList.IndexOf(ButtonName)
            command = device & "-" & value
        End If


        Select Case command
            Case Is = "Refresh"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=refrash", True) '"refrash" is actually not a typo on my part...

            Case Is = "1-1"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a09", True)
            Case Is = "1-2"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a1D", True)
            Case Is = "1-3"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a1F", True)
            Case Is = "1-4"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a0D", True)

            Case Is = "2-1"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a17", True)
            Case Is = "2-2"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a12", True)
            Case Is = "2-3"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a59", True)
            Case Is = "2-4"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a08", True)

            Case Is = "3-1"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a5E", True)
            Case Is = "3-2"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a06", True)
            Case Is = "3-3"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a05", True)
            Case Is = "3-4"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a03", True)

            Case Is = "4-1"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a18", True)
            Case Is = "4-2"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a44", True)
            Case Is = "4-3"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a0F", True)
            Case Is = "4-4"
                output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a51", True)
        End Select

        InterpretOutput(devref, output)
    End Sub

    Public Sub InterpretOutput(ByVal devref As Integer, ByVal output As String)
        'output: Output1=1Output2=1Output3=1Output4=1
        Dim data(3) As Integer
        data(0) = CInt(output(8).ToString)
        data(1) = CInt(output(17).ToString)
        data(2) = CInt(output(26).ToString)
        data(3) = CInt(output(35).ToString)

        Dim master As Integer = hs.GetDeviceParentRefByRef(devref)
        If master = 0 Then master = devref

        Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(master)
        For Each devid As Integer In dv.AssociatedDevices(hs)
            Dim dev As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devid)
            Select Case dev.Device_Type_String(hs)
                Case Is = "HDMI out 1"
                    If hs.DeviceValue(devid) <> data(0) Then
                        hs.SetDeviceValueByRef(devid, data(0), True)
                    Else
                        hs.SetDeviceValueByRef(devid, data(0), False)
                    End If
                Case Is = "HDMI out 2"
                    If hs.DeviceValue(devid) <> data(1) Then
                        hs.SetDeviceValueByRef(devid, data(1), True)
                    Else
                        hs.SetDeviceValueByRef(devid, data(1), False)
                    End If
                Case Is = "HDMI out 3"
                    If hs.DeviceValue(devid) <> data(2) Then
                        hs.SetDeviceValueByRef(devid, data(2), True)
                    Else
                        hs.SetDeviceValueByRef(devid, data(2), False)
                    End If
                Case Is = "HDMI out 4"
                    If hs.DeviceValue(devid) <> data(3) Then
                        hs.SetDeviceValueByRef(devid, data(3), True)
                    Else
                        hs.SetDeviceValueByRef(devid, data(3), False)
                    End If
            End Select
        Next

    End Sub

 

Gir:

nEibCgm.png

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Jeg har laget en ett matrise oppsett med VIrtuelle Devicer, men mine innganger er ikke gruppert sånn som dine. Jeg ser du gjør dette via ett script, betyr det at devicene blir opprettet hver gang du kjører dette scriptet. Når kjører du det ? Er det mulig å gruppere devicer i fra Websiden, eller må dette gjøres vha script ?

Link to comment
Share on other sites

Som du ser i scriptet har jeg en "Setup()" rutine.

Her er "dv" root-devicen, og siste delen lager children og assosierer dem med root:

'Creating child devices
dv.Relationship(hs) = HomeSeerAPI.Enums.eRelationship.Parent_Root
For i As Integer = 1 To 4
    Dim childref As Integer = CreateOutputDevice(i, devref)
    If childref > 0 Then dv.AssociatedDevice_Add(hs, childref)
Next

 

Link to comment
Share on other sites

  • 10 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.