HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: BruceS on March 28, 2015, 09:13:54 PM
-
I have a few scenarios where I would like to trigger a program by clicking a virtual module (such as pushing a garage door button). I created a test program below but when I click on the module I assigned to the program it doesn't trigger program or else the module isn't clickable. I would appreciate any guidance.
Trigger
Program.Setup(()=>
{
Program.AddControlWidget("homegenie/generic/status");
});
return true;
Program
//do something intelligent
Program.Notify("Manual Trigger Test", "Success");
Program.Say("Test Successful", "en-US");
-
Assuming you're using C# Program as your program type, the Program Code section needs to be in the form of a loop or function. For example:
When.ModuleParameterChanged((module, parameter) => {
if (module.Instance.Name == "MyModule"){
Program.Notify("MyModule", parameter.Value);
}
return true;
});
Program.GoBackground();
Depending on what you're doing, you could look for your module by name, or a type of module by domain or parameter if you plan on creating several of these modules.
-
OK I tried using When.ModuleParameterChanged with C# but I am still puzzled. How do I get my module to change when I click on it? And what parameter am I looking for? Maybe I'm stating it wrong. Should I be calling it a control widget?
-
You're using a status widget (homegenie/generic/status), so it doesn't have any input. Try using a switch widget (homegenie/generic/switch) instead. Then, you need to use the web service commands to handle any commands received from the switch widget.
Because I'm better at doing than explaining, I've attached a basic virtual switch example. Let me know if you have any questions about using it.
-
When I was testing, I changed the module type from a sensor to a switch and allowed my code to continue to trigger based off of the same logic. When I wanted to trigger an event that was a bit more complicated, I'd typically just write a simple script (Wizard or C#) that set the state of the module I was trying to simulate. I'm not sure if you are looking to add notification or something more complicated, but this approach should work.
-
Thank you for the follow ups. I used the web service script that CptJack submitted and it worked for me in a browser. But I got an "Array out of range" error when using my Android phone app. I'm not able to determine why the array error occurs.