- Posts: 4
- Thank you received: 1
/*
This code is running one time when program is enabled
*/
public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
// filter digital switch - change module address
if (m.Domain == Domains.MYSENSORS && m.Address == "N21S1" && p.Property == "Sensor.DigitalValue"){
DateTime t = DateTime.Now;
// filter when switch on event
if (p.Value == "1") {
t = t.AddMinutes(5);
Console.WriteLine("Starting 5 Minute Auto Off Timer");
while (DateTime.Now < t) {
Console.WriteLine("Sleeping 10 Seconds... {0} Minutes left", (t - DateTime.Now));
System.Threading.Thread.Sleep(10000); //Set an X Minute Delay
}
Console.WriteLine("Auto Off Entry Light");
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N21S1", "ControlOff", ""); //Entry Light
}
else {
t = DateTime.Now;
}
}
return true;
});
}
/*
This code is running periodically when program is enabled.
Cron job determine running period.
*/
public void Run()
{
}
Please Log in or Create an account to join the conversation.
Cory wrote: I wrote an automation program to automatically turn off a light after 5 minutes.
/* This code is running one time when program is enabled */ public void Setup() { EventHelper.ModuleChangedHandler((o, m, p) => { // filter digital switch - change module address if (m.Domain == Domains.MYSENSORS && m.Address == "N21S1" && p.Property == "Sensor.DigitalValue"){ DateTime t = DateTime.Now; // filter when switch on event if (p.Value == "1") { t = t.AddMinutes(5); Console.WriteLine("Starting 5 Minute Auto Off Timer"); while (DateTime.Now < t) { Console.WriteLine("Sleeping 10 Seconds... {0} Minutes left", (t - DateTime.Now)); System.Threading.Thread.Sleep(10000); //Set an X Minute Delay } Console.WriteLine("Auto Off Entry Light"); DriverHelper.ProcessCommad(Domains.MYSENSORS, "N21S1", "ControlOff", ""); //Entry Light } else { t = DateTime.Now; } } return true; }); } /* This code is running periodically when program is enabled. Cron job determine running period. */ public void Run() { }
I found that sleeping the thread for 5 minutes did not provide a very reliable automation. Has anyone else done an auto-off automation that works reliably?
Please Log in or Create an account to join the conversation.