Announcement

Collapse
No announcement yet.

Alexa Global Cache & Events

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

    Alexa Global Cache & Events

    I control my home audio system using the Global Cache plugin. I have evens set up in HS to turn on & off different sources and zones. I would like to control these with Alexa. I read something about setting up virtual devices to control events, but need more information. Could someone please assist?

    Also if someone has a better way to control the Audio system with HS and Alexa i am open to suggestions. Controlling the system with events is a little clunky doing things like raising and lowering the volume.

    #2
    Just set up virtual devices for your sources and zones. You can make them simple on/off devices. Then have your events set to recognize when the device is turned on or off and activate the appropriate GlobalCache device in the event. When you discover devices with Alexa, you should see the virtual devices listed. Then you can command Alexa to turn on the virtual device, which will trigger the GlobalCache device to turn on the source or select the zone.

    For example, I have a GCIR on my TV and created a virtual device called TV. I have events for TV ON and TV OFF. Alexa sees the device called TV, so I can say 'Turn on the TV', which triggers the event when the device status changes, and sends the GCIR command to turn on the TV.

    You can get much more inventive. I also have the XBMC plug-in, so in addition to a simple TV on/off, I made the virtual device dimmable with statuses for each channel that I want to be able to set. Then I have events for each of my favorite channels. So I can tell Alexa to set the TV to channel 10, and the event has the command for the XBMC plug-in to change to that channel.

    Comment


      #3
      This may or may not help, but its what I am doing to control my Global Cache unit (I just recently started since I received it for xmas, I am working to add a lot more).

      I don't use the plugin, I created a script to control things. Right now it just has the immediate things I wanted to have setup to be controlled by voice. I am using Jon's Alexa Helper scripts and created a few trigger words that run this script and parse out what is being said and take action based off that.

      I highly recommend looking at Jon's helper as you could do what you are wanting without having to create virtual devices or run events.

      For this, you see that I am only looking at either TV or Television being said to trigger the script, from there I look at what was said (like mute) and run that function.

      I am not sure how well you are at scripting, I am new to it and this wasn't too hard with Google's help. You don't need to script to do what you want to do though, the helper really was a life saver in making all this work.

      Code:
      ' import required modules
      Imports System.Net
      Imports System.Net.Sockets
      Imports System.Text
          Sub Main(ByVal parms as Object)
              Dim strCommand as string
      
              Dim Yammy_Mute = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,1517,341,85,21,3655" &vbCR
              
              Dim Yammy_UnMute = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,1517,341,85,21,3655" &vbCR
              
              Dim DTV_Pause = "sendir,1:3,1,38000,1,21,229,45,45,45,22,22,22,22,45,45,22,22,45,22,22,22,22,45,22,1143,114,45,45,45,22,22,22,22,45,45,22,22,45,22,22,22,22,45,22,1143" &vbCR
              
              Dim Yammy_Power_On = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,1517,341,85,21,3655" &vbCR
              
              Dim Yammy_Power_Off = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,1517,341,85,21,3655" &vbCR
              
              Dim DTV_Power_On = "sendir,1:3,1,39000,1,1,232,46,46,46,23,23,46,23,23,23,23,23,23,23,46,46,46,23,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,23,46,46,46,23,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,23,46,46,46,23,23,46" &vbCR
              
              Dim DTV_Power_Off = "sendir,1:3,1,39000,1,1,232,46,46,46,23,23,46,23,23,23,23,23,23,46,46,46,46,46,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,46,46,46,46,46,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,46,46,46,46,46,23,46" &vbCR
              
              Dim NEC_Power_On = "sendir,1:2,1,38109,1,1,343,171,22,21,21,21,22,21,22,63,22,63,22,21,22,21,21,21,22,63,22,63,22,63,22,21,22,21,21,64,21,64,21,64,21,21,22,21,22,21,22,63,22,21,21,21,22,21,22,21,21,64,21,64,21,64,21,21,22,63,22,63,22,63,22,63,22,1533,343,85,22,3661,342,85,22,3661,342,85,22,3800" &vbCR
              
              Dim NEC_Power_Off = "sendir,1:2,1,38000,1,69,342,171,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,1702,342,85,21,3663" &vbCR
              
              Dim DTV_Digit_9 = "sendir,1:3,1,38000,1,21,229,45,45,45,22,22,22,22,22,22,45,22,22,45,22,45,45,45,22,1143,114,45,45,45,22,22,22,22,22,22,45,22,22,45,22,45,45,45,22,1143" &vbCR
              
              Dim Yammy_DTV = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,1517,341,85,21,3655" &vbCR
              
              Dim Yammy_CD = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,1517,341,85,21,3655" &vbCR
              
              If Instr(parms,"pause") then 
              Call IRSend(DTV_Pause) 
              hs.setdevicestring(2393, "I have paused the TV", true)
              End If
              
              If Instr(parms,"mute") then 
              Call IRSend(Yammy_Mute)
              hs.setdevicestring(2393, "I have muted the TV", true)
              End If
              
              If Instr(parms,"unmute") then 
              Call IRSend(Yammy_UnMute) 
              hs.setdevicestring(2393, "I have unmuted the TV", true)
              End If
              
              If Instr(parms,"news") then 
              Call IRSend(Yammy_Power_On)
              hs.waitsecs(1)
              Call IRSend(Yammy_DTV)
              hs.waitsecs(1)
              Call IRSend(DTV_Power_On)
              hs.waitsecs(1)
              Call IRSend(NEC_Power_On)
              hs.waitsecs(1)
              Call IRSend(DTV_Digit_9)
              hs.setdevicestring(2393, "I have turned on the news", true)
              End If
              
              If InStr(parms,"television on") orElse InStr(parms,"tv on") then
              hs.setdevicestring(2393, "I have turned the TV On", true)
                  Dim TV_Watts as integer = hs.devicevalue(824)
                  If TV_Watts = 0 then 
                      hs.CAPIControlHandler(hs.CAPIGetSingleControl(824,true ,"on",false,true))
                      hs.waitsecs(2)
                  Else
                      'Do Nothing
                  End If
              Call IRSend(Yammy_Power_On)
              hs.waitsecs(1)
              Call IRSend(Yammy_DTV)
              hs.waitsecs(1)
              Call IRSend(DTV_Power_On)
              hs.waitsecs(1)
              Call IRSend(NEC_Power_On)
              End If
              
              If InStr(parms,"television off") orElse InStr(parms,"tv off") then
              hs.setdevicestring(2393, "I have turned the TV Off", true)
              Dim TV_Watts as integer = hs.devicevalueEX(822)
                  If TV_Watts > 50 then
                      Call IRSend(Yammy_Power_Off)
                      hs.waitsecs(1)
                      Call IRSend(DTV_Power_Off)
                      hs.waitsecs(1)
                      Call IRSend(NEC_Power_Off)
                  Else
                      'Do Nothing
                      hs.setdevicestring(2393, "TV is already Off", true)
                  End If
              End If
              
              If InStr(parms,"russound") then
                  Dim Stereo_Power as integer = hs.devicevalue(833)
                  Dim TV_Power as integer = hs.devicevalue(822)
                  Dim Russound_Zone as integer = hs.devicevalue(1336)
                      If Stereo_Power < 30 then 'Stereo Off
                          Call IRSend(Yammy_Power_On)
                          hs.waitsecs(1)
                          Call IRSend(Yammy_CD)
                      Else
                          Call IRSend(Yammy_CD)
                          hs.waitsecs(1)
                          Call IRSend(NEC_Power_Off)
                      End If
                      
                      If Russound_Zone = 0 then
                          Call IRSend(Yammy_Power_Off)
                      End If
              End If
      End Sub
      
      Sub IRSend(ByVal strCommand as object)
              Dim tcpClient As New System.Net.Sockets.TcpClient()
              tcpClient.Connect("10.0.254.19", "4998")
              Dim networkStream As NetworkStream = tcpClient.GetStream()
              Dim strResponse As String
              strResponse = "No response"
              If networkStream.CanWrite Then
                  Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strCommand)
                  networkStream.Write(sendBytes, 0, sendBytes.Length)
                  Dim bytes(tcpClient.ReceiveBufferSize) As Byte
                  networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                  Dim returndata As String = Encoding.ASCII.GetString(bytes)
                  strResponse = "Device responded: " & CStr(returndata)
              Else
                  If Not networkStream.CanWrite Then
                      strResponse = "Error: Cannot write data to the device"
                      tcpClient.Close()
                  End If
              End If
              hs.writelog("iTach Script", strResponse)
              tcpClient.Close()
      
      End Sub
      Attached Files

      Comment

      Working...
      X