HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: KaZe on March 11, 2015, 11:40:25 AM

Title: Change switch module status level
Post by: KaZe on March 11, 2015, 11:40:25 AM
Hi!

I need little help!

I wrote a C # program to manage eight relays.
I created the switches with the following code:

Code: [Select]
Program.AddVirtualModules ("HomeAutomation.SettingSwitch", "Switch", "homegenie / generic / switch", 1, 8);
The relays status every 5 seconds retrieves, and attempts to set the virtual switch status of the returned value ("status level").

I can look at the states with the following code:

Code: [Select]
var SettingSwitchModules = Modules.InDomain("HomeAutomation.SettingSwitch");
                for (int i = 0; i < 8; i++)
                  {
    var module = SettingSwitchModules.WithAddress((8-i).ToString()).Get();
    if ((module.Parameter("Status.Level").DecimalValue).ToString() != relayarray[i].ToString())
                      {
                if ((module.Parameter("Status.Level").DecimalValue).ToString() =="1") 
                          {
                             Program .Notify("Switch","You need to turn OFF the relay "+(8-i).ToString()"); 
                          }
                      }
                  }


How do I the state of the virtual switches (status level) change?
Title: Re: Change switch module status level
Post by: KaZe on March 11, 2015, 12:49:49 PM
I found the answer in the other topic:

Code: [Select]
// Turn Switch on
module.Command("Control.On").Set();
// or Off
module.Command("Control.Off").Set();
// or Toggle the switch
module.Command("Control.Toggle").Set();

It"s works!
Title: Re: Change switch module status level
Post by: bkenobi on March 11, 2015, 07:40:20 PM
Your code has an extra space in the notify line:
Code: [Select]
Program .Notify("Switch","You need to turn OFF the relay "+(8-i).ToString()");Should be
Code: [Select]
Program.Notify("Switch","You need to turn OFF the relay "+(8-i).ToString()");
Also, you should be able to simplify your commands to control the relay state to:
Code: [Select]
// Turn Switch on
module.On();
// or Off
module.Off();
// or Toggle the switch
module.Toggle();
Title: Re: Change switch module status level
Post by: KaZe on March 11, 2015, 08:41:02 PM
Thx!

I updated my code.