hey, it’s the sun … heyu and sunwait and cron on the Raspberry Pi

Yep, springtime’s coming, and today’s the first day I know it, despite the -5.8°C outside. I know spring is coming because my sunrise-adjusted lights came on before my alarm today. I’m controlling them with a Raspberry Pi, cron, and X10.

I’d described how to build and use heyu previously, so I won’t go into it further. I use sunwait to control the timing relative to local sunrise and sunset. Sunwait is a simple C program which builds quickly, and you can put the executable somewhere in your path.

(NB: newer versions of sunwait use a completely incompatible command line format. Everything here refers to the 2004 version I linked to above, which does exactly what I need in the way it’s described here.)

You need to know your latitude and longitude to use sunwait. To check its setting for the day, you can call it with the -p option:

$ sunwait -p 43.729N 79.292W
Using location:             43.729000N, 79.292000W
Date:                        6 Feb 2013 
Local time:                  7:44 
Day length:                 10:13 hours
With civil twilight         11:10 hours
With nautical twilight      12:18 hours
With astronomical twilight  13:25 hours
Length of twilight:  civil   0:28 hours
                  nautical   1:02 hours
              astronomical   1:35 hours
Current specified time zone: EST (-5 from UTC) 
Sun transits meridian 1231 EST
                   Sun rises 0726 EST, sets 1736 EST
       Civil twilight starts 0656 EST, ends 1806 EST
    Nautical twilight starts 0622 EST, ends 1840 EST
Astronomical twilight starts 0548 EST, ends 1913 EST

So for me, today’s sunrise is at 0726, and sunset is at 1736. All sunwait does is wait until a specific solar time is reached, and then exit. Whatever command you call after sunwait, therefore, is what gets run at the right time. So if I wanted X10 device H1 to come on an hour before sunrise, I’d run:

sunwait sun up -1:00:00 43.729N 79.292W; heyu on h1

Remembering to run this every day before sunrise would be a pain, so this is where cron helps. cron uses a slightly odd config file that is edited using the crontab -e command. Here’s the relevant bit of my crontab, showing the light control times:

# m h  dom mon dow   command
 01 00   *   *   *   /usr/local/bin/sunwait sun up -1:00:00 43.729N 79.292W; /usr/local/bin/heyu on h1
 02 00   *   *   *   /usr/local/bin/sunwait sun up +1:00:00 43.729N 79.292W; /usr/local/bin/heyu off h1
 03 00   *   *   *   /usr/local/bin/sunwait sun down -1:00:00 43.729N 79.292W; /usr/local/bin/heyu on h1
 45 22   *   *   *   /usr/local/bin/heyu off h1

(you can view your crontab with crontab -l)

The columns in crontab are:

  • minute
  • hour
  • day of month
  • month
  • day of week
  • command

So the four crontab lines mean:

  1. Every day at 00:01, wait until an hour before sunrise and turn light H1 on
  2. Every day at 00:02, wait until an hour after sunrise and turn light H1 off
  3. Every day at 00:03, wait until an hour before sunset and turn light H1 on
  4. At 22:45, turn light H1 off.

So for quite a bit of the day, there are a couple of sunwait tasks just quietly waiting until sunrise or sunset to do their thing. cron, incidentally, is picky about executable paths; that’s why I specified full paths to both sunwait and heyu.

What I’d really like to do is have time on this machine update without a network connection, because it’s running from a particularly messy router set up in a spare bedroom. I should investigate a real-time clock, with GPS time updates from an I²C GPS, talking through a bluetooth console. In my copious free time, of course.

geese! geese! geese!

Because I saw geese flying north today, and because of the rim, it is officially spring in Scarborough. (The ~20cm of snow is merely an anomaly).

go jump over the fire!

Happy Norooz!

Norooz, Persian New Year
Year of 2566 (1386)

In harmony with rebirth of nature, the Persian New Year Celebration, or Norooz, always begins on the first day of spring, March 20th of each year. Norooz ceremonies are symbolic representations of two ancient concepts – the End and Rebirth. About 3000 years ago Persian’s major religion was Zoroastrianism, named in honor of its founder Zoroaster, and arguably the world’s first monotheistic religion. Zoroastrians had a festival called “Farvardgan” which lasted ten days, and took place at the end of the solar year. It appears that this was a festival of sorrow and mourning , signifying the end of life while the festival of Norooz, at the beginning of spring signified rebirth, and was a time of great joy and celebration. Norooz was officially acknowledged and named “Norooz” by mythical Persian emperor, Shah Jamshid, from Achaemenid Dynasty (500 BC). Ashaemenied created the first major empire in the region and built Persepolis complex (Takhte Jamshid) in the city of Shiraz. Norooz in Persian means “New Day” and brings hope, peace and prosperity to the world and has been celebrated among people regardless of ethnic background, political views or religion in many countries around the globe such as Iran, Afghanistan, Azerbaijan, Turkey, Uzbekistan, Pakistan, Georgia, Iraq, Tajikistan, Syria, Armenia and India. Some of the activities during Norooz are Spring cleaning, buying new clothes, painting eggs, family reunion, giving presents, visiting neighbors and friends and celebrating by having a picnic on the 13th day of Spring. Happy Norooz!

in the running

Almost ‘Best of The Year’ time. In the running are:

A Hawk and a Hacksaw – The Way the Wind Blows
A.C. Newman – Souvenir of Canada – EP
Beck – The Information
Calexico – Garden Ruin
Casper & the Cookies – The Optimist’s Club
Colin Meloy – Colin Meloy Sings Shirley Collins
Eels with Strings – Live At Town Hall
Elf Power – Back To The Web
Erynn Marshall – Calico
Faun Fables – The Transit Rider
Grandaddy – Just Like The Fambly Cat
Grant-Lee Phillips – nineteeneighties
Hidden Cameras – Awoo
Joanna Newsom – Ys
Jolie Holland – Springtime Can Kill You
King Biscuit Time – Black Gold
Mayor McCa – Cue Are Es Tea You
Peter Stampfel – The Jig Is Up
Robyn Hitchcock & The Venus 3 РOl̩! Tarantula
Sufjan Stevens – Songs For Christmas – Volume V: Peace
Sufjan Stevens – The Avalanche – Outtakes And Extras From The Illinois Album
The Be Good Tanyas – Hello Love
The Decemberists – The Crane Wife
The Essex Green – Cannibal Sea
The Flaming Lips – At War With The Mystics
The Handsome Family – Last Days of Wonder
The Instruments – Cast A Half Shadow
The Sadies – In Concert Vol. 1
The Wailin’ Jennys – Firecracker
Thom Yorke – The Eraser
Thomas Dolby – The Sole Inhabitant
Wendy Arrowsmith – Crying Out
Yo La Tengo – I Am Not Afraid Of You And I Will Beat Your Ass

Miraculously, all of them fit on my iPod Nano, so they’ll be in heavy rotation over the next week or so while I decide.

a tiny stub-tailed birdlet

Our tree is filled with Ruby-crowned Kinglets, and the title is Peterson’s poetic description of them. I guess they’re feeding up to migrate a bit south. Give news of yourselves when you bring spring back with you!

timwin

Don’t want no car, don’t need no barbecue… But I can always use another coffee from Tim Hortons.

(for those outside Canada, every spring, the Tim Hortons donut chain has a prize promotion. It always provokes a national response little short of hysteria. You can win big things, but winning a coffee is just dandy by me.)