No announcement yet.

Single Play/Pause control

  • Filter
  • Time
  • Show
Clear All
new posts

    Single Play/Pause control

    I have a few Chromecasts throughout the house and this plugin is awesome (very nice work Spud).

    I have a single button within HSTouch to Play/Pause a chromecast. Is there a simple way to do this without a script or setting up several events?
    I can write a quick script to detect the status (playing or not) and trigger the play/pause from within the script, but I was wondering if there was an easier way to do this. Optimally the Status device could just have a play/pause control that would be super easy to trigger.




      Hey Bob;
      Took me a while to understand what I needed to do (new to the HS world).
      Just changing the "Chromecast Status" device Value didn't work, so I had to dive a bit into the CAPI interface (nice learning curve).

      I got this working by using the CAPIControl script you can download from here:

      From a script, you just need to execute the following command:
      ControlDeviceNameAndLabelValue("Living Room Speaker Status,Play")

      What I did:
      HSTouch (on tablet):
      -Text/Label with the chromecast device name (Ex. Living Room Speaker) (the script below adds the " Status" string for the device)
      -Button that executes a script, with ScriptParameter1 as the text/label above

      My sample script:
      What it does: It looks at the chromecast "Status" device value to see if something is "playing" or "paused/idle" and just plays or pauses from there. Nothing fancy and it can use some refinement.

      Public Sub PlayPause(ByVal params As Object)
      	Dim playing as Double = 3
      	Dim paused as Double = 2
      		' confirm the parameters is correct
      		If IsArray(params) And params.Length >= 1 Then
      			Dim name as String
      			name = params(0).Trim
      			If name.Length >= 1 Then
      				Dim statusID as Double
      				statusID = hs.GetDeviceRefByName(name & " Status")
      				If hs.DeviceValueEx(statusID) = playing Then
      					hs.writelog("Script-Chromecast", " Currently Playing, so Pausing.")
      					ControlDeviceNameAndLabelValue(name & " Status,Pause")
      				Else If hs.DeviceValueEx(statusID) = paused Then
      					hs.writelog("Script-Chromecast", " Currently Paused, so Playing.")
      					ControlDeviceNameAndLabelValue(name & " Status,Play")
      					hs.writelog("Script-Chromecast", "'" & name & " Status' is currently '" & hs.DeviceString(statusID) & "', so... do nothing.")
      				End If
      				hs.writelog("Script-Chromecast", "Chromecast name is blank or just spaces.")
      			End If
      			hs.writelog("Script-Chromecast", "Not enough params: '" & params.Length & "'")
      		End If
      	Catch ex As Exception
      		hs.writelog("Script-Chromecast", "Error: " & ex.Message.ToString)
      	End Try
      End Sub
      Note: You'll also have to copy and paste the CAPIControl script contents into your script file, or reference it somehow, since it does all the heavy lifting in triggering the command buttons (play/pause) for the device.

      That should do it. You should now have a button that will play or pause a chromecast device (most of the time).

      This works for my Chromecast Audio, but I noticed that some casted apps onto a Chromecast (tv) don't update the "Status" to playing, so it just shows as "Idle". Not sure if this is a bug with the plugin, or the device casting. Happy to provide more debug info if needed to iron out any issues.
      Last edited by ssvyper; April 2, 2018, 08:44 PM. Reason: shorten the post; corrected some code


        Wow! Thanks a ton.
        I understand that you have made a button?
        What would the code look like without the reference to a button name?

        I am taking the play/pause command from the serial port.
        Last edited by Bobone; April 3, 2018, 05:27 PM.


          I'm not really getting the serial connection (I don't have something like that), or what that has to do with chromecast devices.
          My button is on HSTouch where I have a button on a tablet screen that, when pressed, it runs the script above. (button press = run script)

          How would the serial port/device know whether you want to play or pause a chromecast device? Wouldn't you need to detect whether something is playing or paused on chromecast first? Or if your serial device is just a way to trigger an action (play or pause), I imagine you may have to script that.
          Ex. port 232 receives a signal of some kind, play; if it receives another signal, pause.


            Thank you very much for pointing me to the right direction!!!

            I solved it with this simplified version:

            	Dim arrCC() As HomeSeerAPI.CAPI.CAPIControl = Nothing
            	arrCC = hs.CAPIGetControl("5") ' My CCA Status device
            	If InStr(1,data,"NEXT") > 1      Then
            	        hs.CAPIControlHandler(arrCC(3)) ' Set CCA to "Go to End"
            	End if
            	If InStr(1,data,"PREV") > 1      Then
            	        hs.CAPIControlHandler(arrCC(4)) ' Set CCA to "Go to Beginning"
            	        hs.SendToComPort(Port, "*S1DISPInfo,1700," & "0" & ",2" & Chr(13))
            	End if	
            	If InStr(1,data,"PLAYPAUSE") > 1 Then
            		Select Case hs.DeviceValue("5")
            			Case 3 ' CCA is Playing
            			        hs.CAPIControlHandler(arrCC(2)) ' Set CCA to "Pause"
            				hs.SendToComPort(Port, "*S1DISPInfo,1700," & Pos & ",3" & Chr(13)) ' Set Nuvo to "Pause"
            				hs.TriggerEvent("Timer Stop")
            			Case 2 ' CCA is Paused
            			        hs.CAPIControlHandler(arrCC(1)) ' Set CCA to "Play"
            				hs.SendToComPort(Port, "*S1DISPInfo,1700," & Pos & ",2" & Chr(13)) ' Set Nuvo to "Play"
            				hs.TriggerEvent("Timer Resume")
            		End Select
            	End if
            Still using the Timer Events as resume and stop do not exist in HomeSeer for estimating the position. Looking forward to Spud enabling "Duration"; should be easy. (Songs are on average 170 seconds)
            I know that the code is oversimplified and only for one CCA, but it got med started!

            Thx, I am really a newbie to Homeseer and evaluating it now.

            Last edited by Bobone; April 4, 2018, 05:12 AM.


              Glad to help.
              Can't wait for more info in this plugin so I can do something similar here.