more G-Labs products

Author Topic: Control device based on others trigger (using FGS221)  (Read 2000 times)

August 03, 2014, 11:36:17 PM
Read 2000 times

nunofx

  • *
  • Information
  • Newbie
  • Posts: 18
Hi,

I've a FGS221 where one relay is connected to a light and the other to a fan. I want to turn off the fan 30m after turn off the light.

I did some code but is not working because virtual module is not getting caught on the event change.

Code: [Select]
When.ModuleParameterChanged( (module, parameter) =>
{
if (module.Is("WC Fan") && parameter.Is("Status.Level"))
       {
        if (module.Is("WC Fan") && parameter.Is("Status.IsOn"))
            {
                Pause(1800);
                Modules.WithName("WC Fan").Off();
      return false;
            }       
        }
return true;
});

However module.Is("WC Fan") never returns true but if I use another node that is not virtual, everything works.

Thanks + BRegards,
Nuno

August 04, 2014, 03:05:52 AM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
It looks like that should work.  You should consider that using that approach locks your code for 30 minutes though.  You might consider using a timer function instead.  Gene has some examples if you need one (i.e., Smart Lights).  If the pause was shorter (less than a 2-3 minutes), I'd probably just use the pause statement but with a longer hold time it might cause issues.

August 04, 2014, 03:54:40 PM
Reply #2

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Why not using a simple wizard script?

g.

August 04, 2014, 11:51:22 PM
Reply #3

nunofx

  • *
  • Information
  • Newbie
  • Posts: 18
Why not using a simple wizard script?

g.

How can I "code" event change trigger using wizard? Can you give me an example?

Are you referring to something like the image?

Btw, the "condition switches to true" only executes the code on the transition from on to off and not during all the time while the light is off, right?

Thanks.
« Last Edit: August 05, 2014, 12:03:31 AM by nunofx »

August 31, 2014, 07:24:20 PM
Reply #4

nunofx

  • *
  • Information
  • Newbie
  • Posts: 18
Why not using a simple wizard script?

g.

How can I "code" event change trigger using wizard? Can you give me an example?

Are you referring to something like the image?

Btw, the "condition switches to true" only executes the code on the transition from on to off and not during all the time while the light is off, right?

Thanks.

I tested the image's code but if during the count-down I turn on the light and then off, the old timer persists and I want to reset it on this condition. I think only some C# code could solve my problem.