more G-Labs products

Author Topic: Marmitek LM12 Module  (Read 785 times)

November 02, 2015, 04:00:09 PM
Read 785 times

runs

  • *
  • Information
  • Newbie
  • Posts: 2
I want to use this lamp dimmable module into HG.
I've made a program like the following?

Code: [Select]
Program.AddVirtualModule("HomeAutomation.Marmitek", "A1", "Dimmer", "homegenie/generic/dimmer");
var myModules = Modules.InDomain("HomeAutomation.Marmitek");

// handle standard API calls
When.WebServiceCallReceived("HomeAutomation.Marmitek", ( args ) => {
  string[] reqs = ((string)args).Split('/');
  try
  {
    string lightnumber= reqs[1];
    string command= reqs[2];
    string parameter= ""; if (reqs.Length > 3) parameter = Uri.UnescapeDataString(reqs[3]);
 
    var module= myModules.WithAddress(lightnumber).Get();
    var dim_level= module.Parameter("Status.Level").DecimalValue;
 
    switch(command) {
      case "Control.On":
module.On();
        break;
      case "Control.Off":
module.Off();
        break;
      case "Control.Toggle":
        if (dim_level == 0) {
module.On();
        }
        else {
module.Off();
        }
        break;
      case "Control.Level":
module.Level= dim_level;
        break;
    }
    //
    return "{ 'ResponseValue' : 'OK' }";   
  } catch (Exception e) {

    Program.Notify("My Light ERROR!", e.Message);

  }
  return "{ 'ResponseValue' : 'ERROR' }";
});

Is this correct?


There are no comments for this topic. Do you want to be the first?