captainiffy — 2013-10-17T08:11:53-04:00 — #1
I've been working on controlling the lamps at home using an arduino and my PC. It's sort of working fine, but I wanted to use a Raspberry Pi or (lately) a BeagleBoneBlack to control the arduino, so my PC doesn't have to be "on" all the time. The arduino is great for controlling a 433MHz transceiver as micro-second timings should not be disturbed. The computers do the scheduling and web interface. (I did like it when I used my Kindle to control the wife's bedside light - she's not such a sceptic of my hobby now...)
I've found that I wanted my lights to turn "on" just before dusk, so I've forked Sunwait (now "Sunwait for Windows") on souceforge. 250 downloads but no feedback (is it rubbish, or is it what?). The arduino code is also on sourceforge "smjremote".
What's interesting, is that a custom twilight angle is required. You can't just go with a fixed time offset from a standard twilight angle, as the offset required changes throughout the year. I even have a different twilight angle for lights on the north or south side of the house. North gets darker, earlier.
I've more work to do, as I want a light sensor to operate during daylight hours (between my twitlight). At night, I don't want the light sensor to fire, no matter how much the kids shine a torch at it.
Hopefully, when mine arrives, I'll be able to port to a NinjaBlock. I've tried using a Pi, but I'm finding the Pi fails after 4-6 months (power cuts being chief suspect, but there's some talk of a voltage interaction with SD card and the ethernet port).
The big reward is that the lights come on before it gets gloomy. Another, rather curious benefit, is that having the lights come on steadily earlier as we go into winter seems to remind me of the season.
jh71283 — 2013-10-17T09:29:59-04:00 — #2
Have a look at the TimeOfDay driver by @NinjaChris
Might help you out!
mike_biddell — 2013-10-17T09:46:24-04:00 — #3
Just tried that.... it works wonderfully well. Only criticism, is that dusk is quite dark. Driver would benefit from a variable to define time before dusk e.g. 0.25, 0.5 , 1 hour etc.
jh71283 — 2013-10-17T09:55:13-04:00 — #4
I'm sure chris will be happy to accept a pull request ...
ninjachris — 2013-10-17T15:55:03-04:00 — #5
Guys, still a work in progress
@CaptainIffy have a look at https://github.com/chrisn-au/ninja_timeofday
@mike_biddell - Absolutely agree - am looking at it now
captainiffy — 2013-10-18T09:24:08-04:00 — #6
That's so what I want. But I'm sure you'll need to consider user defined twilight angles. Mike Biddell makes the point, but a timed offset doesn't cut it. In the winter here, the sun skids along the horizon - while in the summer the sun plunges through the last few degrees more perpendicularly (is that a word?). Here in the Northern Hemisphere, I like a 5 degree above the horizon twilight angle on the south facing rooms; and a 7 degree angle in the northern rooms; when my lights go "on".
I tried timed offsets at first - I got moaned at, by the wife, for the lights being "on" too early (summer), to being too gloomy before they came "on" in the winter. I think the sun sort of moves constantly along it's trajectory rather than the simple angle seen between sun and horizon - unless you're at the equator. But it is the simple angle relative to the horizon that determines light levels. Imagine life at the poles: if the sun does not get high enough over the horizon on polar-days, it's just too gloomy and you'll need the lights to stay "on".
What really fuddles the brain is that the sun is actually well below the horizon when we watch it set. A trick of the atmosphere.
ninjachris — 2013-10-19T13:53:39-04:00 — #7
SunCalc.addTime(/*Number*/ angleInDegrees, /*String*/ morningName, /*String*/ eveningName)
My intention is that I will allow multiple locations (one state device for each location) and ability to define both a time offset and angle. This should allow "I like a 5 degree above the horizon twilight angle on the south facing rooms; and a 7 degree angle in the northern rooms; when my lights go "on"."
let me know what you think
ninjachris — 2013-10-20T01:49:58-04:00 — #8
I have done some work and have a test program. It can be downloaded from https://github.com/chrisn-au/ninja_timeofday
The test program test.js allows you replicates the driver but has no cloud capabilities. It can be used to identify the correct config for your setup. It has the capability to define offsets from sunlight phases and define new phases based on sun position above horizon
It uses the suncalc package https://github.com/mourner/suncalc (many thanks mourner) and you will need to use the phases defined in the suncalc package
Will develop documentation and update driver over the next few days but please feel free to ping me
captainiffy — 2013-10-21T04:56:32-04:00 — #9
I've remembered the full 'gotcha' with my bedside light. It comes on at 7:30am and goes out at 8:30am. When dawn gets earlier, the light goes out earlier (say at 8am, using a dawn schedule). But the trick is that when dawn arrives prior to 7:30, the light resumes to being on at 7:30 to 8:30. Also, twice a year, the light has a very silly short 'on' time, 7:30 to 7:33 say. I'm not sure if it should stay on for longer, or should not have come on at all. I think if I had a daylight sensor, I would not want "on" lasting less than a couple of minutes.
captainiffy — 2013-10-21T05:07:27-04:00 — #10
"CaptainNiffy"? Well, that's going to make me reconsider my handle. I hadn't thought of it that way. No offence taken.
ninjachris — 2013-10-21T22:56:06-04:00 — #11
sim — 2013-10-29T00:47:18-04:00 — #12
Check the standard Linux utility - "remind". It can trigger events based on sunset/sunrise times for a predefined geo location.
keenanj — 2013-12-30T03:33:28-05:00 — #13
ninjatimeofday does not work well for me sometimes there is no state or the state is wrong I say it fires off about %40 of the time.
right now for example it is 8:37 am and the state is night.
when it works the timing are right on as far as sunset and sunrise.
danny — 2014-01-09T23:12:18-05:00 — #14
- the daily recalc wasn't happening
- some times returned by SunCalc were in the past so weren't getting scheduled
- I've added some logging which will appear in /var/log/ninjablock.log and hopefully help people diagnose future issues.
ninjachris — 2014-01-10T22:26:30-05:00 — #15
@danny many thanks - Pull request accepted.
For those that have the driver I suggest that you update it.
The significant missing capability is configuration through the UI.
Again many thanks to Danny. -
ninjachris — 2014-01-27T16:27:44-05:00 — #16
Driver updated to create default values and to solve some unix/dos eol issues - thanks @carlossg
derpeit — 2014-02-25T12:52:06-05:00 — #17
I've been developing a suncalc based driver by myself and decided to publish my current development to github. I called it Dusk 'Till Dawn and it supports multiple locations at a time and a gui configuration. It then sends notifications to the ninja cloud for night, several twilight, golden hours, sunrise and sunset events each location.
It still lacks unit tests and has by now only be smoke tested on RPi by myself but it works as far as I can tell, at least for Germany.