more G-Labs products

Author Topic: How to understand the syntax of an API call  (Read 673 times)

January 11, 2016, 04:52:18 AM
Read 673 times

kevinvinv

  • ****
  • Information
  • Sr. Member
  • Posts: 196
The documentation lists a particular API call like this for example
/api/HomeAutomation.X10/<module_address>/Control.Off

But how do I understand how to CALL this "function" from C# for example?  That doesn't seem to be clear to me.

Thanks for your patience!  :)

January 11, 2016, 01:37:20 PM
Reply #1

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
The API you mentioned is what is referred to as "webapi" (I think, that's how I refer to it anyway). The widgets and external code can "call" these to execute things in HG.  I use these webapi URL's to link my Amazon Echo to IFTTT to turn on lights:

http://<IP>/api/HomeAutomation.X10/A1/Control.On
http://<IP>/api/HomeAutomation.ZWave/16/Control.Off

Depending how a given module is coded, it can return a value (to the web browser) like:
  result:   {"ResponseValue":"OK"}

To turn a module off you could do (examples are not tested so not 100% sure accurate):
Code: [Select]
Modules.WithName("Light 1").On();
Modules.InGroup("Living Room").WithName("Lamp").Off();
Modules.WithAddress("A1").On();

var sirenModules = Modules.WithFeature("HomeGenie.SecurityAlarm").OfDeviceType("Siren");
sirenModules.On();

//if you are inside an if statement to match name, group, features etc, then
         module.Off();

January 11, 2016, 01:56:25 PM
Reply #2

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Read here about the API command syntax:

http://genielabs.github.io/HomeGenie/api/mig/overview.html

In your example we have

/api/HomeAutomation.X10/<module_address>/Control.Off

domain = HomeAutomation.X10
address = <module_address> (let's prentend it to be "A5")
command = Control.Off

So to call this from a script you will use:

Code: [Select]
var module = Modules.InDomain("HomeAutomation.X10").WithAddress("A5");
module.Command("Control.Off").Execute();
// or as kevin1 said you can use the shortcut
module.Off();

reading this http://genielabs.github.io/HomeGenie/programs.html can also help.

Cheers,
g.
« Last Edit: January 11, 2016, 01:58:38 PM by Gene »