more G-Labs products

Author Topic: Change switch module status level  (Read 1171 times)

March 11, 2015, 11:40:25 AM
Read 1171 times

KaZe

  • ****
  • Information
  • Sr. Member
  • Posts: 219
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?

March 11, 2015, 12:49:49 PM
Reply #1

KaZe

  • ****
  • Information
  • Sr. Member
  • Posts: 219
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!

March 11, 2015, 07:40:20 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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();

March 11, 2015, 08:41:02 PM
Reply #3

KaZe

  • ****
  • Information
  • Sr. Member
  • Posts: 219
Thx!

I updated my code.