Throwback
Posts: 2
Joined: Wed Nov 27, 2013 2:42 pm

Automation for Dawn.Dusk lighting on even numbered days

Wed Nov 27, 2013 2:50 pm

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.

User avatar
scruss
Posts: 3212
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

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

Wed Nov 27, 2013 5:00 pm

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
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

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

Wed Nov 27, 2013 5:25 pm

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
scruss
Posts: 3212
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

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

Wed Nov 27, 2013 6:30 pm

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”. ☺
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Throwback
Posts: 2
Joined: Wed Nov 27, 2013 2:42 pm

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

Wed Nov 27, 2013 11:44 pm

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.

snapster
Posts: 1
Joined: Thu Dec 05, 2013 7:05 pm

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

Thu Dec 05, 2013 9:46 pm

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

Return to “Automation, sensing and robotics”