Announcement

Collapse
No announcement yet.

New Plugin - Use WebSockets for getting status updates

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

  • New Plugin - Use WebSockets for getting status updates

    I finally got around to playing with HomeSeer plugin development. I'm working on a project that I want to integrate with HomeSeer so I was looking for an easy way to get device status updates for any number of devices. In my searching I found a plugin on GitHub that somebody wrote that makes HTTP POSTs when device status changes, but I wanted something lighter weight to go along with a different project I'm working on. I took his code (https://github.com/DoctorMcKay/HSPI_...Notifications/) as a template, and went with WebSockets instead of HTTP POSTs.

    The end result is a plugin that spins up a web server on a configurable port, and any time a device changes, any connected client will get status updates instantly. It's very much in the early stages of development, and there are a number of things I want to add to it to increase its functionality and usability, but I thought I'd share it now to see if anybody wanted to give feedback.

    https://github.com/PilotC150/HSPI_WebSockets

    I don't have any documentation on it yet, or any compiled and zipped up releases. It's just the source code. So if anybody wants to try it out, feel free. If anybody wants me to upload a compiled version to test with, I can do that, too.

    Anybody have any ideas for things you'd like added? I can take those under advisement, as well. Like I said, I've already got a list of ideas of things I'm thinking about possibly adding, as time allows.

  • #2
    So if I understand this correctly... you are taking HS device events and posting those to a websocket server that another websocket client can consume? Interesting.

    I would also like to point you in the direction of the native ASCII interface that provides what you are looking for just in a different method.

    Comment


    • #3
      Close, but not exactly. The plug-in itself is the websocket server.

      The user can configure the port, say 8080, and start up the plugin. The user can then have one or more client endpoints (mobile app, webpage, etc.) connect to "http://{homeseer ip}:8080" over websockets and there will now be a persistent connection. Any time a device status changes in HomeSeer, the data will get broadcast to any client connected to it. This removes the necessity of polling HomeSeer to find out the status of devices. Changes are broadcast instantaneously so there's no lag.

      Comment


      • #4
        Originally posted by PilotC150 View Post
        Close, but not exactly. The plug-in itself is the websocket server.

        The user can configure the port, say 8080, and start up the plugin. The user can then have one or more client endpoints (mobile app, webpage, etc.) connect to "http://{homeseer ip}:8080" over websockets and there will now be a persistent connection. Any time a device status changes in HomeSeer, the data will get broadcast to any client connected to it. This removes the necessity of polling HomeSeer to find out the status of devices. Changes are broadcast instantaneously so there's no lag.
        Ok I like the websocket server aspect and it opens it for integration with other systems. I'm just point out it's the same as the ASCII interface as in it does the same thing just using websocket as the medium. I can see many uses for this if it doesn't put too much strain on HS....this should be interesting!

        Comment


        • #5
          Originally posted by simplextech View Post

          Ok I like the websocket server aspect and it opens it for integration with other systems. I'm just point out it's the same as the ASCII interface as in it does the same thing just using websocket as the medium. I can see many uses for this if it doesn't put too much strain on HS....this should be interesting!
          Yeah, that's why I went with WebSockets. Any system can connect to it, it's a persistent connection, and it's a more modern technology. It shouldn't put any extra strain on HS since from the HS side, it's just calling the HSEvent function in the plugin. Most of the WebSocket work is actually happening in separate threads. The only thing that's happening in the main plugin thread is the HSEvent function call and create the object that will eventually get broadcast over the WebSocket.

          Can you point me at some documentation for the ASCII Interface? The only thing I came up with while searching was something related to Telnet and that doesn't seem ideal.

          Comment


          • #6
            Here's the doc link:

            http://help.homeseer.com/help/ASCII-JSON/static/

            The ASCII interface is a standard that's been around for years and still used by many things. The examples use telnet because it's a widely available tool for testing and usage but to use ASCII interfaces all you need is a raw socket connection which can be done from anything (almost) that has a network stack.

            I'm in favor of the websocket interface and I was hopeful we might get it native in HS4. However the sooner an implementation the better in my view. It will open up the door to integration with other systems in a bi-directional manner.

            Comment


            • #7
              Got it. Thanks. I see what you mean how it does the same thing, or at least has the same goals.

              Right now it's built strictly for broadcasting status updates because I have been using a REST API for controlling devices as necessary (https://forums.homeseer.com/forum/de...tp-restful-api). One of the next things I want to add is the ability to pass a formatted data packet through the WebSocket to control a device, as well. In fact, most of the functions that are available in that REST API could be available over an already-connected WebSocket connection.

              I've got a few other ideas to make it a more fully-featured interfacing plugin, as well.

              Comment


              • #8
                Originally posted by PilotC150 View Post
                Got it. Thanks. I see what you mean how it does the same thing, or at least has the same goals.

                Right now it's built strictly for broadcasting status updates because I have been using a REST API for controlling devices as necessary (https://forums.homeseer.com/forum/de...tp-restful-api). One of the next things I want to add is the ability to pass a formatted data packet through the WebSocket to control a device, as well. In fact, most of the functions that are available in that REST API could be available over an already-connected WebSocket connection.

                I've got a few other ideas to make it a more fully-featured interfacing plugin, as well.
                It sounds very interesting and something I would be interested in and could possibly put to use with other projects for integrations. At the very least it would open a new avenue for development of web interfaces for dashboards and tablets which is currently lacking.

                Comment

                Working...
                X