Announcement

Collapse
No announcement yet.

WDTV Live Control

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

  • WDTV Live Control

    Hi all,

    I have a few WDTV Live (generation 3) media players and created one device, one event and one script (with apologies to George Thorogood ) to allow for control of them using their web interface. I'm posting it here in case someone else is interested. There are other ways to control them (ir, upnp, etc.) as well.

    One Device:
    Click image for larger version

Name:	WDTVLive1.PNG
Views:	1
Size:	35.1 KB
ID:	1209147
    Click image for larger version

Name:	WDTVLive2.jpg
Views:	1
Size:	137.3 KB
ID:	1209148
    Click image for larger version

Name:	WDTVLive3.PNG
Views:	1
Size:	118.6 KB
ID:	1209149

    One Event:
    Click image for larger version

Name:	WDTVLive4.PNG
Views:	1
Size:	25.7 KB
ID:	1209150

    And One Script:
    Code:
    Imports System.IO
    Imports System.Net
    
    Sub Main(ByVal Parms As Object)
    	Dim logName As String = "WDTV Live"			'set log name for HS log
    	Dim debug As Boolean = True
     
    	Dim ParmArray() as String
    	ParmArray = Parms.tostring.split(",")			'split parameter into an array
    	Dim playerDev As Integer = CInt(ParmArray(0))	'device reference ID for the player's device
    	Dim player = ParmArray(1)					'player dns name or ip address
    	Dim cmd, cmdType As String
    
    	Select Case hs.deviceValueEx(playerDev)
    		Case 33 To 127
    			cmdType = "remote"
    			cmd = Chr(CInt(hs.deviceValueEx(playerDev)))
    		Case 200 To 300
    			cmdType = "service"
    			cmd = CStr(hs.deviceValueEx(playerDev) - 200)
    	End Select
    
    	Dim json As String = "{""" & cmdType & """:""" & cmd & """}"
    	If Debug Then hs.writelog(logName, "Command: " & json)
    	Dim strURL As String = "http://" & player & "/cgi-bin/toServerValue.cgi"
    	Dim myWebReq As HttpWebRequest
    	Dim myWebResp As HttpWebResponse
    	Dim encoding As New System.Text.UTF8Encoding
    	Dim sr As StreamReader
    	
    	Try
    		Dim data As Byte() = encoding.GetBytes(json)
    		myWebReq = DirectCast(WebRequest.Create(strURL), HttpWebRequest)
    		myWebReq.ContentType = "application/json; charset=utf-8"
    		myWebReq.ContentLength = data.Length
    		myWebReq.Method = "POST"
    		Dim myStream As Stream = myWebReq.GetRequestStream()
            
    		If data.Length > 0 Then
    			myStream.Write(data, 0, data.Length)
    			myStream.Close()
    		End If
    		
    		myWebResp = DirectCast(myWebReq.GetResponse(), HttpWebResponse)
    		sr = New StreamReader(myWebResp.GetResponseStream())
    		Dim responseText As String = sr.ReadToEnd()
    		If Debug Then hs.WriteLog(logName, "Response: " & responseText)
    
    	Catch ex As Exception : hs.writelog(logName, "Error:  " & ex.Message.ToString)
    	End Try
    End Sub
    save as wdtvlive2.vb

    Cheers
    Al
    Last edited by sparkman; March 12th, 2016, 03:55 PM.
    HS 3.0.0.548: 1970 Devices 1149 Events
    Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

  • #2
    Very Nice Al! You just keep coming out with new and smarter ways to do stuff with HS. Thank for sharing your genius!
    Tom
    baby steps...starting again with HS3
    HS3Pro: Z-NET & 80 Z wave Devices,
    HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
    Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
    In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
    System: XP on Fanless Mini-ITX w/ SSD

    Comment


    • #3
      Originally posted by TomTom View Post
      Very Nice Al! You just keep coming out with new and smarter ways to do stuff with HS. Thank for sharing your genius!
      Thanks for the kind words Tom! I wouldn't call it genius however, just good at plagiarizing other stuff I find on the web .

      Cheers
      Al
      HS 3.0.0.548: 1970 Devices 1149 Events
      Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

      Comment

      Working...
      X