Announcement

Collapse
No announcement yet.

CAPI makes no sense to me

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

    CAPI makes no sense to me

    I need some dumbed down explanation of CAPI or something.

    I've tried so many variations of examples i've found for controlling devices but for some reason continue to have problems.

    So, i'm hoping to get a clear example of the following:

    How do you control an on / off switch?

    How do you control a dimmer switch?

    I've got something like this, among other examples that i've tried:

    Code:
    hs.CAPIControlHandler(hs.CAPIGetSingleControl(lightId,false,val,false,true));
    I will have a var with the device in it (should it be just the device ID, or does it need to be another reference to the device?

    I will also have a var with the level that the light should be set to (1-100). (for dimmers)

    For on/off switches, I will have a var that represents on or off.

    if I can get an example that sets these vars, and controls the device, that would be a huge help. This is just not something that makes sense to me for some reason.

    #2
    Try this utility to generate CAPI code for your device actions:

    http://tenholder.net/tenWare2/tenScriptAid/default.aspx

    http://tenholder.net/tenWare2/tenScriptAid/Videos.aspx



    tenholde
    tenholde

    Comment


      #3
      thanks a lot for the reply. Wow, what an awesome tool!

      So, this is what got spit out for me to run in my script:

      Code:
      Dim cc as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(113, True, "Dim (value)%", False, False)
      cc.ControlValue = 3
      Dim cr as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
      i replaced 113 with lightId variable, and i replaced 3 (control value) with val variable. I also added semi colons to the end.

      so i end up with this:
      Code:
       Dim cc as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(lightId, True, "Dim (value)%", False, False);
          cc.ControlValue = val;
          Dim cr as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc);
      This is the error I get in the logs when trying to run this:

      Code:
      Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\MatchLightLevel.cs: {interactive}(59,11): error CS1525: Unexpected symbol `as', expecting `,', `;', or `=' {interactive}(59,86): error CS1001: Unexpected symbol `Dim (value)%', expecting identifier {interactive}(59,108): error CS0128: A local variable named `False' is already defined in this scope {interactive}(59,112): error CS1525: Unexpected symbol `)', expecting `;' {interactive}(63,11): error CS1525: Unexpected symbol `as', expecting `,', `;', or `=' {interactive}(2,1): warning CS0105: The using directive for `System' appeared previously in this namespace {interactive}(3,1): warning CS0105: The using directive for `System.Linq' appeared previously in this namespace {interactive}(4,1): warning CS0105: The using directive for `Scheduler' appeared previously in this namespace {interactive}(5,1): warning CS0105: The using directive for `HomeSeerAPI' appeared previously in this namespace
      So, not sure what to do about this. any ideas?

      Also... just have to say it, this a joke how verbose it is to control a simple device. Why hasn't homeseer written some methods to do this? IE. hs.DimLight(deviceId, dimLevel) or hs.ControlCapi(deviceId, 1 or 0).

      Thanks again for chiming in and sharing your tool. Glad i'm not the only one that recognizes the cumbersome nature of the CAPI control.

      Comment


        #4
        I was able to get it working. Turns out, that code is not c# friendly. I don't know either languages really, but it seems like c# is the better way to go, so I figure I wont mess with VB.

        anyway, if anyone else needs it, this is what I ended up adjusting the code to:

        Code:
            HomeSeerAPI.CAPI.CAPIControl cc = hs.CAPIGetSingleControl(lightId, true, "Dim (value)%", false, false);
            cc.ControlValue = val;
            HomeSeerAPI.CAPI.CAPIControlResponse cr = hs.CAPIControlHandler(cc);
        Thanks again for the nice little tool. Huge help!

        Comment


          #5
          tenScriptAid generates vb.net code only, but should give you an idea of what the C# code should look like.

          tenholde
          tenholde

          Comment


            #6
            Originally posted by smikkelsen View Post
            Also... just have to say it, this a joke how verbose it is to control a simple device. Why hasn't homeseer written some methods to do this?
            Although I can't give you a satisfactory answer, I think that HST would claim that using HS events is the preferred method. The good news is that with Ed's tool, the solution is just an extra cut-and-paste crib, rather than writing an original essay.
            Mike____________________________________________________________ __________________
            HS3 Pro Edition 3.0.0.548, NUC i3

            HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

            Comment


              #7
              Originally posted by smikkelsen View Post
              I was able to get it working. Turns out, that code is not c# friendly. I don't know either languages really, but it seems like c# is the better way to go, so I figure I wont mess with VB.
              You'll find that most scripts around here are in vb.net and vbscript, rather than c# (close to 100%) and the examples HS provides are also in vb.net and vbscript. Beacuse of that I would recommend using vb.net for HS.

              Cheers
              Al


              Sent from my Phone using Tapatalk
              HS 3.0.0.548: 1990 Devices 1172 Events
              Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

              Comment


                #8
                Originally posted by smikkelsen View Post
                Also... just have to say it, this a joke how verbose it is to control a simple device. Why hasn't homeseer written some methods to do this? IE. hs.DimLight(deviceId, dimLevel) or hs.ControlCapi(deviceId, 1 or 0).
                Look at this poll on the subject. Overwhelming result but ignored. The fact that they implemented something for JSON makes it worse.
                Jon

                Comment


                  #9
                  I think that HST would claim that using HS events is the preferred method.
                  Yeah... Unfortunately, the event engine is limited in other ways. For example, I cannot set the value of a device to the value of another device. Seems silly.

                  You'll find that most scripts around here are in vb.net and vbscript, rather than c# (close to 100%) and the examples HS provides are also in vb.net and vbscript. Beacuse of that I would recommend using vb.net for HS.
                  Good to know. Is this just a matter of preference for people? I was under the impression that c# scripts were faster. I thought I read that in the documentation, but I could be wrong.

                  Look at this poll on the subject. Overwhelming result but ignored. The fact that they implemented something for JSON makes it worse.
                  Yeah, that is frustrating.

                  Thank you all for your input.

                  Comment


                    #10
                    Originally posted by smikkelsen View Post
                    Good to know. Is this just a matter of preference for people? I was under the impression that c# scripts were faster. I thought I read that in the documentation, but I could be wrong.
                    C# is only faster on Linux, however there are several issues still unresolved using it on HS3. The majority of people use VB.NET which is fully supported. I very much doubt you would notice any difference in speed between the two unless you write something complex.
                    Jon

                    Comment


                      #11
                      Originally posted by smikkelsen View Post
                      Yeah... Unfortunately, the event engine is limited in other ways. For example, I cannot set the value of a device to the value of another device. Seems silly.
                      Actually, you can. . .with the EasyTrigger plug-in.
                      Mike____________________________________________________________ __________________
                      HS3 Pro Edition 3.0.0.548, NUC i3

                      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                      Comment


                        #12
                        Originally posted by tenholde View Post
                        tenScriptAid generates vb.net code only, but should give you an idea of what the C# code should look like.

                        tenholde
                        Working on tenScriptAid4 for HS4. Will generate code more specific for HS4 AND WILL ALSO GENERATE C# CODE!

                        tenScripting now allows you to code and debug in C#
                        tenholde

                        Comment

                        Working...
                        X