Here's my script to control my sharp aquos tv in the bedroom:
Code: Select all
Sub Main(parm)
'add spaces if neccesairy
Do Until len(parm) = 8
parm = parm & " "
Loop
Dim retVal
'hs.WriteLog "SharpTV", "Execute: [" + parm + "]"
hs.SendToComPort 14, parm + vbCr
hs.WaitSecs(1)
retVal = hs.GetComPortData(14)
'hs.WriteLog "SharpTV", "Response: [" + retVal + "]"
End Sub
Sub GetStatus()
' get the power state and update device V7
retVal = ""
hs.SendToComPort 14, "POWR? " + vbCr
hs.WaitSecs(1)
retVal = Trim(hs.GetComPortData(14))
If Instr(retVal, "1") > 0 Then
hs.SetDeviceStatus "V40", 2
Else
hs.SetDeviceStatus "V40", 3
End If
' update other devices, if powerstate is on, otherwise set all to off
If hs.IsOn("V40") Then
' get the audio state and update device V8
retVal = ""
hs.SendToComPort 14, "MUTE? " + vbCr
hs.WaitSecs(1)
retVal = Trim(hs.GetComPortData(14))
'hs.WriteLog "SharpTV", retVal
If Instr(retVal, "1") > 0 Then
hs.SetDeviceStatus "V41", 3
Else
hs.SetDeviceStatus "V41", 2
End If
'get the source input and update device V9, V10,V11
'retVal = ""
'hs.SendToComPort 14, "IAVD? " + vbCr
'hs.WaitSecs(1)
'retVal = Trim(hs.GetComPortData(14))
'If Instr(retval, "1") > 0 Then
' hs.SetDeviceStatus "V9", 2
'Else
' hs.SetDeviceStatus "V9", 3
'End If
'If Instr(retval, "5") > 0 Then
' hs.SetDeviceStatus "V10", 2
'Else
' hs.SetDeviceStatus "V10", 3
'End If
'If Instr(retval, "8") > 0 Then
' hs.SetDeviceStatus "V11", 2
'Else
' hs.SetDeviceStatus "V11", 3
'End If
'get volume level
retVal = ""
hs.SendToComPort 14, "VOLM? " + vbCr
hs.WaitSecs(1)
retVal = Trim(hs.GetComPortData(14))
'hs.WriteLog "SharpTV", retVal
hs.SetDeviceValue "V42", Clng(retVal)
hs.SetDeviceString "V42", retVal
'hs.SetDeviceString "V12", ""
'get sleep timer
hs.SendToComPort 14, "OFTM? " + vbCr
hs.WaitSecs(1)
retVal = Trim(hs.GetComPortData(14))
'hs.WriteLog "SharpTV", "Sleeptimer: [" & retVal & "]"
hs.SetDeviceValue "V43", Clng(retVal)
If retVal = 0 Then
hs.SetDeviceString "V43", "Off"
Else
hs.SetDeviceString "V43", retVal & " min"
End If
'get the channel
hs.SendToComPort 14, "DCCH? " + vbCr
hs.WaitSecs(1)
retVal = Trim(hs.GetComPortData(14))
'hs.WriteLog "SharpTV", "Channel: [" & retVal & "]"
hs.SetDeviceValue "V44", Clng(retVal)
hs.SetDeviceString "V44", retVal
Else
' set all other devices to off
hs.SetDeviceStatus "V40", 3
hs.SetDeviceString "V43", "Off"
hs.SetDeviceValue "V43", 0
End If
'hs.CloseComPort 10
End Sub
Sub PowerToggle()
If hs.IsOn("V40") Then
hs.SendToComPort 14, "POWR0 " + vbCr
hs.SetDeviceStatus "V40", 3
Else
hs.SendToComPort 14, "POWR1 " + vbCr
hs.SetDeviceStatus "V40", 2
End If
End Sub
Sub SetVolume()
Volume = Cstr(hs.DeviceValue("V42"))
If len(Volume) = 1 Then
Volume = "0" + Volume + " "
Else
Volume = Volume + " "
End If
hs.SetDeviceString "V42", Volume
hs.SendToComPort 14, "VOLM" + Volume + vbCr
End Sub
And here's a screenshot of some tv events, I have 2 sharp aquos tv's in the house.

- TV_Events.jpg (233.38 KiB) Viewed 16283 times