Announcement

Collapse
No announcement yet.

Python - How to script in HS using Python...

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

  • Python - How to script in HS using Python...

    I was hoping to find a "How To" guide to setup my HS3 system to be able to script using Python. Something that would take a user through the setup of Python to the creation of a script to query say the state of a device and then possibly turn a device on, off, dim value.... Then an example event that would call the python script...

    I would imagine that the first step would be to install Python onto the HS3 system. Can this be Python 3.x or should it be Python 2.7?

    Are there any modules that one might need to interface with HS3?

    I guess a HS3 Python for Dummies guide...

    WHY - well at work they are starting to use Python quite a bit and as such I would like to switch over and use it here as well.

    GOAL: I have an DSC Alarm System that is now interfaced with my HS3 system via the EnvisaLink Plug-In. I have created a HSTouch interface for my iPhone that lets me see the status of all my sensors as well as arm and disarm my system... I want to write a script that I could use to bypass all open sensors with a single press of a button. I would assume it would need to scan the state of all sensors, note those that are open/not ready and then go back through that list and bypass each one. This would save the time from having to individually bypass open sensors...

    OK now I guess I search any HS documentation I can find on scripting...

  • #2
    OK so far I found

    http://forums.homeseer.com/showthread.php?t=160063

    In the PDF file on Page 42 it seems to be the start of Scripting Help.

    And online it starts at:

    http://homeseer.com/support/homeseer.../scripting.htm


    Now to start some reading....

    Well not a thing on Python. Found Visual Basic (.vbs .vb) or C# (.cs). I've done a little with Visual Basic scripting. Once I tried to get my dinning room light to pulse like the lights on the Indiana Jones ride at Disneyland that look like they are running on a old generator. It was for a Halloween project. Also did a little Thermostat scripting... I really would like to use Python vs C# or VB.

    Comment


    • #3
      Interesting...I "started" trying to learn python but end up putting it on my long to do list. Will be following your progress...

      "Once I tried to get my dinning room light to pulse like the lights on the Indiana Jones ride at Disneyland that look like they are running on a old generator" - Wow, nice. how did you do this, and would you mind sharing your script?
      Tom
      baby steps...starting again with HS3
      HS3Pro: Z-NET & 80 Z wave Devices,
      HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
      Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
      In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
      System: XP on Fanless Mini-ITX w/ SSD

      Comment


      • #4
        Gen Light Script...

        It was a long time ago, in a galaxy ....

        I was then using HS to manage my Insteon & Z-wave Devices and have since switched to ISY-994i and use ISTInsteon HS Plugin.

        In that galaxy I was also still on HS2 vs now HS3.

        Needless to say, the blow code does not like the galaxy I am currently in.

        To the best I can remember I was developing this bit of code and it was working, however, not finalized.

        In the HS3 galaxy and what ever other updates to the OS and .net that have happened, I now get errors... It will need work to finalize in HS3 and I believe it only runs through the simulated gen lighting once as I did not get to the run until I end the even code...

        Code:
        Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
        
        Public Sub Main(Parm As Object)
        
        Dim LvlHigh = 30
        Dim LvlLow = 20
        Dim LvlDelay = 1
        
        hs.plugin("Insteon").setdevicesetting("1B.B6.22","Default Ramp Rate", "19 Sec.")
        
        For x As Integer = 1 to 5
        	hs.setdevicevalue("[4", LvlLow)
        	WaitSeconds(LvlDelay)
        	hs.setdevicevalue("[4", LvlHigh)
        	WaitSeconds(LvlDelay)
        Next x
        
        hs.setdevicevalue("[4", 0)
        
        End Sub
        
        Public Sub WaitSeconds(intSeconds As Integer)
          ' Comments: Waits for a specified number of seconds
          ' Params  : intSeconds      Number of seconds to wait
          ' Source  : Total Visual SourceBook
        
          Dim datTime As Date
        
          datTime = DateAdd("s", intSeconds, Now)
        
          Do
           ' Yield to other programs (better than using DoEvents which eats up all the CPU cycles)
            Sleep(100)
            Windows.Forms.Application.DoEvents()
          Loop Until Now >= datTime
        
        End Sub

        Comment


        • #5
          Seems I have read that HS3 uses .net to run its scripts and I may need to use something like IronPython. It's described on their site as:

          IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.

          IronPython is an excellent addition to the .NET Framework, providing Python developers with the power of the .NET framework. Existing .NET developers can also use IronPython as a fast and expressive scripting language for embedding, testing, or writing a new application from scratch.

          The CLR is a great platform for creating programming languages, and the DLR makes it all the better for dynamic languages. Also, the .NET framework (base class library, presentation foundation, Silverlight, etc.) gives developers an amazing amount of functionality and power.
          Of course I have no idea how.... more reading....

          Comment


          • #6
            Don't Read when you can steal/borrow.

            I would not bother trying to get Python working. Been looking at a Raspberry PI and yet another scripting language is not the hardest part to overcome.
            Even for my trivial first script which I started in VB.NET in Notepad++ it was a short time before I was very much helped with better tools.

            Get "Visual Studio Express 2013 for Windows Desktop" free from Microsoft and the TenScripting debug environment with examples from here
            http://www.tenholder.net/tenWare2/tenScripting/

            It will save you a lot of time with debugging and syntax accelerators.

            Comment


            • #7
              IronPython & Homeseer

              Hi,

              Installed IronPython and tried the following Python script:

              def Main():
              hs.WriteLog("Debug","Hello HomeSeer from Smart-Living in Python!")

              It doesn't seem work work as I get the following error message in the log:

              Running script: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex-> at System.String.IndexOf(String value, Int32 startIndex, Int32 count, StringComparison comparisonType) at System.String.IndexOf(String value, Int32 startIndex) at A.c1b0f37609f2


              Anyone more success?

              Regards,
              Jan

              Comment

              Working...
              X