Hi Guys.
I have a (virtual) device setup for my Sonance DAB1 audi distribution amp.
It's controlled via RS232 and sends responses back. ie. if you set the volume up to level 23 in zone 1, it responds "+V123" on the serial port. I can control the Sonance via an remote or keypads as well as over the serial.
I have written a script to update the virtual device status in HS when I get a status via serial port.
So. Let's keep it simple. Power. I have a virtual device setup for Power. If I turn off the DAB1, the DAB1 sends "+Z0" via serial and my script sees this and updates the status of the Power virtual device in Homeseer.
Now, How do i make the control buttons for the device run a script? I do not want to set an action to trigger every time the status changes/updates or it'll fire when I change the power with my remote. I just want to click on button and run an action. I see that this is doable with a plugin
But not via the GUI?
Oh, and for completeness, this is the script that triggers on inbound serial status updates.
I have a (virtual) device setup for my Sonance DAB1 audi distribution amp.
It's controlled via RS232 and sends responses back. ie. if you set the volume up to level 23 in zone 1, it responds "+V123" on the serial port. I can control the Sonance via an remote or keypads as well as over the serial.
I have written a script to update the virtual device status in HS when I get a status via serial port.
So. Let's keep it simple. Power. I have a virtual device setup for Power. If I turn off the DAB1, the DAB1 sends "+Z0" via serial and my script sees this and updates the status of the Power virtual device in Homeseer.
Now, How do i make the control buttons for the device run a script? I do not want to set an action to trigger every time the status changes/updates or it'll fire when I change the power with my remote. I just want to click on button and run an action. I see that this is doable with a plugin
Function DeviceScriptButton_AddButton(ByVal dvRef As Integer, ByVal Label As String, ByVal Value As Double, _
ByVal ScriptFile As String, ByVal ScriptFunc As String, ByVal ScriptParm As String, _
ByVal Row As UInt16, ByVal Column As UInt16, ByVal ColumnSpan As UInt16) As Boolean
Purpose
Use DeviceScriptButton_Add to add a button to the device to be shown in the UI, and that will launch a script when the button is activated or controlled.
ByVal ScriptFile As String, ByVal ScriptFunc As String, ByVal ScriptParm As String, _
ByVal Row As UInt16, ByVal Column As UInt16, ByVal ColumnSpan As UInt16) As Boolean
Purpose
Use DeviceScriptButton_Add to add a button to the device to be shown in the UI, and that will launch a script when the button is activated or controlled.
Oh, and for completeness, this is the script that triggers on inbound serial status updates.
Code:
Sub Main(Param As Object) Dim Command As String = Param.Substring(1, 1) Dim Param1 As String = Param.Substring(2, 1) Dim Param2 As String ' Param is the response status from the DAB1 ' It has a different format depending upon the second character in the response. ' eg. zone power is +Zxy (Z = Zone Power, x= zone 1-6, y=1 if On, 0 if Off) ' volume is +Vxy (V = Volume, x= zone 1-6, y= Current Volume 0-60) ' Command is the Command part of the string (Z = zone command, V = Volume command etc) ' Param1 is always there but has a different meaning depending upon the command ' Param2 is only used for some commands is Volume status, which return say a zone value and volume. Select Case Command Case "Z" ' Zone On/Off if Param1.Length = 1 Then hs.SetDeviceValueByName("DAB1 Power", Convert.ToInt32(Param1)) hs.writelog("DAB1","Zone Power " & Param1 ) Else Param2 = Param.Substring(3, Param.Length - 3) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Power", Convert.ToInt32(Param2)) hs.writelog("DAB1","Zone Power Zone:" & Param1 & " " & "Status:" & Param2) End If Case "S" 'Source Param2 = Param.Substring(3, 1) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Source", Convert.ToInt32(Param2)) hs.writelog("DAB1","Source Zone:" & Param1 & " " & "Source:" & Param2) Case "R" ' Tuner Memory. Note this can be 0 to 12 Param1 = Param.Substring(2, Param.Length - 2) hs.SetDeviceValueByName("DAB1 Station", Convert.ToInt32(Param1)) hs.writelog("DAB1","Station " & Param1 ) Case "N" ' Tuner Band hs.SetDeviceValueByName("DAB1 Band", Convert.ToInt32(Param1)) hs.writelog("DAB1","Tuner Band "&Param1 ) Case "V" 'Volume Param2 = Param.Substring(3, Param.Length - 3) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Volume", Convert.ToInt32(Param2)) hs.writelog("DAB1","Volume Zone:" & Param1 & " " & "Volume:" & Param2) Case "G" 'Page Volume Param2 = Param.Substring(3, Param.Length - 3) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Page Volume", Convert.ToInt32(Param2)) hs.writelog("DAB1","Page Volume Zone:" & Param1 & " " & "Page Volume:" & Param2) Case "M" 'Mute Param2 = Param.Substring(3, 1) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Mute", Convert.ToInt32(Param2)) hs.writelog("DAB1","Mute Zone:" & Param1 & " " & "Mute:" & Param2) Case "B" 'Balance Note: Param 2 can be -10 to +10 Param2 = Param.Substring(3, Param.Length - 3) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Balance", Convert.ToInt32(Param2)) hs.writelog("DAB1","Balance Zone:" & Param1 & " " & "Balance:" & Param2) Case "L" 'Bass Param2 = Param.Substring(3, Param.Length - 3) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Bass", Convert.ToInt32(Param2)) hs.writelog("DAB1","Bass Zone:" & Param1 & " " & "Bass:" & Param2) Case "H" 'Treble Param2 = Param.Substring(3, Param.Length - 3) hs.SetDeviceValueByName("DAB1 Zone" & Param1 & " Treble", Convert.ToInt32(Param2)) hs.writelog("DAB1","Treble Zone:" & Param1 & " " & "Treble:" & Param2) Case Else hs.WriteLog("DAB1", "I don't know what to do with: " & Command) End Select End Sub
Comment