more G-Labs products

Author Topic: Help programing a switch to toggle "IF" after sunset a door sensor is tripped  (Read 1371 times)

November 10, 2015, 12:23:43 AM
Read 1371 times

Acorlin

  • **
  • Information
  • Jr. Member
  • Posts: 44
I have a need to turn on a Z-wave light switch ONLY after sunset when a Z-wave door sensor is tripped. I am not a programmer and am running Windows 10.

If someone could point me in the correct direction I would appreciate it.
Thank you.
Alan
« Last Edit: November 10, 2015, 12:44:59 AM by Acorlin »

November 10, 2015, 07:15:50 AM
Reply #1

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Here is a C# example: (untested, but you should get the idea)

I'm using jkUtils.SolarAltitude for the times. The Motion sensor is called 'front door sensor' and the light is called 'Front door light'. Any motion detected between Sunset and Sunrise will cause the light to switch on, and then switch off again after 30 seconds.

Startup Code:
Code: [Select]
Program.Run();
Program Code:
Code: [Select]
When.ModuleParameterChanged( (module, parameter) =>
        {                             
          if (module.Is("Front door sensor"))
          {   
            //Program.Notify("front door sensor", parameter.Name); Pause(1);
            //Program.Notify("front door sensor", parameter.Value); Pause(1);
            if(parameter.Name == "Sensor.MotionDetect" && parameter.Value == "1")
            {     
              //Program.Notify("Sensor.MotionDetect", "Sensor.MotionDetect");
             
              // Get the times
              DateTime EveningSunsetEnd = DateTime.Parse(solarAltitude.Parameter("jkUtils.SolarAltitude.Evening.Sunset.End").Value);
              DateTime MorningSunriseStart = DateTime.Parse(solarAltitude.Parameter("jkUtils.SolarAltitude.Morning.Sunrise.Start").Value);
             
              DateTime currentTime = DateTime.Now;
             
              if (currentTime >= EveningSunsetEnd && currentTime <= MorningSunriseStart)
              {
         Modules.WithName("Front door light").On();
         Pause(30);
         Modules.WithName("Front door light").Off();
              }
              return false;
            }
          }
          return true;
        });

If your're using a different type of sensor, just uncomment these two lines to get the paremeter name and value the sensor is giving:
Code: [Select]
            //Program.Notify("front door sensor", parameter.Name); Pause(1);
            //Program.Notify("front door sensor", parameter.Value); Pause(1);
« Last Edit: November 10, 2015, 07:18:36 AM by mvdarend »

November 10, 2015, 02:28:00 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
This code should work as long as your motio n sensor sets the Sensor.MotionDetect parameter.  For X10, you should check Sensor.StatusLevel==1 (or greater than 0)

November 10, 2015, 08:45:29 PM
Reply #3

Acorlin

  • **
  • Information
  • Jr. Member
  • Posts: 44
The last programming I had was in the early 70's---Fortran.

Where do I compile the C program for use in a Windows 10 OS?

Thank you both for the help.
Alan

November 10, 2015, 11:08:45 PM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Log on to your HG web interface.  Select Configure from the upper left and Programs.  Add a program to either an existing or new group.  Edit that program and change the language to C#.  Paste the code in the two code tabs and select the compile button from the left side banner.  Assuming everything works, it will say "save complete".