HomeGenie Forum

General Category => Troubleshooting and Support => Topic started by: Acorlin on November 10, 2015, 12:23:43 AM

Title: Help programing a switch to toggle "IF" after sunset a door sensor is tripped
Post by: Acorlin on November 10, 2015, 12:23:43 AM
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
Title: Re: Help programing a switch to toggle "IF" after sunset a door sensor is tripped
Post by: mvdarend on November 10, 2015, 07:15:50 AM
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);
Title: Re: Help programing a switch to toggle "IF" after sunset a door sensor is tripped
Post by: bkenobi on November 10, 2015, 02:28:00 PM
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)
Title: Re: Help programing a switch to toggle "IF" after sunset a door sensor is tripped
Post by: Acorlin on November 10, 2015, 08:45:29 PM
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
Title: Re: Help programing a switch to toggle "IF" after sunset a door sensor is tripped
Post by: bkenobi on November 10, 2015, 11:08:45 PM
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".