Announcement

Collapse
No announcement yet.

Simple Control / Roomie integrate with HS3

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

    Simple Control / Roomie integrate with HS3

    Anyone using Simple Control - Roomie Remote?

    I have been using it for a couple of years. Although HSTouch is working great for me, Simple Control has more power and ease to create AV related macros and is a fantastic remote.

    I would love it if you could easily switch back and forth from HSTouch to Simple Control.
    Simple control does allow this with other IOS apps using URL Schemes like Squeezepad.

    I would also love to launch Simple Control macros from HS. I think that this might be possible using the Simple Control Simple Hub. The user guide is Here.

    The Simple Sync JSON HTTP Activity & Device Command Interface is Here.

    If it could be done, it would make a great plugin.
    DSteiNeuro

    HS3Pro

    MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

    Enabled Plug-Ins
    BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

    #2
    Need help with JSON

    I wanted to see if I could get this to work so loaded the Simple Hub Android on a PiPo X8.
    It works! I can send commands to Simple Control and get responses.

    I figured out how to send an HTTP command to get the Simple Control Device information including a Device UUID, but don't know how to format a JSON command to get it to send a device command

    Example:
    $ curl -X POST ‘http://localhost:47147/api/v1/sendcommands' -X POST -d ‘{ "delay"
    : "1000", "commands" : [ { "type" : "command", "params" : { "command" : "VOLUME
    UP", "device" : “2DCCA135-4264-41B1-842B-8118337C71DE”, “repeat” : “constant” } }
    ] }’

    From the HTTP Activity & Device Command Interface-

    Code:
    Send Device Command
    Send a command to a specific device, with an optional repeat parameter. The response will include a
    session identifier that can be used to refresh a repeating command. If a command repeat option is
    specified, the refresh API will need to be called frequently to continue the repeating command. If the
    refresh API is not called, the repeating command will time out after a short duration.
    NOTE: Despite specifying device commands in an array, the API currently
    is limited to accepting and handling a single command.
    Request: POST /api/v1/sendcommands
    {
    “delay” : <(optional) string: Delay in ms before sending commands>,
    “commands”: <(required) Array of command objects. Details below>
    }
    Command object:
    {
    “type” : <(required) string: “command” | “activity” | “url”>,
    “delay” : <(optional) string: Delay in milliseconds. Usage varies by type>
    “params” : <(required) object: Fields vary by type. Details below>
    }
    “command” params object:
    {
    “command” : <(required) string: Command name in caps>,
    “device” : <(required) string: Device UUID of the target device>,
    “condition” : <(optional) object: Conditions to meet before sending command>
    {
    “activity_uuid” : <(required) string: Toggle activity UUID>,
    “toggle_state” : <(required) string: “on” | “off”>
    },
    “power_delay” : <(optional) string: Power delay in milliseconds>,
    “delay_all” : <(optional) string: “yes” | “no” Delay devices globally>,
    “repeat” : <(optional) string: “constant” | “progressive” Repeat type>,
    “params” : <(optional) array of strings: Up to 3 command parameters>
    }
    
    “activity” params object:
    {
    “activity_uuid” : <(required) string: Activity UUID>,
    “toggle_state” : <(optional) string: “on” | “off” Toggle state to set>,
    }
    “url” params object:
    {
    “url” : <(required) string: URL to load. e.g. http://www.google.com/>
    }
    NOTE: The specified URL must include the scheme (e.g. “http://“)
    Response data: Session identifier. The session can be used to refresh or end any repeating
    commands. NOTE: Sessions are very short-lived to prevent repeating commands
    from continuing unmonitored.
    {
    "session" : "96F4C281-B34D-47D4-9097-EA80874FAFE4"
    }
    Example:
    $ curl -X POST ‘http://localhost:47147/api/v1/sendcommands' -X POST -d ‘{ "delay"
    : "1000", "commands" : [ { "type" : "command", "params" : { "command" : "VOLUME
    UP", "device" : “2DCCA135-4264-41B1-842B-8118337C71DE”, “repeat” : “constant” } }
    ] }’
    {
    "status" : "success",
    "data" : {
    "session" : "96F4C281-B34D-47D4-9097-EA80874FAFE4"
    },
    "code" : 200
    }
    Any help appreciated. I would love to get this to work. The combination of Simple Control (Roomie Remote) with HS3 could be very powerful
    DSteiNeuro

    HS3Pro

    MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

    Enabled Plug-Ins
    BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

    Comment


      #3
      I use the following script to send json commands to WDTV Live boxes. Hopefully the code will help with what you need to do.

      Cheers
      Al

      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 cmdType = ParmArray(0)						'remote or service
      	Dim cmd = ParmArray(1)							'message or string ID
      	Dim player = ParmArray(2)						'player dns name or ip address
      	Dim json As String = "{""" & cmdType & """:""" & cmd & """}"
      	If Debug Then hs.writelog(logName, "Command: " & json)
      
      	Try
      		Dim httpWebRequest = DirectCast(WebRequest.Create("http://" & player & "/cgi-bin/toServerValue.cgi"), HttpWebRequest)
      		httpWebRequest.ContentType = "application/json"
      		httpWebRequest.Method = "POST"
      
      		Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream().ToString)
      			streamWriter.Write(json)
      		End Using
      
      		Dim httpResponse = DirectCast(HttpWebRequest.GetResponse(), HttpWebResponse)
      		Using streamReader = New StreamReader(httpResponse.GetResponseStream().ToString)
      			Dim responseText = StreamReader.ReadToEnd()
      			If Debug Then hs.WriteLog(logName, "Response: " & responseText)
      		End Using
      
      	Catch ex As Exception : hs.writelog(logName, "Error:  " & ex.Message.ToString)
      	End Try
      End Sub
      HS 4.2.8.0: 2134 Devices 1252 Events
      Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

      Comment


        #4
        Thanks Al, that does give me a start. I next to read up on the command set and JSON payloads
        DSteiNeuro

        HS3Pro

        MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

        Enabled Plug-Ins
        BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

        Comment


          #5
          Originally posted by sparkman View Post
          I use the following script to send json commands to WDTV Live boxes. Hopefully the code will help with what you need to do.

          Cheers
          Al

          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 cmdType = ParmArray(0)						'remote or service
          	Dim cmd = ParmArray(1)							'message or string ID
          	Dim player = ParmArray(2)						'player dns name or ip address
          	Dim json As String = "{""" & cmdType & """:""" & cmd & """}"
          	If Debug Then hs.writelog(logName, "Command: " & json)
          
          	Try
          		Dim httpWebRequest = DirectCast(WebRequest.Create("http://" & player & "/cgi-bin/toServerValue.cgi"), HttpWebRequest)
          		httpWebRequest.ContentType = "application/json"
          		httpWebRequest.Method = "POST"
          
          		Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream().ToString)
          			streamWriter.Write(json)
          		End Using
          
          		Dim httpResponse = DirectCast(HttpWebRequest.GetResponse(), HttpWebResponse)
          		Using streamReader = New StreamReader(httpResponse.GetResponseStream().ToString)
          			Dim responseText = StreamReader.ReadToEnd()
          			If Debug Then hs.WriteLog(logName, "Response: " & responseText)
          		End Using
          
          	Catch ex As Exception : hs.writelog(logName, "Error:  " & ex.Message.ToString)
          	End Try
          End Sub

          OK, this might work. I don't know if I need to send the Json as a cURL command or if I could just parse it out?

          I am able to connect to the server and tried parsing the Json several ways:

          Code:
          "activity_uuid : B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" 
          
          or
          
          '{ "activity_uuid" : "B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }'
          but get

          Code:
          Error: The remote server returned an error: (400) Bad Request
          The payload that I am trying to recreate is:
          Code:
          
          Example:
          $ curl -X POST 'http://localhost:47147/api/v1/runactivity' -d
          ‘{ "activity_uuid" : "B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }'
          {
          "status" : "success",
          "data" : {
          },
          "code" : 200
          }
          DSteiNeuro

          HS3Pro

          MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

          Enabled Plug-Ins
          BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

          Comment


            #6
            It likely should be sent it in this type of format:

            Code:
            { "activity_uuid" : "B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }
            You need the curly brackets and the quotation marks inside, but not the apostrophes on the outside. Just set the json variable in my example to that, but take care that you get the quotation marks correct. It'll write the json string to the log, so you can check it there to make sure it's formatted correctly.

            I'm assuming that this part is what the Roomie Remote returns:

            Code:
            {
            "status" : "success",
            "data" : {
            },
            "code" : 200
            }
            Cheers
            Al
            HS 4.2.8.0: 2134 Devices 1252 Events
            Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

            Comment


              #7
              Thanks, but no luck

              May-22 9:58:35 AM WDTV Live Error: The remote server returned an error: (400) Bad Request.

              May-22 9:58:35 AM Json { "activity_uuid : B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }

              I will keep playing around
              DSteiNeuro

              HS3Pro

              MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

              Enabled Plug-Ins
              BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

              Comment


                #8
                Missed the inner quotes but still no luck:

                May-22 10:05:05 AM WDTV Live Error: The remote server returned an error: (400) Bad Request.

                May-22 10:05:05 AM Json { "activity_uuid" : "B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }
                DSteiNeuro

                HS3Pro

                MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

                Enabled Plug-Ins
                BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

                Comment


                  #9
                  Checking the curl command parameters, it looks like -d tells is to send it as URL encoded, so try changing

                  Code:
                  httpWebRequest.ContentType = "application/json"
                  to

                  Code:
                  httpWebRequest.ContentType = "application/x-www-form-urlencoded"
                  You may have to URL Encode the json string as well.

                  Cheers
                  Al
                  HS 4.2.8.0: 2134 Devices 1252 Events
                  Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                  Comment


                    #10
                    Looks like I have everything correct.
                    I tried with and without the -d

                    May-22 10:13:14 AM WDTV Live Error: The remote server returned an error: (404) Not Found.

                    May-22 10:13:14 AM Json { "activity_uuid" : "B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }

                    May-22 10:13:14 AM httpWebrequest http://192.168.1.141:47147/api/v1/runactivity -d

                    ________________


                    May-22 10:13:14 AM WDTV Live Error: The remote server returned an error: (404) Not Found.

                    May-22 10:13:14 AM Json { "activity_uuid" : "B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }

                    May-22 10:13:14 AM httpWebrequest http://192.168.1.141:47147/api/v1/runactivity
                    DSteiNeuro

                    HS3Pro

                    MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

                    Enabled Plug-Ins
                    BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

                    Comment


                      #11
                      Don't append the -d. It's just when using the curl command. Since you are using a script, rather than curl, you need to change as per my previous post.
                      Last edited by sparkman; May 22, 2016, 12:21 PM.
                      HS 4.2.8.0: 2134 Devices 1252 Events
                      Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                      Comment


                        #12
                        Here's an example on how to URL Encode a string. You need to add the Imports System.Web

                        Code:
                        Imports System.Web
                        
                        Sub Main(ByVal Parms As Object)
                        	Dim logName As String = "URL Encode"				'set log name for HS log
                        	Dim debug As Boolean = True
                        	Dim MyURL As String
                        	MyURL = "http://www.123.com/articles.aspx?title=" & HttpUtility.UrlEncode("ASP.NET://Examples")
                        	hs.writelog(logName, MyURL )
                        End Sub
                        HS 4.2.8.0: 2134 Devices 1252 Events
                        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                        Comment


                          #13
                          Still no luck.
                          Will try more later.

                          Thanks for the support, always learning
                          DSteiNeuro

                          HS3Pro

                          MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

                          Enabled Plug-Ins
                          BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

                          Comment


                            #14
                            No problem. Always a bit of trial and error with these things.

                            Here's a complete script with all the changes I was talking about. Can you run it and let me know what error you get?

                            Code:
                            Imports System.IO
                            Imports System.Net
                            Imports System.Web
                            
                            Sub Main(ByVal Parms As Object)
                            	Dim logName As String = "Roomie"				'set log name for HS log
                            	Dim debug As Boolean = True
                             
                            	Dim json As String = "{ ""activity_uuid"" : ""B02BEC70-3B0F-4F64-8084-AAF01ABF6F03"" }"
                            	If Debug Then hs.writelog(logName, "Command: " & json)
                            
                            	Try
                            		Dim httpWebRequest = DirectCast(WebRequest.Create("http://localhost:47147/api/v1/runactivity"), HttpWebRequest)
                            		httpWebRequest.ContentType = "application/x-www-form-urlencoded"
                            		httpWebRequest.Method = "POST"
                            
                            		Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream().ToString)
                            			streamWriter.Write(HttpUtility.UrlEncode(json))
                            		End Using
                            
                            		Dim httpResponse = DirectCast(HttpWebRequest.GetResponse(), HttpWebResponse)
                            		Using streamReader = New StreamReader(httpResponse.GetResponseStream().ToString)
                            			Dim responseText = StreamReader.ReadToEnd()
                            			If Debug Then hs.WriteLog(logName, "Response: " & responseText)
                            		End Using
                            
                            	Catch ex As Exception
                            		hs.writelog(logName, "Error:  " & ex.Message.ToString)
                            	End Try
                            End Sub
                            HS 4.2.8.0: 2134 Devices 1252 Events
                            Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                            Comment


                              #15
                              Thanks

                              I ran as is and got error


                              May-22 1:25:02 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\RoomieAPI.vb: 'HttpUtility' is not declared. It may be inaccessible due to its protection level.

                              May-22 1:25:02 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\RoomieAPI.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.


                              so added

                              Code:
                              Dim HttpUtility
                              Now the error is:


                              May-22 1:29:34 PM Roomie Error: Object variable or With block variable not set.

                              May-22 1:29:34 PM Roomie Command: { "activity_uuid" : "B02BEC70-3B0F-4F64-8084-AAF01ABF6F03" }

                              May-22 1:29:34 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/RoomieAPI.vb("Main")


                              Close????
                              DSteiNeuro

                              HS3Pro

                              MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

                              Enabled Plug-Ins
                              BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

                              Comment

                              Working...
                              X