more G-Labs products

Author Topic: Newbie scripting question  (Read 1092 times)

May 07, 2015, 01:06:58 AM
Read 1092 times

monkeyangst

  • *
  • Information
  • Newbie
  • Posts: 6
Hi everyone! I'm a complete newcomer to home automation and HomeGenie and I do not speak C#. After a few days of struggling, though, I think I wouldn't be able to do what I need just with the Wizard, so I'm trying to make heads or tails of what I'm seeing in the included C# scripts.

Let's start with the basics. I have a Z-Wave switch (controlling my porch light), which I have added as a module and I can control that to my heart's content. I've scheduled it, too, so it goes on at sunset. So far so good. But what I want to do is use my MultiSensor, so that if the porch light is not already on, and the sensor detects motion, it turns the light on and then, after a minute, off again. I have figured out how to script the action part of that. No problem. But I can't figure out what to put in the Trigger part, i.e. how to tell it to fire on motion. Can anyone help me out?

May 07, 2015, 01:40:45 AM
Reply #1

monkeyangst

  • *
  • Information
  • Newbie
  • Posts: 6
Aha! Just discovered that the options under "Features and Options" for the switch module are cumulative, not either-or. So I can have it both on a schedule and be a "Smart Light" and go off automatically after a minute!

I'm still very curious about scripting though, so I'll still be exploring making programs if anyone still wants to point me in the right direction.

May 07, 2015, 05:05:32 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
There are 3 scripts for motion controlled lights that are available right now.

1) Smart Lights - This is built in to HG and works for controlling a light based on a motion sensor and a light level sensor.

2) Advanced Smart Lights - I wrote this script to meet my needs.  It requires a light or siren for the controlled device, one or more motion sensors, and optionally a transmitting switch or other controller that can be used to override the motion sensor.  This is a much more complex code so if you are new to coding and it doesn't do exactly what you want, you may want to try it but use something else.
http://www.homegenie.it/forum/index.php?topic=241.0

3) Smart Light (update) - This is an updated version of the built in script that nolio submitted.  I've never tried this code, but based on the documentation in the thread it looks like it's very similar to the built in version with some tweaks to meet the author's needs, so you could try this or the first almost interchangeably.
http://www.homegenie.it/forum/index.php?topic=845.0

May 07, 2015, 06:46:44 PM
Reply #3

monkeyangst

  • *
  • Information
  • Newbie
  • Posts: 6
Thanks, bkenobi. I'm trying to suss out exactly what these things do.

Here's what I've been able to determine: The original Smart Lights script, and the one you mention as #3, add some fields to the module's settings -- like, now you can select "Smart Lights" and fill in a few fields. OK, got that. Not *quite* clear on whether your script does the same kind of thing, or instead is intended to be used in other scripts.

May 07, 2015, 08:09:36 PM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
All of these scripts will add a menu item in the module configuration window (the drop down you found).  You then fill out the text boxes and whatnot to configure things as you need.  Do not enable more than one as they will probably fight each other and cause unknown results. 

My script will work very similar to Gene's built in code if configured very basic.  The primary difference between mine and Gene's is that he uses a light sensor to control day/night activity while mine uses one of the weather widgets to determine sunset/sunrise based on latitude/longitude.  I don't have a light sensor, so I had to go a different route.  If you do have a light sensor, using it is probably better since cloud cover can dramatically affect the time of perceived sunset/sunrise and even so much that during day time you might actually want the lights to come on.

Beyond the basic "turn light on if motion and night" that all of these scripts do, I have added other capabilities to match my specific needs.  If you review the thread for my script, I've detailed all of what it does.  It should be pretty self explanatory, but you can use portions of my code but not all of it based on how you configure modules.