Submitted by: Jeff Hinrichs
Program Name: rise_set.pgm
Program Description: Monitor the Sunrise/Sunset and perform and action at each event.

Hardware required to implement Program:
1 - CPU-XA
1 - TW523 X-10 interface
2 - X-10 Controllable switching devices, i.e.. Lamp Module LM465

Discussion of Program:
I have a number of Motion Sensors that I use to automatically turn on
lights if activity is detected. Normally, I only want this to occur after
Sunset and before Sunrise. Here is the code I use to monitor these daily

The program uses 1 Variable (V0) and sets it to a value of 1 for Sunrise and
2 for Sunset. Lines 1-3 look for V0 to "become" equal to 1. It then
flashes an X-10 controlled light. The reader may feel free to implement a
more sophisticated event to control but for purposes of this demonstration
it will suffice. Lines 4-6 flash a second X-10 Controlled light when V0
becomes equal to 2.

*A note here: You must use Becomes = and not just plain equals (=)
otherwise the event code in lines 1-3 or 4-6 will occur more than once.

Lines 7-9 Check to see if the month is January and if the time is
equal to the time sunrise occurs. If this condition is met V0 is set to 1.
Lines 10-12 look for a similar event that will occur later in the day, Sunset,
and set V0 to 2. This block of code is repeated for the next 11 months with
the proper Sunrise/Sunset information for each month.

I use the Sunrise and Sunset times for the 15th of each month. While not
exact, it does serve its intended purpose.

You can find a listing of sunrise and sunset times for your area using
the "Compute Sunrise, Sunset & Twilight For Cities & Airports Worldwide With
Local TZ", resource located on the Internet at the following URL:

There are 2 caveats to remember. They are adjusting for Daylight Savings
Time (DST), if required for your area. The times given by the above
resource are adjusted to DST. In the program I have made notations in the comment
fields on the months that require you to reset your CPU-XA's clock.

Download the CPU/XA Program