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:
Program.Run();
Program Code:
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:
//Program.Notify("front door sensor", parameter.Name); Pause(1);
//Program.Notify("front door sensor", parameter.Value); Pause(1);