Announcement

Collapse
No announcement yet.

Newbie question: How to simply turn on/off a light in a script??

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

  • JKaplan
    replied
    Thanks, very helpful!

    jerry

    Leave a comment:


  • Wadenut
    replied
    Originally posted by JKaplan View Post
    Thanks Unc and Sparkman... indeed, I had to bite the bullet and move the scripts to VB using CAPI. Not for the feint of heart, what a complex interface! All working, finally...
    You could just make Al's example a subroutine and use it everywhere you need the function in a script.

    Sub ControlLight(ByVal AnyLight as String, ByVal NewSetTo As String)
    Dim dvRef as Integer = hs.GetDeviceRefByName(AnyLight)
    hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef, false, NewSetTo, false, false))
    End Sub

    To use it:
    ControlLight("Jerry's Office","On")
    or
    ControlLight("Jerry's Office","Off")

    Leave a comment:


  • JKaplan
    replied
    I'm over the hump now, but I'll give it a try next script revision...

    Leave a comment:


  • Uncle Michael
    replied
    Originally posted by JKaplan View Post
    I had to bite the bullet and move the scripts to VB using CAPI. Not for the feint of heart, what a complex interface!
    As Ed noted earlier, I pointed you to the wrong tool in my earlier post. Although tenScripting is a great help when trying to translate a VBS script to vb.net, tenScriptAid is the tool you want to help construct CAPI commands. It makes it relatively easy - even for the faint of heart.

    Leave a comment:


  • JKaplan
    replied
    Thanks Unc and Sparkman... indeed, I had to bite the bullet and move the scripts to VB using CAPI. Not for the feint of heart, what a complex interface! All working, finally...

    Leave a comment:


  • sparkman
    replied
    Try this and save it with a .vb extension:

    Code:
    Sub Main(ByVal Parms as String)
    
    Dim dvRef as Integer = hs.GetDeviceRefByName("Jerry's Office")
    hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef, false, "On", false, false))
    
    End Sub
    If that does not work, please post a screen shot of the Status Graphics tab for the device that you are trying to turn on.

    Leave a comment:


  • sparkman
    replied
    The whole script is in VBScript format so it'll take more than just renaming it and changing the first line.

    Leave a comment:


  • Uncle Michael
    replied
    Originally posted by BlairG View Post
    According to what I see, is your scripts name 'test.txt' ??

    rename it to 'test.vb' and try again.
    The first line of the script will probably need to be changed as well
    from: sub main()

    to: Public Sub Main(ByVal Parms As Object)

    Leave a comment:


  • BlairG
    replied
    According to what I see, is your scripts name 'test.txt' ??

    rename it to 'test.vb' and try again.

    Leave a comment:


  • tenholde
    replied
    tenScriptAid

    Leave a comment:


  • Uncle Michael
    replied
    I believe you need to use vb.net. I don't think the CAPI functions are compatible with VBS. I'd also recommend taking a look at Ed Tenholder's tenScripting for excellent guidance in implementing CAPI.

    Leave a comment:


  • Newbie question: How to simply turn on/off a light in a script??

    I can't seem to get this to work. I'm using VBscript, here's the script:


    ------

    sub main()

    dvRef = hs.GetDeviceRefByName("Jerry's Office")
    hs.writelog "dvRef", dvRef

    objCAPIControl = hs.CAPIGetSingleControlByUse(77, 2)

    hs.writelog "objCAPIControl", objCAPIControl

    hs.CAPIControlHandler objCAPIControl

    end sub

    ------

    The log output is:
    Jun-18 1:08:54 PM Error Running script, script run or compile error in file: C:/Program Files (x86)/HomeSeer HS3/scripts/test.txt5:Invalid procedure call or argument: 'hs.CAPIControlHandler' in line 10 More info: Invalid procedure call or argument: 'hs.CAPIControlHandler'
    Jun-18 1:08:54 PM objCAPIControl HomeSeerAPI.CAPI+CAPIControl
    Jun-18 1:08:54 PM dvRef 77
    Jun-18 1:08:54 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/test.txt
    Jun-18 1:08:54 PM Event Event Trigger "misc Test turn a light off/on by script"
    Jun-18 1:08:54 PM Event Event misc Test turn a light off/on by script triggered by the event page 'Run' button.

    Obviously, the device is found (ref # 77), and I think the CAPI control object is found (CAPI+CAPIControl), though I don't know what CAPI+CAPIControl means. But the call to hs.CAPIControlHandler doesn't work. (Note that in VB script, there's no need for parens here).

    The Device is a UPB light switch, a "UPB Device" imported through UPBSpud. I can control the device normally through the Device page interface.

    Note also that the script interpreter objects to the underscore as an "invalid character" if I try this:

    objCAPIControl = hs.CAPIGetSingleControlByUse(dvRef,ePairControlUse._On)

    ...so I substituted the value for "off" (2, supposedly). Quoting the value as a string doesn't work either.



    I've spent hours trying everything to no avail. Any advice appreciated!


    Jerry


    Current Date/Time: 6/18/2019 1:21:49 PM
    HomeSeer Version: HS3 Standard Edition 3.0.0.534
    Operating System: Microsoft Windows 10 Pro - Work Station
    System Uptime: 0 Days 0 Hours 47 Minutes 42 Seconds
    IP Address: 192.168.1.101
    Number of Devices: 155
    Number of Events: 60
    Available Threads: 200
    HSTouch Enabled: True
    Event Threads: 0
    Event Trigger Eval Queue: 0
    Event Trigger Priority Eval Queue: 0
    Device Exec Queue: 0
    HSTouch Event Queue: 0
    Email Send Queue: 0
    Anti Virus Installed: Windows Defender
    In Virtual Machine: No MFG: dell inc.
    Enabled Plug-Ins
    3.0.6681.34300: UltraCID3
    3.0.0.50: UPBSpud
    3.0.0.36: X10



Working...
X