Announcement

Collapse
No announcement yet.

X10 Plugin: using ExecX10() from a script

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • X10 Plugin: using ExecX10() from a script

    If you want to send X10 commands over the power line from within a script, the 'old' ExecX10() plugin function is still available. However, you cannot access it using hs.ExecX10() as many of you have discovered and you must make a special call to the plugin to access it. Here is the info you'll need to use this and a simple VB.Net 'script' that will send Preset Dim commands when called from an event that you can easily modify for your needs.

    ****** OLD (PRE-HS3) method of calling ExecX10() ******
    Code:
      Dim Code As String = "B2"     ' Device Code - a string of devices like "A1" or "A1+2+3+9".
      Dim Cmd As String = "On"      ' Command - the name of the command as a string.
      Dim DimVal As Integer = 0     ' Dim Value - (optional) This is the % dim for "Dim" and "Bright" commands. For the "Pre-set Dim" command, this is a value between 0 and 31.
      Dim Data2 As Integer = 0      ' Data2 - (optional) This is the second data byte for the "Extended" X10 command. The dimval parameter is the first data byte if the command is "Extended".
      Dim Wait As Boolean = False   ' Wait - (optional) If TRUE, the command will not return until after the X10 command has actually been sent on the power line.
    
      hs.ExecX10(code, cmd, dimval, data2, wait)

    ****** NEW HS3 method of calling ExecX10() ******
    Code:
      Dim Code As String = "B2"     ' Device Code
      Dim Cmd As String = "On"      ' Command
      Dim DimVal As Integer = 0     ' Dim %
      Dim Data2 As Integer = 0      ' Extended data or Preset Dim % (non-standard)
      Dim Wait As Boolean = False   ' Always set to FALSE!!
      Dim sRet As String
    
      ' Create an object that references the X10 plugin
      Dim X10plugin as HomeSeerAPI.PluginAccess = New HomeSeerAPI.PluginAccess(hs, "X10","")
    
      ' Call the ExecX10() function within the plugin
      Sret = X10plugin.PluginFunction("ExecX10",{Code,Cmd,DimVal,Data2,Wait})
    Format of call:
    PluginFunction("ExecX10", {parameters})

    VERY IMPORTANT: parameters must be enclosed in {} and separated by commas!

    Parameters for plugin function 'ExecX10':
    Code As string
    Command As string
    DimVal As Integer
    Data2 As Integer
    Wait As Boolean


    Notes:
    1. These parameters are the same as the old HS2 version EXCEPT when commanding a Preset Dim.
    2. Dim values for Preset Dim commands are passed to the plugin as Data2 and NOT as DimVal.
    3. Dim values for Preset Dim commands are specified as 0-100 (% dim) rather than the standard 0-31.



    Here is an example of sending Preset Dim commands:
    Code:
    '--------------------------------
    ' Send X10 Preset Dim commands on the powerline using the X10 plugin.
    
    ' Specify Main as the "Sub or Function" and enter the X10 code and Preset Dim level (in the range 0-31) separated by a comma for "Parameters".
     
    
    Sub Main(parm as object)
    
    	Dim X10plugin as HomeSeerAPI.PluginAccess = New HomeSeerAPI.PluginAccess(hs, "X10","")
    	Dim sRet As String
    	Dim sTemp() as String = Split(Parm, ",")
    	Dim Code as String = Trim(sTemp(0))
    	Dim Pdim As Integer = Cint(sTemp(1))
    	Dim DimPercent As Integer
    
    	If Pdim <= 31 And Pdim >= 0 Then 
    		DimPercent = Pdim * 100 / 31
    
    		' PluginFunction(Function to call [as string], parameters [as object])
    		' Parameters for ExecX10:
    			' X10 Code As string         ' such as "B2"
    			' X10 Command As string      ' "preset dim"
    			' DimVal As Integer (0-100)  ' dim % for standard X10 devices
    			' Data2 As Integer (0-100)   ' dim % for preset dim
    			' Wait As Boolean            ' always use False
    		' Important: parameters must be enclosed in {} and separated by commas!
    		sRet = X10plugin.PluginFunction("ExecX10",{Code,"preset dim",0,DimPercent,False})
    
    		hs.WriteLog("X10 Plugin", "X10 plugin response: " & sRet)
    
    	Else
    		hs.WriteLog("X10 Plugin Error", "Preset dim value provided is outside the range 0 - 31")
    
    	End If
    
    End Sub
    '--------------------------------
    Here's how to quickly save this as a new script in HS:
    1. Create a new event in HS and select a trigger of your choice.
    2. Select "Run a Script or Script Command" for the action.
    3. Click the Edit button next to "Choose or change the script file to run:"
    4. At the end of path in the "address bar" (very top of "Select a script file." dialog), add the name for this script. Perhaps X10pdim.vb. Mine reads like this: C:/Program Files (x86)/HomeSeer HS3/scripts/X10pdim.vb
    5. Click Submit.
    6. Expand the event action line (yellow arrow on the right).
    7. Copy the script code above.
    8. Paste the code into the "Script:" box
    9. Click "Save Script Edits"
    10. Enter Main (no quotes) in the "Sub or Function:" box
    11. Enter the X10 code for the device you want to address, a comma, and then the preset dim level you want to send (in the range 0-31). Here's an example for device B3 at Pdim 12: B3,12 (again, no quotes)
    12. Click the test button for the event (blue arrow up on the event line).
    13. Verify code is sent.


    You can easily expand or change the script to send other commands, I just wanted to demonstrate sending preset dims.

    Give it a try and let me know how you fare.
    Last edited by mfisher; January 9th, 2018, 10:21 AM. Reason: Updated to add old and new methods of calling.
    Best regards,
    -Mark-

    If you're not out on the edge, you're taking up too much room!
    Interested in 3D maps? Check out my company site: Solid Terrain Modeling

  • #2
    Thank you, I will give it a try.
    Missed the command indeed.

    Comment


    • #3
      Originally posted by mfisher View Post
      Give it a try and let me know how you fare.
      Can't get this to work with my light dimmer. I am thinking I may not have my "Status Graphics" Page set up right. I have the device set as 'dimmable'

      Would you be so kind as to provide a screen shot of one of your dimmable devices?

      I can turn it on and off by using CAPI. But haven't been able to dim it.

      Thank you!

      Comment


      • #4
        Does your device support Preset Dim commands? Note that the script above is for sending 'Preset Dim' commands, not regular dims and was provided as a workaround for a bug in the plugin related to preset dims.

        Be sure you have set the 'Device Type' on the X10 tab to the type of module you are controlling. Setting 'is Dimable' on the main page does not change the setting within the plugin.
        Best regards,
        -Mark-

        If you're not out on the edge, you're taking up too much room!
        Interested in 3D maps? Check out my company site: Solid Terrain Modeling

        Comment


        • #5
          Originally posted by mfisher View Post
          Does your device support Preset Dim commands? Note that the script above is for sending 'Preset Dim' commands, not regular dims and was provided as a workaround for a bug in the plugin related to preset dims.

          Be sure you have set the 'Device Type' on the X10 tab to the type of module you are controlling. Setting 'is Dimable' on the main page does not change the setting within the plugin.
          I have a cm15a interface. Type 'x15' is shown as the default device "type". Should I enter each individual x10 device type in Advanced - 'Device Type (String)' ? The area is free form.

          The device is a WS467. Pre-set dimming is not mentioned in the documentation.

          thank you for the help with this.

          EDIT. I just read that preset dimming is not supported by the CM15A plugin.
          Last edited by frankc; June 3rd, 2016, 01:56 PM.

          Comment


          • #6
            Originally posted by mfisher View Post
            Be sure you have set the 'Device Type' on the X10 tab to the type of module you are controlling.
            I finally figured out that the "Type" box is missing from my CM15A setup.

            Since this turns out to be an entirely different problem than this thread addresses, I started a new thread.

            Thanks for mentioning 'Device Type' setup. I searched for more information on that and finally found an image of what it is supposed to look like.

            Comment


            • #7
              Unfortunately there are many issues with the CM15a plugin. One of the major ones is that while the hardware supports preset dims, the ActiveHome SDK that the CM15a plugin uses to interface with the hardware does not support preset dims.
              Last edited by mfisher; January 6th, 2018, 11:42 AM.
              Best regards,
              -Mark-

              If you're not out on the edge, you're taking up too much room!
              Interested in 3D maps? Check out my company site: Solid Terrain Modeling

              Comment


              • #8
                Originally posted by mfisher View Post
                while the hardware supports preset dims, the ActiveHome SDK that the CM15a plugin used to interface with the hardware does not support preset dims.
                Is it possible to send a command to the device to set the 'on level' to one that is dimmed even if there is no preset dims?

                I've tried every combination using ExecX10 I can think of and I can't get the device to respond. I can, however, use "hs.CAPIControlHandler" to turn them on and off.

                The following returns sRet = 'Nothing':
                Code:
                Dim sRet As String
                Dim X10plugin As HomeSeerAPI.PluginAccess = New HomeSeerAPI.PluginAccess(hs, "CM15A", "")
                sRet = X10plugin.PluginFunction("ExecX10", {"A8", "off", 0, 0, False})
                Last edited by frankc; June 5th, 2016, 08:07 AM.

                Comment


                • #9
                  I can't speak from experience to your first question, though my guess is that the answer is 'no'.

                  Regarding the ExecX10 command, I believe the return variable 'sRet' captures any errors generated by the command line. I do not know what the significance of a return value of 'Nothing' means, though.

                  Am I correct in assuming that the script command does not turn off the device with address A8, but a device control action in an event does?

                  I can say that the command does work with the X10 plug-in, at least most of the time. I have seen some behavior that makes me suspect that the off function does not work every time, but have not been able to get solid evidence.
                  Mike____________________________________________________________ __________________
                  HS3 Pro Edition 3.0.0.548

                  HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF, Rain8Net+ | RFXCOM | QSE100D | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3

                  Comment


                  • #10
                    The ExecX10 'word' does not yield any results no matter how I use it. I am assuming that "Nothing" means that an error occurred. I can deliberately put "wrong" stuff in that statement and "Nothing" is returned.

                    Yes, the devices can be turned on and off from an event.

                    And Capi controls in scripts do turn the device on and off. And I haven't seen a time when that didn't work. But I haven't found a way to dim with Capi.

                    Also, from the HS3 Device Management screen, I can turn devices on and off, seemingly consistently without fail.

                    Also from that page, I can dim a device with the slider bar. So perhaps there are statements or parameters that could be sent from a script to emulate what is happening on that page that would result in dimming.

                    The cm15a plugin works perfectly for me except for the dimming issue and the plugin not passing external inputs to HS3.

                    Perhaps a look at the plugin source code would reveal some useful things. Assuming we don't have the source code, how difficult would it be to write one?

                    Comment


                    • #11
                      Originally posted by frankc View Post
                      The ExecX10 'word' does not yield any results no matter how I use it. I am assuming that "Nothing" means that an error occurred. I can deliberately put "wrong" stuff in that statement and "Nothing" is returned.
                      My guess is that it returns "Nothing" because it isn't being recognized. In my system, the return string is "Command Sent." If I make an error I either get an X10 error and the return value is blank, or - if I enter a dim value that cannot be processed, the function still returns "Command Sent", but physical results are unpredictable.

                      And Capi controls in scripts do turn the device on and off. And I haven't seen a time when that didn't work. But I haven't found a way to dim with Capi.

                      Also, from the HS3 Device Management screen, . . .I can dim a device with the slider bar. So perhaps there are statements or parameters that could be sent from a script to emulate what is happening on that page that would result in dimming.
                      Try this:
                      Code:
                      Dim cc as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(379, True, "Brightness (value)%", False, False)
                      cc.ControlValue = 10
                      Dim cr as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                      Replace 379 with the Ref # of your device.
                      ControlValue is the dim percent.
                      If this works, then I'd strongly recommend you look at TenScriptAid.

                      Regarding your other post:
                      Originally posted by frankc View Post
                      I'm wondering whether there is any advantage in manually entering a Device Type in Advanced - Device Type. Perhaps that would tell HS3 to select a certain set of parameters.
                      I doubt it. In my system, the device type is simply listed as X10.
                      Mike____________________________________________________________ __________________
                      HS3 Pro Edition 3.0.0.548

                      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF, Rain8Net+ | RFXCOM | QSE100D | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3

                      Comment


                      • #12
                        Yes... "Not Recognized" is more inline with what I was thinking.

                        So maybe "Device Type" is just used to set up the Value-Status pairs in the 'Status-Graphics' tab, and then ignored ?

                        I tried your script. First line was OK. But 'cc.ControlValue = 10' returned an error: "Object reference not set to an instance of an object."

                        And I am not at all familiar with what that code means. I have used hs.CAPIControlHandler and hs.CAPIGetSingleControl, but not in that manner.

                        I appreciate your help with this!

                        Comment


                        • #13
                          Hmmm.
                          Does the S/G tab of the device you want to dim in a script look like this?
                          Attached Files
                          Mike____________________________________________________________ __________________
                          HS3 Pro Edition 3.0.0.548

                          HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF, Rain8Net+ | RFXCOM | QSE100D | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3

                          Comment


                          • #14
                            If I replace "Brightness (value)%" with "on" or "off", the device turns on and off without error.

                            So I think that means that "Brightness (value)%" isn't recognized. Could it be the way my device is setup. I do not have a way to set "Device Type".

                            Comment


                            • #15
                              Originally posted by Uncle Michael View Post
                              Hmmm.
                              Does the S/G tab of the device you want to dim in a script look like this?
                              It did not look like that. I first converted it to look like that, then it still failed on the second line of code. So I deleted the device and rebuilt it again to look like that, but it still failed on the second line.

                              But when I replace "Brightness (value)%" with "on" or "off", the code runs.

                              I checked spelling, etc. And the page is identical.

                              Comment

                              Working...
                              X