Ninja Blocks Forum

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google

In this Discussion

Top Posters

Most Helpful Ninjas

Sunset timings for lighting
  • 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. 
  • jh71283jh71283
    Ninja, Shinobi
    Have a look at the TimeOfDay driver by @NinjaChris

    Might help you out!
  • 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.
  • jh71283jh71283
    Ninja, Shinobi
    I'm sure chris will be happy to accept a pull request ... ;-)
  • NinjaChrisNinjaChris
    Administrator, Ninja, Sensei (Ninja Blocks Inc), Shinobi
    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

    @jh71283 always 


  • 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.
  • NinjaChrisNinjaChris
    Administrator, Ninja, Sensei (Ninja Blocks Inc), Shinobi
    Captainniffy,

    I am using the SunCalc node package so it is absolutely feasible

    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

  • NinjaChrisNinjaChris
    Administrator, Ninja, Sensei (Ninja Blocks Inc), Shinobi
    Guys,

    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

    Chris
  • 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.
  • "CaptainNiffy"?  Well, that's going to make me reconsider my handle. I hadn't thought of it that way. No offence taken.
  • NinjaChrisNinjaChris
    Administrator, Ninja, Sensei (Ninja Blocks Inc), Shinobi
    :-) i apologise 
  • Check the standard Linux utility - "remind". It can trigger events based on sunset/sunrise times for a predefined geo location.
  • ninja_timeofday 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.
  • I found a couple of issues in ninja_timeofday and I've sent Chris a pull request here: https://github.com/chrisn-au/ninja_timeofday/pull/2
    • 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.

  • NinjaChrisNinjaChris
    Administrator, Ninja, Sensei (Ninja Blocks Inc), Shinobi
    @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. - 
  • NinjaChrisNinjaChris
    Administrator, Ninja, Sensei (Ninja Blocks Inc), Shinobi
    Driver updated to create default values and to solve some unix/dos eol issues - thanks @carlossg
  • Hey guys,

    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. :-)

    You can find it at https://github.com/DerPeit/ninja-dusk-till-dawn if you like to try it. I didn't test the usual ninja installation routine. I just cloned it to the drivers directory and installed the node.js dependencies.

    Manuel