more G-Labs products

Author Topic: Event Times based on sunrise or sunset  (Read 920 times)

November 03, 2015, 03:05:41 AM
Read 920 times

RedMD

  • *
  • Information
  • Newbie
  • Posts: 1
I wanted to have certain lights in my house turn off, or on, based on wunderground events (i.e. sunrise or sunset) but not at sunrise or sunset.  I wanted to have my lights turn off 2 hours after sunrise and turn on an hour prior to sunset.  To do this I explored a number of options (including creating a new C# class), but sometimes the simplest solution is the best solution. So here's how I accomplished my goal:

Added 2 new variables to the top of the Weather Underground program (34)

var sunriseDelayEvent = "SunriseDelay";
var DELAY = 2; //delay in hours after sunrise event/time for SunriseDelay event to be set


and then add this section later in the file (~ line 41 and 43)

Scheduler
        .WithName(sunriseDelayEvent)
        .SetSchedule(String.Format("{0} {1} * * *", sunrise_minute, sunrise_hour + DELAY));


After compiling, this created a new event w/ a correct cron expression in the scheduler tab.  This event can then be referenced using the @SunriseDelay notation.
 
« Last Edit: November 03, 2015, 03:07:28 AM by RedMD »

November 03, 2015, 04:15:15 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
This approach has also been used with the jkUtils sun calculator.  If you wanted to make it even a bit more clever, you could create a feature/option and assign the value in the interface.  This would allow for changes without a recompile.  Thanks for the post!