Giter VIP home page Giter VIP logo

sun's Introduction

About

Simple public domain library and application that shows sunset and sunrise based on your latitude,longitude. The application can also be used with cron to run a script, see section Goal below.

The library, which can be used entirely stand-alone, is based on the excellent code by Paul Schlyter.

Example

Without any arguments the sun goes dumpster diving in system files /etc/timezone and /usr/share/zoneinfo/zone.tab to figure out your latitude and longitude.

On my system, in mid December here in Sweden, the result is:

$ cat /etc/timezone
Europe/Stockholm
$ sun
Sun rises 07:31, sets 13:49 UTC

You can set the environment variable TZ to check other locations:

$ TZ="Africa/Luanda" sun
Sun rises 04:42, sets 17:18 UTC

For more precision, you can of course provide your exact latitude and longitude. See the built-in usage text for more help: sun -h

Cron

To launch applications at sunrise/sunset using cron, simply:

$ crontab -e
01 00 * * * sun -r -w -o -30m; play english.au

This plays Linus Torvalds' classic audio file 30 minutes before sunrise.

NOTE: You may want to set the $PATH in your crontab, or use an absolute path to your programs, otherwise cron will not find them.

Usage

Usage:
  sun [-ahirsw] [-o OFFSET] [+/-latitude +/-longitude]

Options:
  -a      Show all relevant times and exit
  -l      Increased verbosity, enable log messages
  -h      This help text
  -i      Interactive mode
  -r      Sunrise mode
  -s      Sunset mode
  -u      Use UTC everywhere, not local time
  -v      Show program version and exit
  -w      Wait until sunset or sunrise
  -o ARG  Time offset to adjust wait, e.g. -o -30m
          maximum allowed offset: +/- 6h

Bug report address: https://github.com/troglobit/sun/issues

Goal

The goal of this project is to provide just enough intelligence to my home automation system so it can control the indoor lights, which are operated using 433 MHz outlet switches.

Building

The sun is built with the GNU configure and build system. Simply run the following commands to build and install:

$ ./configure
$ make
$ sudo make install

The sunriset.c code can be built as a library, use --enable-library with the configure script to enable this optional feature.

If you built from GIT, or have modified any of the .ac or .am files, you have to run the following to (re-)create the configure script:

.$ /autogen.sh

For that to work you need to have autoconf, automake, and libtool installed. These tools are not needed when building from an official released tarball.

sun's People

Contributors

darshan-shah-git avatar troglobit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sun's Issues

Minutes are not correctly calculated as per timezone

Hi,
In convert() function of sunrise.c file, difference is not correctly added.
As example, if my timezone is +5:30, then current logic is only adding +5 Hr only. We need to add logic to add correct minutes details.
Updated Code:

static void convert(double ut, int *h, int *m)
{
   *h = (int)floor(ut);
   *m = (int)(60 * (ut - floor(ut)));

   *m += (timediff() % 3600)/60;
   *h += timediff() / 3600;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.