Announcement

Collapse
No announcement yet.

XML HTTP RESTful API for HS3 - Discussion Thread

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

  • XML HTTP RESTful API for HS3 - Discussion Thread

    This thread is the support/discussion thread for the RESTful API I created for HomeSeer 3, located in this thread: http://board.homeseer.com/showthread...20#post1089120

    Please post any issues, questions, complaints, or compliments in this thread.

    Thanks Everyone!
    Last edited by RedTechie; November 24th, 2013, 07:54 PM.

  • #2
    Hi. I installed your plugin but i am having no luck getting any commands to go through. I am able to execute an event, but only when using a browser on the same computer that HS3 is on.

    I use this command:
    http://192.168.1.102:86/HomeSeer_RES...&param1=Garage Door Toggle

    Im guessing I need to put my user name/password in there. How do I do this so I can fire events from other computers on my lan, and most importantly to enable events from remote computers?

    Something like?:
    https://chris:xxx71536@192.168.1.102...&param1=Garage Door Toggle

    I feel I'm missing something obvious.

    Comment


    • #3
      AWESOME!

      Hi Red, this is an awesome script. I have been using it now for a week or two.

      One question/thought. This seems perfect for using as a more general web service into Homeseer. In particular to use for Occupancy for when you are at home. I found an iOS app called Geo Hopper that allows you to do geofencing (GPS) and iBeacons (bluetooth) that are both good on battery life. It allows the use of web hooks.

      I made an HS Device called Bill is At Home that is turned off an on by an Event (which nicely enough can be triggered by a URL using your API

      I setup geo hopper to do a POST to this URL:
      http://myserver/HomeSeerAPI.aspx?fun...am1=BillIsHome

      Unfortunately it doesn't seem to trigger the URL via Geohopper. Is this because your API works only on a GET using that URL and not a POST? Or is there something wrong with geo hopper?

      Also it would be great if we could extend your script to take in custom POSTs with data like the below. A reference example would be good, otherwise I will have to brush off my comp sci programming skills.

      PHP Code:
      http://geohopper.com/support

      What information gets sent to the web service? ∞

      When a web service is notifiedit sends a HTTP POST to the specified URL.  It posts a JSON payload:
      {
      "sender":"tperfitt@twocanoes.com","location":"Beacon in upstairs office","event":"LocationExit","time":"2013-09-11 02:03:33 +0000"}

      The fields are defined as follows:

      SenderThe email address of the sender.
      LocationThe name of the defined location that triggered the event.
      EventThe type of event.  Possible values are LocationEnterLocationExitLocationTest
      Time
      time the event occurred in RFC 3339 format

      Comment


      • #4
        Originally posted by bandook View Post
        Hi. I installed your plugin but i am having no luck getting any commands to go through. I am able to execute an event, but only when using a browser on the same computer that HS3 is on.

        I use this command:
        http://192.168.1.102:86/HomeSeer_RES...&param1=Garage Door Toggle

        Im guessing I need to put my user name/password in there. How do I do this so I can fire events from other computers on my lan, and most importantly to enable events from remote computers?

        Something like?:
        https://chris:xxx71536@192.168.1.102...&param1=Garage Door Toggle

        I feel I'm missing something obvious.

        Bandook, when you browse to the URL in your browser it will prompt you for your HomeSeer Username and Password via Basic Auth (Same as if you were browsing to it via a computer on your LAN). You could pass the credentials in the URL like you described, If you want to automate a URL call.

        Are you getting any sort of error or is it just timing out? Are you sure you are using the correct port and protocol (http/https) that Homeseer's web interface is running on?

        Are you able to access HomeSeer's Web UI at all for a LAN computer? You might need to enable a Admin + Local account in homeseer.

        Comment


        • #5
          Originally posted by robilium View Post
          Hi Red, this is an awesome script. I have been using it now for a week or two.

          One question/thought. This seems perfect for using as a more general web service into Homeseer. In particular to use for Occupancy for when you are at home. I found an iOS app called Geo Hopper that allows you to do geofencing (GPS) and iBeacons (bluetooth) that are both good on battery life. It allows the use of web hooks.

          I made an HS Device called Bill is At Home that is turned off an on by an Event (which nicely enough can be triggered by a URL using your API

          I setup geo hopper to do a POST to this URL:
          http://myserver/HomeSeerAPI.aspx?fun...am1=BillIsHome

          Unfortunately it doesn't seem to trigger the URL via Geohopper. Is this because your API works only on a GET using that URL and not a POST? Or is there something wrong with geo hopper?

          Also it would be great if we could extend your script to take in custom POSTs with data like the below. A reference example would be good, otherwise I will have to brush off my comp sci programming skills.

          PHP Code:
          http://geohopper.com/support

          What information gets sent to the web service? ∞

          When a web service is notifiedit sends a HTTP POST to the specified URL.  It posts a JSON payload:
          {
          "sender":"tperfitt@twocanoes.com","location":"Beacon in upstairs office","event":"LocationExit","time":"2013-09-11 02:03:33 +0000"}

          The fields are defined as follows:

          SenderThe email address of the sender.
          LocationThe name of the defined location that triggered the event.
          EventThe type of event.  Possible values are LocationEnterLocationExitLocationTest
          Time
          time the event occurred in RFC 3339 format
          Robilium, unfortunately the API currently only supports HTTP GET verbs. I will definitely look into adding the ability to pass the variables via POST calls as well.

          What you could do is write a simple PHP (or other language of your choice) script that will accept the post calls from Geohopper and then make the GET call into the Homeseer REST API. A sort of interface API, if you will.

          That would also be the best practice anyway. That way if say something changes with the REST API down the road, all you have to do on your end is change your interface API without having to change anything else in Geohopper or any other software package that would make calls into the REST API.

          Comment


          • #6
            Cool thanks.

            It seems like PHP isn't installed as part of the HomeSeer install
            So I assume I would have to go figure out C# like you are using or VB scripting...

            Comment


            • #7
              Originally posted by robilium View Post
              Cool thanks.

              It seems like PHP isn't installed as part of the HomeSeer install
              So I assume I would have to go figure out C# like you are using or VB scripting...
              Ah yes, if you wanted to use the HomeSeer's web server then yes you would nee to use C#.NET or VB.NET.

              But if you have a few spare cycles I would highly recommend XAMPP. I have it installed on the same server as HomeSeer (running on a different port of course). It is a packaged Apache Web Server, MySQL and PHP solution for Windows. http://www.apachefriends.org/en/xampp.html

              I use XAMPP for my Adobe Air application that uses PHP as a backend that communicates into this API via PHP HTTP CURL calls.

              Comment


              • #8
                Originally posted by RedTechie View Post
                Bandook, when you browse to the URL in your browser it will prompt you for your HomeSeer Username and Password via Basic Auth (Same as if you were browsing to it via a computer on your LAN). You could pass the credentials in the URL like you described, If you want to automate a URL call.

                Are you getting any sort of error or is it just timing out? Are you sure you are using the correct port and protocol (http/https) that Homeseer's web interface is running on?

                Are you able to access HomeSeer's Web UI at all for a LAN computer? You might need to enable a Admin + Local account in homeseer.
                Thank you! I was indeed missing the obvious. I just installed hs3 on my server and forgot to change firewall rules.

                Your program works great! Using it on my android phone through tasker for beautiful one click events. One thing I would like is to have a way to toggle devices on/off. Is there a toggle command for homeseer?

                Thanks again!

                Chris

                Comment


                • #9
                  Thank you! This is exactly what I've been looking for.
                  Haven't had a chance to do anything cool with it yet, but hopefully this weekend I'll have some time!

                  Comment


                  • #10
                    Originally posted by bandook View Post
                    Thank you! I was indeed missing the obvious. I just installed hs3 on my server and forgot to change firewall rules.

                    Your program works great! Using it on my android phone through tasker for beautiful one click events. One thing I would like is to have a way to toggle devices on/off. Is there a toggle command for homeseer?

                    Thanks again!

                    Chris
                    You can set a device to on / off using the "Set Device Status (By ID or Name)" cmd. You don't need events for that!

                    You could easily build an interface API (a separate php or C# script) that toggles. Basically you would build a condition that uses "Get Device Status" then based on the result of that cmd use "Set Device Status" to the opposite value.

                    Comment


                    • #11
                      Originally posted by desolatax View Post
                      Thank you! This is exactly what I've been looking for.
                      Haven't had a chance to do anything cool with it yet, but hopefully this weekend I'll have some time!
                      Awesome! Glad, you are enjoying it! Let me know how it works out!

                      Comment


                      • #12
                        Originally posted by RedTechie View Post
                        You can set a device to on / off using the "Set Device Status (By ID or Name)" cmd. You don't need events for that!

                        You could easily build an interface API (a separate php or C# script) that toggles. Basically you would build a condition that uses "Get Device Status" then based on the result of that cmd use "Set Device Status" to the opposite value.
                        Thanks. Well, I'm trying. Wondering if you could get me over a hump. This is my very first script, ever. Having a lot of fun learning Python, but am pretty stuck. I'm unable to get the "status" into eventghost. What I'm trying is this:

                        Code:
                        import eg
                        import urllib2
                        eg.RegisterPlugin()
                        
                        class MyNewPlugin(eg.PluginBase):
                        def __init__(self):
                        self.AddAction(HallLightOn)
                        self.AddAction(HallLightOff)
                        
                        class HallLightOn(eg.ActionBase):
                        def __call__(self):
                        response = urllib2.urlopen('http://192.168.1.102:86/HomeSeer_REST_API.aspx?function=devicestatusbyid&param1=2036&param2=on')
                        if response.read == 'true': 
                        print "true"
                        What I'm hung up on is that I can't get (response.read) to provide me anything that I can use as a variable. I can get it to print out in eventghost log as "true" or "false", but using it in my "if" statement it wont work. Just confuses me. It returns true when the light on, but using that in my code as a condition does nothing in Eventghost. It Shows my action has ran, and I get no errors, but I just want it to print something so I can then finish the code as I know its then working.

                        Hope I made sense. My brain feels like cotton right now, lol. Thanks for any help. Once I get it to respond I can finish what I'm doing fairly easily, I think.

                        Comment


                        • #13
                          Originally posted by bandook View Post
                          Thanks. Well, I'm trying. Wondering if you could get me over a hump. This is my very first script, ever. Having a lot of fun learning Python, but am pretty stuck. I'm unable to get the "status" into eventghost. What I'm trying is this:

                          Code:
                          import eg
                          import urllib2
                          eg.RegisterPlugin()
                          
                          class MyNewPlugin(eg.PluginBase):
                          def __init__(self):
                          self.AddAction(HallLightOn)
                          self.AddAction(HallLightOff)
                          
                          class HallLightOn(eg.ActionBase):
                          def __call__(self):
                          response = urllib2.urlopen('http://192.168.1.102:86/HomeSeer_REST_API.aspx?function=devicestatusbyid&param1=2036&param2=on')
                          if response.read == 'true': 
                          print "true"
                          What I'm hung up on is that I can't get (response.read) to provide me anything that I can use as a variable. I can get it to print out in eventghost log as "true" or "false", but using it in my "if" statement it wont work. Just confuses me. It returns true when the light on, but using that in my code as a condition does nothing in Eventghost. It Shows my action has ran, and I get no errors, but I just want it to print something so I can then finish the code as I know its then working.

                          Hope I made sense. My brain feels like cotton right now, lol. Thanks for any help. Once I get it to respond I can finish what I'm doing fairly easily, I think.
                          Hmm, not to familiar with Python, but have you tried:

                          PHP Code:
                          if response.read == 'True'
                          Difference being a capital "T" for true? Not sure if it's choking on the case sensitivity.



                          But if you call my API:
                          Code:
                          http://192.168.1.102:86/HomeSeer_REST_API.aspx?function=devicestatusbyid&param1=2036&param2=on
                          That is working?

                          Comment


                          • #14
                            That doesn't work either, but thanks for the shot in the dark

                            Yeah, your API works great. I can just do "print response.read()"
                            And it will log true/false. Just cant figure out why I can't capture the response and use it. I asked for some help over on the Eventghost forums, which is where I should have asked. Your side works great, its just my noobishness that's frustrating me.

                            Comment


                            • #15
                              Just to update and bring some conclusion to my issue, it was indeed a simple error. I just needed this:

                              Code:
                              if response.read() == 'True':
                              So now I am able to toggle my device with one action in eventghost with:

                              Code:
                               
                                response = urllib2.urlopen(getstatus)
                                      if response.read() == 'True':
                                          urllib2.urlopen(turnoffdevice)
                                      else:
                                       urllib2.urlopen(turnondevice)
                              Eventually I'll finish the plugin and enable you to enter each device you want to control in the plugin config, and create actions for each device. Shouldn't be crazy hard but my learning curve is steep so it will take me awhile.

                              Comment

                              Working...
                              X