Announcement

Collapse
No announcement yet.

Help with an Action from a Script

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

    Help with an Action from a Script

    Hello

    So I am making a script which is for tts, as opposed to the proper linkgroup method, which is due to response times and that I don't use linking.

    What I am trying to achieve: I would like to call an event action.

    The simple way is creating several events like the attached, then put the hs.TriggerEvent line in - but I don't want to do this, as I would like it all within this vb script.

    There is no device in the devices that allow me to pair, so I can't use CAPI ( at least I don't think I can).


    Is there a way I can put the green THEN SONOS ACTION into my script?


    Thank you
    Chris


    Code:
    Code:
    '----------------------------------
    ' SONOS Script by Chris Coles
    ' Note this does not UNLINK/LINK Groups, LINKGROUPS should be used for this
    '----------------------------------
    
    
    
    '---------------------------------------------------------------------------
    ' Public Variables
    '---------------------------------------------------------------------------
    
    
    
    '---------------------------------------------------------------------------
    ' Main Method
    '---------------------------------------------------------------------------
    Sub Main(parm As Object)
    End Sub
    
    
    
    '---------------------------------------------------------------------------
    ' Speak Method
    '---------------------------------------------------------------------------
    Public Sub speakSomething(ByVal Parms As Object)
    
    	Dim parmArray() As String = Parms.ToString.Split("|")
    	Dim setSpeakerName As String = parmArray(0)
    	Dim setVolume As Integer = parmArray(1)
    	Dim setTTS As String = parmArray(2)
    
    	Dim speakerNameID As Integer
    	Dim speakerVolumeID As Integer
    	Dim getOriginalVolume As Integer
    
    
    	Select Case setSpeakerName
    
    		Case "upstairs"
    					speakerNameID = -1
    					speakerVolumeID = -1
    		Case "bathroom"
    					speakerNameID = 11
    					speakerVolumeID = 77
    		Case "ensuite"
    					speakerNameID = 1369
    					speakerVolumeID = 1379
    		Case "masterbedroom"
    					speakerNameID = 8
    					speakerVolumeID = 22
    		Case "guestbedroom"
    					speakerNameID = -1
    					speakerVolumeID = -1
    		Case "office"
    					speakerNameID = -1
    					speakerVolumeID = -1
    		Case "livingroom"
    					speakerNameID = 10
    					speakerVolumeID = 59
    		Case "frontroom"
    					speakerNameID = 292
    					speakerVolumeID = 321
    		Case "downstairs"
    					speakerNameID = 293
    					speakerVolumeID = 339
    		Case "frontdoor"
    					speakerNameID = 12
    					speakerVolumeID = 95
    
    		Case "frontdoor"
    					speakerNameID = 12
    					speakerVolumeID = 95
    
    		Case "kitchen"
    					speakerNameID = -1
    					speakerVolumeID = -1
    		Case else
    					hs.WriteLogEx("SONOS TTS", "Destination Speaker Incorrect", "#ff0000")
    	End Select
    
    	If speakerNameID >-1 Then
    	
    	' Get Original Volume
    		getOriginalVolume = hs.DeviceValueEx(speakerVolumeID)
    		hs.WriteLog("SONOS TTS", "Speaker Number: " & speakerNameID & " has an original volume of: " & getOriginalVolume)
    
    	' Set Pause on Speaker
    		hs.CAPIControlHandler(hs.CAPIGetSingleControl(speakerNameID,True,"Pause",False,False))
    
    	' Set Speaker to New Volume
    		Dim cc as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(speakerNameID, True, "Volume (value)%", False, False)
    		cc.ControlValue = setVolume
    		Dim cr as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    
    
    
    	' Set Speaker to Line-In of Master Bedroom Connect Amp 
    	'	?????????????????????????????????????????????????????????????????????
    	'       ?????????????????????????????????????????????????????????????????????
    
    
    
    	' Set Resume on Speaker
    		hs.CAPIControlHandler(hs.CAPIGetSingleControl(speakerNameID,True,"Play",False,False))
    
    	' Speak TTS through 3.5mm Jack to Connect AMP LineIn Input
    		hs.Speak(setTTS, True, "EAGLE54:DEFAULT")
    
    	' Set Speaker to Original Volume
    		Dim cc as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(speakerNameID, True, "Volume (value)%", False, False)
    		cc.ControlValue = getOriginalVolume
    		Dim cr as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
    		
    	' Set speakerNameNumber to stop
    		hs.CAPIControlHandler(hs.CAPIGetSingleControl(speakerNameID,True,"Stop",False,False))
    
    	End If
    End Sub
    Attached Files
    Last edited by smokeycoles; April 2, 2017, 05:48 AM.

    #2
    Any takers on the above?

    Comment


      #3
      Originally posted by smokeycoles View Post
      Any takers on the above?
      I'm afraid unless Dirk has exposed any of the methods by script (I know he has some but no idea where/if these are documented) then you won't be able to do this. HS events in HS3 are complex objects and down to the plugin author how they wish to store the data and that's why they aren't exposed in scripting actions.

      Comment


        #4
        I understand, I don't want to upset him.
        At worse I can create 12 events (each player) from a single input.

        It will still be ten times less events than I currently use...
        and I will still get the speed increase.

        I have asked him in a post.

        Thank you for answering my question.

        Comment

        Working...
        X