HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: [email protected] on December 16, 2015, 10:43:22 PM

Title: Stupid question.. getting all modules and status?
Post by: [email protected] on December 16, 2015, 10:43:22 PM
I'm obviously doing something stupid..

I've extracted a snippet.. basically I want to get all modules, and then the status... I've tried:

Code: [Select]
{
  var modules = Modules.OfDeviceType("Light,Dimmer,Switch").SelectedModules;
  Program.Notify("",module.Address);
  Program.Notify("",module.Parameter("Status.Level").Statistics.History[0].Value);
}

and

Code: [Select]
for(int i = 0; i < modules.Count; i++)
{
 var module = modules[i];
  Program.Notify("",module.Address);
  Program.Notify("",module.Parameter("Status.Level").Statistics.History[0].Value);
}

Thanks
Title: Re: Stupid question.. getting all modules and status?
Post by: bkenobi on December 17, 2015, 04:26:51 PM
I would try using the same format as what's used in a lot of WhenModuleChanging code to toggle through all modules.  As for your snippet, I don't see why you are using the history[0] element since that's the same as the current value.
Code: [Select]
module.Parameter("Status.Level").Statistics.History[0].Valueshould evaluate the same as
Code: [Select]
module.Parameter("Status.Level").Value
Title: Re: Stupid question.. getting all modules and status?
Post by: [email protected] on December 18, 2015, 04:14:25 PM
Bit of a bad copy and paste error, I was trying all options and I was at the end of my....

doesn't the module changing pass the parameters as a seperate object?

I'm using the exact same code as a web method that does work, so dont know why I see the errors..
Title: Re: Stupid question.. getting all modules and status?
Post by: bkenobi on December 18, 2015, 05:06:33 PM
AFAIK, when you use the WhenModuleChanging function, it passes 2 objects (module, parameter).  And WhenModuleChanging can be triggered by more than one module at a time, so it's possible that you could need to parse more than one module (I suspect this would most likely occur when one triggers and another triggers before the first loop was finished.

The first object is a reference to the module which gives you access to everything connected to that module.  The second object is the parameter that changed IIRC.  I believe it would be something like
Code: [Select]
parameter.Name = "Status.Level"
parameter.Value = 1
for a module turning on but I could be remembering incorrectly.  Just look at one of the functions in any code (or the documentation) to see what the parameter value is being checked against.
Title: Re: Stupid question.. getting all modules and status?
Post by: mvdarend on December 18, 2015, 08:04:29 PM
You can use ModulesManager Each (http://genielabs.github.io/HomeGenie/api/ape/a00006.html#a0c9e7edc3d82a1ddd31e8abfa45e1e53) to iterate through all modules, eg.:

Code: [Select]
Modules.OfDeviceType("Light,Dimmer,Switch").Each( (module) => {
  Program.Notify(module.Instance.Name, module.Parameter("Status.Level").Value);
  Pause(1);
  return false;
});
Title: Re: Stupid question.. getting all modules and status?
Post by: [email protected] on December 20, 2015, 03:40:35 PM
Thanks :)