more G-Labs products

Author Topic: Movement sensor notifier  (Read 989 times)

May 06, 2015, 03:17:41 PM
Read 989 times

Michel

  • **
  • Information
  • Jr. Member
  • Posts: 42
Hello everyone,

I have a motion detector in the backyard and I would like to use a lamp in the living room as a movement notifier. This lamp is usually dimmed to 50%, so, what I want to do is to bright it to 100% when a movement is detected, pause 1 second and return it to the previous level.

The code below sometimes works, sometimes does not. As I'm pretty new to HG and C#, there should be a better way to do it.

Thanks

---------------------------------
var lamp = Modules.WithName("Test Lamp");
var level = lamp.Level;

if (lamp.IsOn)
{
  lamp.Level = 100;
  Pause(1);
  lamp.Level = level;
}
// if lamp is off, do nothing
---------------------------------

May 06, 2015, 08:37:12 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That looks pretty good for the functional code.  You'd need to wrap that in a function that detects the motion sensor triggering.  I use the following:
Code: [Select]
When.ModuleParameterChanged((module, parameter)=>
...

May 07, 2015, 12:39:58 AM
Reply #2

monkeyangst

  • *
  • Information
  • Newbie
  • Posts: 6
Sweet. I just joined this forum, as I am dipping my toe into HA for the first time and trying out HomeGenie... I'm trying to figure out how to trigger events with my motion sensor as well, so I'd like to ask benkenobi to elaborate a bit more if you could, please...

May 07, 2015, 12:56:02 AM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Your best bet it so start by looking at the code that comes with HG.  Under Configure->Automation there's quite a few modules that do a variety of tasks.  If you want to know about motion sensing I'd recommend the Smart Lights code.  There are also a number of contributions on this forum that are in C#, JS, etc that might also be useful.  I've contributed several scripts under the Advanced Smart Lights thread that might be of use.