Page 1 of 1

Automation for Dawn.Dusk lighting on even numbered days

Posted: Wed Nov 27, 2013 2:50 pm
by Throwback
I am a new user/beginner. I would appreciate direction on programming that would trigger a light from dawn to dusk on even numbered calendar days for a signal application. I can live with an LED only signal from one of the IO ports (3 v or 5 v) In a perfect world, I would want a program that would also trigger a dawn to dusk light (again LED would be fine) on odd number days to the alternate IO port so that for example I could have the 3 volt port trigger a green LED on even numbered days and the 5 volt port trigger a red led on the odd number days. I will be starting at the very beginning on this project. Any direction appreciated.

Re: Automation for Dawn.Dusk lighting on even numbered days

Posted: Wed Nov 27, 2013 5:00 pm
by scruss
Yes, you can do this. But we might need more help to get you to your solution.

First off, what do you mean by “even numbered days”?
  • the 2nd, 4th, 6th … 28th and 30th (except February) of every month?
  • by Julian day: January 2nd, 4th … 30th, then February 1st (Julian day 32), etc?
  • … or something else completely?
Raspbian includes cron, Unix's powerful but spectacularly confusing tool to execute scheduled commands. So if your Raspberry Pi's clock is set correctly, you can get cron to schedule things for you.

Secondly, by dawn to dusk, do you want:
  • exactly the local astronomical times of sunrise and sunset?
  • when a sensor tells you the sun has gone up or gone down?
Both are doable. The second one doesn't need much of a computer, but will need lots of trial and error selecting, placing and calibrating a light sensor. Quite importantly, this light sensor will need to be protected from the light you turn on at sunset — unless you like a continuously flashing light. Ask me how I know ☺

For local sunrise and sunset times, you need to know your latitude and longitude. From this, you can work out when the sun rises and sets, and the various civil definitions (dawn, twilight, dusk, etc) that arise from them. I use sunwait to handle all that difficult stuff. All it does is wait until the event you want, then exits. Doesn't sound like much, but if you trigger it very early in the morning (with cron), you can have it wait for dawn — and then the command specified after it on the cron command line will run.

I already use this setup to control a couple of lights around the house using X10. This is expensive and fiddly, but you don't need the hardware part.

A couple of links. Not particularly beginner-friendly, but none of them impossible to learn and understand how they work: cheers,
 Stewart

Re: Automation for Dawn.Dusk lighting on even numbered days

Posted: Wed Nov 27, 2013 5:25 pm
by DougieLawson
Pull a copy of Remind from http://www.roaringpenguin.com/products/remind
Tailor it to your local lat/long, configure,make & make install, and it will tell you sunrise/sunset times or civil twilight dawn/dusk times.

It can also tell you whether a day is even or odd numbered or a Hebrew sabbath, holiday or festival.

The remind programming language will let you run scripts on a schedule. I think it's easier and more flexible than the arcane runes we'd have to cast at cron.

Since we're running on Linux (not Apple or Microsoft - don't go there) we can even ask the author questions on
http://lists.roaringpenguin.com/cgi-bin ... emind-fans
Make sure you've read all 3700 lines of the man page before approaching that mailing list (or you could come away feeling like an Apple user).

There's also a web server CGI program.
Here's today's output.

Code: Select all

Sunrise in Basingstoke
Today is Wednesday, 27 November, 2013.

The local time in Basingstoke is 17:21.

Sunrise today was at 07:41; in other words, 9 hours and 40 minutes ago.

Sunrise tomorrow is at 07:43.

The daylight portion of tomorrow will be 3 minutes shorter than today.

Code: Select all

Sunset in Basingstoke
Today is Wednesday, 27 November, 2013.

The local time in Basingstoke is 17:21.

Sunset today was at 16:02; in other words, 1 hour and 19 minutes ago.

Sunset tomorrow is at 16:01.

The daylight portion of tomorrow will be 3 minutes shorter than today.

Re: Automation for Dawn.Dusk lighting on even numbered days

Posted: Wed Nov 27, 2013 6:30 pm
by scruss
DougieLawson wrote:… I think it's easier and more flexible than the arcane runes we'd have to cast at cron.
Hmm. It seems to be replacing one complex rule set with another equally complex (but different) one. cron has the advantages of already being installed under Raspbian, and being widely understood.

Note I said “understood”. I didn't say “liked”. ☺

Re: Automation for Dawn.Dusk lighting on even numbered days

Posted: Wed Nov 27, 2013 11:44 pm
by Throwback
First--thanks all. I am feeling my way and the quick and helpful responses are greatly appreciated. I am going to now take some time and work through all your thoughts and will repost. And of course, I meant dusk to dawn...As for even and odd numbered days, even would mean the 2nd, 4th, 6th, 8th, etc of every month. The odd days would be 1st, 3rd, etc. I need something that knows that November has 30, December 31 and so on. So I am looking for a green signal dusk to dawn on for example the 1st., 3rd, 5th, etc and a red signal on the 2nd, 4th, 6th. More reading to do on your posts and I will be back. Thanks.

Re: Automation for Dawn.Dusk lighting on even numbered days

Posted: Thu Dec 05, 2013 9:46 pm
by snapster
Have a look at suncron (http://stenarson.com/projects/suncron/)

It builds a cron file based on rules in a configuration file so you can have commands run at times relative to sunrise or sunset.

It's not too difficult to use if you understand cron scheduling and use the examples. Note the information in the bugs file as there is quite an important bug if for example you use a time sunset + 0:20 so you have to work around that.

Regards
Chris