Code Monkey home page Code Monkey logo

heliocron's Introduction

heliocron

crates.io crates.io Build Status

A simple command line application that integrates with cron to execute tasks relative to sunset, sunrise and other such solar events.

Table of Contents

Installation

There are several ways to install heliocron on your device.

1. Pre-compiled binaries

You can download a pre-compiled binary from the releases page.

Here's a quick compatibility table to help choose the correct binary to download:

Platform Binary
Raspberry Pi 0/1 heliocron-v0.8.1-arm-unknown-linux-gnueabihf.tar.gz
Raspberry Pi 2/3/4 heliocron-v0.8.1-armv7-unknown-linux-gnueabihf.tar.gz
Linux with a 64bit CPU heliocron-v0.8.1-x86_64-unknown-linux-gnu.tar.gz

2. Install with cargo

# make sure you've got an up to date version of rust and cargo installed
# full instructions can be found at https://www.rust-lang.org/tools/install
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
.
.
# then install using cargo
$ cargo install heliocron
.
.
$ heliocron --version
heliocron 0.8.1

3. Build from source

$ git clone https://github.com/mfreeborn/heliocron
$ cd heliocron
$ cargo build --release
$ ./target/release/heliocron --version
heliocron 0.8.1

Usage Examples

Delay execution of a command relative to sunrise or sunset

The following code snippet entered into the terminal will wait until sunset on 25th Feb 2020 at the Royal Greenwich Observatory (17:32:17 +00:00) before listing the files and folders contained within the user's home directory.

$ heliocron --date 2020-02-25 --latitude 51.4769 --longitude -0.0005 \
wait --event sunset && ls ~
Thread going to sleep for _ seconds until 2020-02-25 17:32:17 +00:00. Press ctrl+C to cancel.

Integration with cron for recurring tasks is easy. The following snippet shows a crontab entry which will run every morning at 2am. heliocron will wait until 30 minutes before sunrise, before allowing the execution of the turn-on-lights.sh script.

0 2 * * * heliocron --latitude 51.4769 --longitude -0.0005 wait --event sunrise --offset -00:30 \
&& turn-on-lights.sh

Show a report of sunrise and sunset times for a given location and date

$ heliocron -d 2065-05-07 -l 55.9533 -o -3.1883 report
LOCATION
--------
Latitude:  55.9533
Longitude: -3.1883

DATE
----
2065-05-07 12:00:00 +01:00

Solar noon is at:         2065-05-07 13:09:19 +01:00
The day length is:        15h 49m 51s

Sunrise is at:            2065-05-07 05:14:24 +01:00
Sunset is at:             2065-05-07 21:04:15 +01:00

Civil dawn is at:         2065-05-07 04:27:31 +01:00
Civil dusk is at:         2065-05-07 21:51:08 +01:00

Nautical dawn is at:      2065-05-07 03:19:56 +01:00
Nautical dusk is at:      2065-05-07 22:58:43 +01:00

Astronomical dawn is at:  Never
Astronomical dusk is at:  Never

Display real time data pertaining to the current position of the Sun

Use the poll subcommand to see what the Sun is doing right now:

$ heliocron -l 51.4769 -o -0.0005 poll
LOCATION
--------
Latitude:  51.4769
Longitude: -0.0005

DATE
----
2022-08-01 05:21:38 +01:00
Civil Twilight

Solar elevation: -0.805°
Azimuth angle:   58.592°

The same set of data can be output in machine-readable JSON format.

$ heliocron -l 51.4769 -o -0.0005 poll --json
{"date":"2022-08-01T23:23:06.261284054+01:00","location":{"latitude":51.4769,"longitude":-0.0005},"day_part":"astronomical_twilight","solar_elevation":-17.08752031631813,"azimuth_angle":334.3033709467604}

Supplying the optional --watch flag will give a second-by-second live view of the position of the Sun.

Click to expand

--watch and --json combined also works:

Click to expand

Configuration

heliocron supports reading some configuration options from a file located at ~/.config/heliocron.toml. Note that this file is not created by default, it is up to the user to create the file correctly, otherwise heliocron will simply pass over it. In particular, you can set a default latitude and longitude (must provide both, otherwise it will fall back to the default location of the Royal Greenwich Observatory).

# ~/.config/heliocron.toml
# set the default location to Buckingham Palace
latitude = 51.5014
longitude = -0.1419

Now, using heliocron without providing specific coordinates will yield the following output:

$ heliocron -d 2020-03-08 report
LOCATION
--------
Latitude: 51.5014
Longitude: -0.1419

DATE
----
2020-03-08 12:00:00 +00:00

Solar noon is at:         2020-03-08 12:11:12 +00:00
The day length is:        11h 24m 22s

Sunrise is at:            2020-03-08 06:29:01 +00:00
Sunset is at:             2020-03-08 17:53:23 +00:00

Civil dawn is at:         2020-03-08 05:55:45 +00:00
Civil dusk is at:         2020-03-08 18:26:39 +00:00

Nautical dawn is at:      2020-03-08 05:17:04 +00:00
Nautical dusk is at:      2020-03-08 19:05:20 +00:00

Astronomical dawn is at:  2020-03-08 04:37:39 +00:00
Astronomical dusk is at:  2020-03-08 19:44:45 +00:00

Observe that the location is set according to the contents of the configuration file.

Arguments passed in via the command line will override those set in the configuration file. Perhaps we want to check what is happening over at Windsor Castle without changing the configuration file:

$ heliocron -d 2020-03-08 -l 51.4839 -o -0.6044 report
LOCATION
--------
Latitude: 51.4839
Longitude: -0.6044

DATE
----
2020-03-08 12:00:00 +00:00

Solar noon is at:         2020-03-08 12:13:03 +00:00
The day length is:        11h 24m 24s

Sunrise is at:            2020-03-08 06:30:51 +00:00
Sunset is at:             2020-03-08 17:55:15 +00:00

Civil dawn is at:         2020-03-08 05:57:36 +00:00
Civil dusk is at:         2020-03-08 18:28:30 +00:00

Nautical dawn is at:      2020-03-08 05:18:56 +00:00
Nautical dusk is at:      2020-03-08 19:07:10 +00:00

Astronomical dawn is at:  2020-03-08 04:39:32 +00:00
Astronomical dusk is at:  2020-03-08 19:46:34 +00:00

Edge Cases

The chosen event does not occur on the given day

Sometimes, a particular event will never happen on a certain day at a certain location. For example, the Sun never drops below 18° below the horizon in England during the height of summer; astronomical dawn and dusk never occur.

When using the report subcommand, this is identified like so:

$ heliocron -d 2020-06-21 -l 52.8300 -o 0.5135 report
<-- snip -->
Astronomical dawn is at:  Never
Astronomical dusk is at:  Never

When using the wait subcommand, an error is raised and the program terminates immediately:

$ heliocron -d 2020-06-21 -l 52.8300 -o 0.5135 wait -e astronomical_dusk
Runtime error: The chosen event does not occur on this day.

The chosen event occurred some time in the past

If you try and wait for an event which happened in the past, an error will be raised and the program will terminate immediately:

$ heliocron -d 2020-06-21 -l 52.8300 -o 0.5135 wait -e sunrise
Runtime error: The chosen event occurred in the past; cannot wait a negative amount of time.

No such error arises if you just want a report from that date.

Reference

Usage

heliocron [Options] <Subcommand> [Subcommand Options]

Options

  • -d, --date [default: today]

    Specify the date in ISO 8601 format (YYYY-MM-DD).

  • -l, --latitude [default: 51.4769]

    Specify the north/south coordinate of the location. If --latitude is passed as a command line option, --longitude must also be provided.

    Latitude must be specified in decimal degrees - a number between -90.0 and 90.0 where positive is to the north and negative is to the south.

    Can be specified in a file located at ~/.config/heliocron.toml (see Configuration), although note that options provided over the command line take precedence.

  • -o, --longitude [default: -0.0005]

    Specify the east/west coordinate of the location. If --longitude is passed as a command line option, --latitude must also be provided.

    Longitude must be specified in decimal degrees - a number between -180.0 and 180.0 where positive is to the east and negative is to the west.

    Can be specified in a file located at ~/.config/heliocron.toml (see Configuration), although note that options provided over the command line take precedence.

  • -t, --time-zone [default: here and now]

    Specify the time zone, in [+/-]HH:MM format, at which to calculate and display times.

Subcommands

  • report

    Output the dates and times of sunrise, sunset, etc to stdout on the specified date at the specified location.

    • --json [optional]

      If this flag is present, the report will be output in JSON format, enabling easier parsing by other programs. If absent, the report is presented in a human-readable format, as displayed in the usage examples above.

      Example:

      # note that the output has been annotated and prettified in this example to more clearly show the structure
      $ heliocron report --json  
      {
        "date": "2022-06-11T12:00:00+01:00",  # dates are formatted as rfc3339
        "location": {"latitude": 51.4, "longitude": -5.467},  # coordinates use decimal degree notation 
        "day_length": 59534,  # day length is an unsigned integer number of seconds
        "solar_noon": "2022-06-11T13:21:31+01:00",
        "sunrise": "2022-06-11T05:05:24+01:00",
        "sunset": "2022-06-11T21:37:38+01:00",
        "dawn": {
          "civil": "2022-06-11T04:18:29+01:00",
          "nautical": "2022-06-11T03:06:40+01:00",
          "astronomical": null  # missing dates use the `null` JSON value
        },
        "dusk": {
          "civil": "2022-06-11T22:24:34+01:00",
          "nautical": "2022-06-11T23:36:23+01:00",
          "astronomical": null
        }
      }
  • wait

    Put the thread to sleep until the chosen event [+ offset] occurs on the specified date at the specified location.

    • -e, --event [required]

      Must be one of:

      Event Description
      sunrise The moment when the upper edge of the solar disk becomes visible above the horizon
      sunset The moment when the upper edge of the solar disk disappears below the horizon
      civil_dawn The moment when the geometric centre of the Sun reaches 6° below the horizon as it is rising
      civil_dusk The moment when the geometric centre of the Sun reaches 6° below the horizon as it is setting
      nautical_dawn The moment when the geometric centre of the Sun reaches 12° below the horizon as it is rising
      nautical_dusk The moment when the geometric centre of the Sun reaches 12° below the horizon as it is setting
      astronomical_dawn The moment when the geometric centre of the Sun reaches 18° below the horizon as it is rising
      astronomical_dusk The moment when the geometric centre of the Sun reaches 18° below the horizon as it is setting
      custom_am Allows the user to specify the moment when the geometric centre of the Sun reaches a custom number of degrees below the horizon as it is rising
      custom_pm Allows the user to specify the moment when the geometric centre of the Sun reaches a custom number of degrees below the horizon as it is setting
      solar_noon The moment when the Sun reaches its highest point in the sky
    • -a, --altitude [required if --event is one of { custom_am | custom_pm }]

      Specify the number of degrees that the geometric centre of the Sun is below the horizon when using a custom_* event. Allowed values are between -90.0 and 90.0.

      If this option is passed for any other event, it is simply ignored.

      Example:

      # specify the custom event of Jewish dusk, commonly held to be when the centre of the Sun is 8.5° below the horizon as it is setting in the evening
      $ heliocron wait --event custom_pm --altitude 8.5
    • -o, --offset [default: 00:00:00]

      Specify an offset, either in [-]HH:MM or [-]HH:MM:SS format, from the chosen event. Negative offsets (those which are prefixed with a '-' e.g. -01:00) will set the delay to be before the event, whilst positive offsets will shift the delay after the event.

    • --run-missed-task [optional]

      If this flag is present, then the process will exit successfully even if the event was missed. This can happen, for example, if the device running heliocron goes to sleep and does not wake up until after the event has occurred. Without this flag, if the event is missed by more than 30 seconds, then the task will not be run.

    • --tag [optional]

      Allows specifying a custom string to describe or otherwise tag the process. When viewing all running processes, e.g. with htop, it will then be possible to filter against this tag as it appears on the command line.

      This option has no other effect on the running of the program.

  • poll

    Display real time data pertaining to the Sun at the current local time

    Note that if --date is specified previously as an option, it is ignored in favour of using the current local date.

    • --watch [optional] If this flag is present, the program will continue to run and update the values every second.

    • --json [optional] If this flag is present, the data will be output in JSON format, enabling easier parsing by other programs. If absent, the report is presented in a human-readable format, as displayed in the usage examples above.

      Example:

      # note that the output has been annotated and prettified in this example to more clearly show the structure
      $ heliocron poll --json  
      {
        "date": "2022-08-01T14:51:06.137191414+01:00",  # dates are formatted as rfc3339
        "location": {"latitude": 51.4769, "longitude": -0.0005},  # coordinates use decimal degree notation 
        "day_part": "day",  # one of "day", "civil_twilight", "nautical_twilight", "astronomical_twilight" or "night"
        "solar_elevation": 50.59814354839365,  # floating point number of degrees that the Sun is above the horizon
        "azimuth_angle": 221.39860862334302  # floating point number of degrees that the Sun is positioned on a horizontal plane clockwise from north
      }

heliocron's People

Contributors

4e554c4c avatar mfreeborn 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

heliocron's Issues

compilation errors on cubieboard 1

I'm trying to compile heliocorn on a cubieboard1 running armbian, and I'm getting the following errors:

error[E0599]: no method named "as_deref" found for type "std::option::Optionstd::string::String" in the current scope
--> src/config.rs:140:37
|
140 | date_args.time_zone.as_deref(),
| ^^^^^^^^ help: did you mean: "as_ref"

error[E0658]: use of unstable library feature 'range_contains': recently added as per RFC (see issue #32311)
--> src/structs.rs:141:39
|
141 | n if (0.0..=90.0).contains(&n) => Ok(n),
| ^^^^^^^^

error[E0658]: use of unstable library feature "range_contains": recently added as per RFC (see issue #32311)
--> src/structs.rs:197:40
|
197 | n if (0.0..=180.0).contains(&n) => Ok(n),
| ^^^^^^^^

error: aborting due to 3 previous errors

Some errors occurred: E0599, E0658.
For more information about an error, try "rustc --explain E0599".
error: Could not compile "heliocron".

I've tried to understand a bit more about the errrs, but with no luck... do you have any idea?

thanks
rosanna

Only waits for 1 hour then stops

Heliocron only seems to wait 1 hour then stops, prior to executing script.

syslog shows counting per min for 60 min then halting with no error.

Output ISO8601 dates

Currently heliocron reports events as Never or very similar to date '+%Y-%m-%d %H:%M:%S %:z', this is nonstandard and it would be very easy to output in ISO8601 instead, as chrono::DateTime has a to_rfc3339 method. Furthermore, there is no way to control the timezone of output dates.

Implement the --event flag {sunrise | sunset} as an enum

As per title, it would be much better to have this return an Event enum, rather than a String. From the Reddit thread:

For the enum, you just have to implement FromStr for parsing enum variants (for example matching on "sunrise", "sunset" or return an error), and in Structopt you can specify what are the possible values for a field with the attribute #[structopt(possible_values = &["foo", "bar", "thing"])].

TZ issue

hello,
i'm not able to figure out how to set different time zones. for me it just doesn't work as expected:

cargo run -- --latitude 55.7558N --longitude 37.6173E  report # Moscow
LOCATION
--------
Latitude: 55.7558N
Longitude: 37.6173E

DATE
----
2022-01-18 12:00:00 +03:00

Solar noon is at:         2022-01-18 12:39:53 +03:00
The day length is:        7h 48m 15s

Sunrise is at:            2022-01-18 08:45:46 +03:00
Sunset is at:             2022-01-18 16:34:01 +03:00
...

so good so far,

TZ=EST cargo run -- --latitude 40.7128N --longitude 74.0060W  report # New York
LOCATION
--------
Latitude: 40.7128N
Longitude: 74.0060W

DATE
----
2022-01-18 12:00:00 -05:00

Solar noon is at:         2022-01-18 12:06:29 -05:00
The day length is:        9h 40m 11s

Sunrise is at:            2022-01-18 07:16:24 -05:00
Sunset is at:             2022-01-18 16:56:35 -05:00
...

ok

cargo run -- --latitude 40.7128N --longitude 74.0060W  -t -05:00 report # New York
LOCATION
--------
Latitude: 40.7128N
Longitude: 74.0060W

DATE
----
2022-01-18 12:00:00 +03:00

Solar noon is at:         2022-01-18 20:06:23 +03:00
The day length is:        9h 39m 38s

Sunrise is at:            2022-01-18 15:16:34 +03:00
Sunset is at:             2022-01-19 00:56:12 +03:00
...

doesn't work -t -05:00 option

TZ=PST cargo run -- --latitude 37.7749N --longitude 122.4194W  report # San Francisco
LOCATION
--------
Latitude: 37.7749N
Longitude: 122.4194W

DATE
----
2022-01-18 12:00:00 +00:00

Solar noon is at:         2022-01-18 20:20:05 +00:00
The day length is:        9h 54m 43s

Sunrise is at:            2022-01-18 15:22:43 +00:00
Sunset is at:             2022-01-19 01:17:26 +00:00
...

doesn't work even with TZ set to seemed correct PST time zone

could you please point me to where what i missed something? Thanks!

Multiple instances in cron

I’m using Heliocron to schedule a Timelapse at sunrise, sunset, and with a different exposure after dark. If I kick them all off from a cron, they seem to fail. Or perhaps heliocron is not multithreaded? And only the last one triggered works?

I know the syntax is correct because I can run any of the commands manually from a shell. But if I trigger them all from cron at say 0 1 * * * even staggered by a minute two, they fail.

Do I need to make sure there’s only one sleeping at a time from Cron?

Not showing proper time when using report function?

When using report, the time is reported as local noon time:

LOCATION
--------
Latitude: 
Longitude: 

DATE
----
2023-08-09 12:00:00 -03:00

Solar noon is at:         2023-08-09 13:19:48 -03:00
The day length is:        14h 20m 16s

Sunrise is at:            2023-08-09 06:09:40 -03:00
Sunset is at:             2023-08-09 20:29:56 -03:00

Civil dawn is at:         2023-08-09 05:37:13 -03:00
Civil dusk is at:         2023-08-09 21:02:23 -03:00

Nautical dawn is at:      2023-08-09 04:56:53 -03:00
Nautical dusk is at:      2023-08-09 21:42:43 -03:00

Astronomical dawn is at:  2023-08-09 04:11:40 -03:00
Astronomical dusk is at:  2023-08-09 22:27:56 -03:00

However, when using poll, the time is reported is the same as the system time:

LOCATION
--------
Latitude:  
Longitude: 

DATE
----
2023-08-09 19:00:39 -03:00
Day

Solar elevation: 14.396°
Azimuth angle:   278.083°

Is this correct behavior or should report also give the system time?

(Note: I've removed my latitude and longitude as that would identify where I am located, but are entered in my config.toml file.)

Binary 0.5.0 on arm-unknown (RPi 0) appear broken on RPi0W

I just installed the binary https://github.com/mfreeborn/heliocron/releases/download/v0.5.0/heliocron-v0.5.0-arm-unknown-linux-gnueabi.tar.gz onto a Raspberry Pi 0 WiFi running Raspbian 10 (buster).

When I call heliocron, it always estimates sunrise and sunset to be at 00:00:00 local time (and hence the day is pretty short).

So something isn't working in that release.

Here is a sample output from the RPi0w (from README.md and works fine on another Linux box I tested on):

user@rpi0w:~/heliocron-v0.5.0-arm-unknown-linux-gnueabi $ ./heliocron -d "7 May 2065" -f "%e %B %Y" -l 55.9533N -o 3.1883W report
LOCATION
--------
Latitude: 55.9533N
Longitude: 3.1883W

DATE
----
2065-05-07 12:00:00 +01:00

Solar noon is at:         2065-05-07 00:00:00 +01:00
The day length is:        0h 0m 0s

Sunrise is at:            2065-05-07 00:00:00 +01:00
Sunset is at:             2065-05-07 00:00:00 +01:00

Civil dawn is at:         2065-05-07 00:00:00 +01:00
Civil dusk is at:         2065-05-07 00:00:00 +01:00

Nautical dawn is at:      2065-05-07 00:00:00 +01:00
Nautical dusk is at:      2065-05-07 00:00:00 +01:00

Astronomical dawn is at:  2065-05-07 00:00:00 +01:00
Astronomical dusk is at:  2065-05-07 00:00:00 +01:00

I assume something doesn't quite build right on this platform, although I haven't tried to rebuild from source.

README.md needs updating?

I've just noticed that some instructions and examples in README.md file might need updating.
It seems helicron no longer uses symbols N, S, E, and W; instead we should use numerical values only for North (N) and East (E), and a minus sign before numerical values for South (S) and West (W).

Additionaly, the values in the configuration file shouldn't be quoted, and that section should be changed like this:

# set the default location to Buckingham Palace
latitude = 51.5014
longitude = -0.1419

Bug: panic if sunrise/sunset overflows to the next day

When calculating sunset and sunrise, it panics if sunrise or sunset crosses over to the next or previous day. This can happen if you want to find, for example, sunset time somewhere on the opposite side of the world but with your own timezone.

The chosen event occurred in the past

I have lots of problems to schedule the cron job correctly. All the time I get message:

Runtime error: The chosen event occurred in the past; cannot wait a negative amount of time.

Which is funny, because I trigger event at 02:00, and sunrise is 08:51:11
Same goes for sunset: job scheduled at 12:00, sunset at 14:55.

Apparently, there are some problems when date is today.

I think it's obvious, if I wait for sunrise (without specific --date), I mean the next coming sunrise tomorrow morning. I can't process why this program assumes I care about sunrise which already happened today morning. Maybe some sort of --force flag will do?

Read config from `/etc`

Might be useful to read a configuration file from standard locations such as /etc and /usr/local/etc. Would submit a PR myself but don't speak Rust!

Getting Illegal Instruction when attempting to run on Raspberry Pi Zero W with latest OS

I have tried both the full version of the Raspbian OS and the light version and it is happening with both OSes. I think it might be a hardware issue, because the version of heliocron for my Pi3+ runs just fine on the latest OS. This is happening on the prebuilt binary additional for the Pi1/0.

Please let me know if you need any further information.

Add time thresholds

Hi, thanks for this handy tool!

My use case for heliocron is to control window blinds: open at sunrise and shut at sunset. That works fine for the most part of the year, except for the summer.
For example, I would like to wake up at 07:00 in the morning, but if the sun rises at 06:00 or even earlier and the blinds open with sunrise, my morning is ruined... Also in the evening I would like my room to be dark when I go to bed, but sun may be setting much later than that.
I thought, it would be convenient to have 2 more threshold options in heliocron:

  1. "No earlier than". It would prevent sunrise event from firing before specified time. As per example above, if I would like to set a threshold that blinds never open before 07:00. Only at 07:00 or later.
  2. "No later than". Similarly in the evening, the sunset event would be fired no later than specified time. E.g., my blinds would always shut at 22:00 if the sun sets after that time.

Does not work if system sleeps or is suspended

When my laptop goes to sleep, or is suspended, heliocron sleeps for far too long. I suspect this is because its main std::thread::sleep call does not make progress while the system itself is suspended. This is expected behavior according to the sleep docs, so heliocron shouldn't be using this call. A better alternative would probably be sleep_until from tokio, but that would require an async rewrite.

Pre-built binary for 64bit pi OS (aarch64)

Perhaps I'm just misunderstanding, but having issues getting any of the pre-built binaries to run for 64bit raspbian on a raspberry pi 3 (aarch64) - I'm guessing they are 32bit only and the 64bit download is for x86. Thank you for your work on this project, has been a huge help to some custom home automation projects I've been working on!

Config File issue

Howdy from Texas!

I stumbled upon Heliocron while working on a timelapse project designed to run on a RPi. I am trying to get it set up to use in crontab for launching my script at sunrise each day.

I love the elegance of your solution, thanks for contributing it to the world!

My issue is with setting my GPS location in the config file I created at ~/.config/heliocron.toml.

# ~/.config/heliocron.toml
# set the default location to Texas Capitol    
latitude = "30.274N"
longitude = "-97.740W"

Perhaps I'm doing something stoopid?

When I run heliocron --version, I get:
Config error: Error parsing TOML file. Ensure that it is of the correct format.

Request: Allow next time each event occurs and not assume system runs continuously.

Mirror of this #25

I would love to integrate heliocron with fcron to execute a script every day regardless of system status (suspend, hibernate, power-down) at sundown and sunrise. The application would be using brightnessctl to automatically dim or engage keyboard backlight or screen backlight.

Heliocron assumes the system does not run continuously. Using fcron to run it, heliocron does not execute past events nor (as in acejacek's and my case) events occurring the same day.

I think this would be a brilliant tool that very many users could appreciate, as it has so much potential to be a battery saver.

Feature Request: Add 'tag' or 'comment' parameter.

Because these processes run for a prolonged period of time -- it would be nice to be able to include some sort of 'tag' or 'comment' parameter, so that the purpose of the heliocron process could be identified more easily via 'ps'. The parameter/value doesn't need to actually do anything - but including one currently causes an error for an invalid parameter.

Build on MacOs

Hi,

When I try to build (rustc 1.65.0 (897e37553 2022-11-02)) the project (v0.8.1) on arm64-apple-darwin22.1.0 (MacOs 13.0 (22A380)), I get a compilation error for tokio-walltime v0.1.2. Errors are of the kind
error[E0425]: cannot find function `timer_create` in crate libc.
I tried on Linux and I had no problem.

I'm not sure what I should be looking for, I'm not a rust expert.

Otherwise, the plugin seems nice!

test parsers::tests::test_parse_date ... FAILED

I tried building with the PKGBUILD script in the Arch User Repository and test_parse_date failed:

    Finished release [optimized] target(s) in 58.95s
     Running unittests (target/release/deps/heliocron-da9bfa9da31946ab)

running 23 tests
test calc::tests::test_day_fraction_to_time_underoverflow ... ok
test calc::tests::test_day_length ... ok
test calc::tests::test_day_fraction_to_time ... ok
test calc::tests::test_day_length_24_hour_day ... ok
test calc::tests::test_day_length_24_hour_night ... ok
test enums::tests::test_custom_event_instantiation ... ok
test enums::tests::test_non_custom_event_instantiation ... ok
test enums::tests::test_non_custom_ignores_altitude ... ok
test parsers::tests::test_parse_altitude ... ok
test parsers::tests::test_parse_date_wrong_format_fails ... ok
test parsers::tests::test_parse_event ... ok
test parsers::tests::test_parse_date ... FAILED
test parsers::tests::test_parse_offset ... ok
test report::tests::test_report_content ... ok
test report::tests::test_solar_report_new ... ok
test structs::tests::test_parse_latitude ... ok
test structs::tests::test_parse_longitude ... ok
test report::tests::test_sunrise_sunset ... ok
test traits::tests::test_day_fraction ... ok
test utils::tests::test_wait ... ok
test traits::tests::test_to_juilian_date ... ok
test parsers::tests::test_parse_event_fails ... ok
test parsers::tests::test_parse_date_wrong_tz_fails ... ok

failures:

---- parsers::tests::test_parse_date stdout ----
thread 'parsers::tests::test_parse_date' panicked at 'assertion failed: `(left == right)`
  left: `2020-03-25T12:00:00+00:00`,
 right: `2020-03-25T12:00:00-06:00`', src/parsers.rs:137:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    parsers::tests::test_parse_date

test result: FAILED. 22 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '--lib'
==> ERROR: A failure occurred in check().
    Aborting...
error making: heliocron

Add support for Jewish dusk

It would be great if the wait command of this project could support "Jewish dusk", more commonly known as the time in the evening when the ritual of havdalah is done. (Other names for this time that you'll find if you look around the web are "tzeit hakochavim" or "the appearance of three stars".) The time for this is not universally agreed upon, but the most commonly used time is when the center of the sun is 8.5 degrees below the horizon.

Add support for a config file

Currently heliocron has some hardcoded defaults for parameters such as location. It would be nice to be able to configure this, perhaps so that you can set the default location (and other things) to your own coordinates.

It would be something like a file such as ~/.config/heliocron.conf with key=val entries which are read into heliocron when it runs. These values would override any other defaults.

Doesn't seem to be working through cron

Hi,

I've installed heliocron as I have scripts that I'd like to run at sunrise and sunset but they're not running. When I use 'heliocron report' I do get the correct results so I know it's installed properly.

In my crontab, I have the following (I've hidden my lat/long):

00 15 * * * heliocron --latitude xx.xxxx --longitude yyy.yyyy wait --event sunset \ && /usr/local/bin/dim.sh

00 02 * * * heliocron --latitude xx.xxxx --longitude yyy.yyyy wait --event sunrise \ && /usr/local/bin/brighten.sh

I do have the correct lat long configured in .config/heliocron.toml but added them in the cron entries just in case they were specifically needed there. I've tried without as well.

But nothing happens at sunrise or sunset, my scripts aren't run.

Have I missed something really obvious please?

I'm using a Raspberry Pi with Raspbian Stretch. It needs to be Stretch, what I'm running won't work with a later version.

Thanks.

Useful utility

Not an issue but I can't find anywhere else to comment, so please delete comment if inappropriate.

I needed exactly this utility and it works a treat. Easily installed by the R Pi binary although I did take a look at Rust and nearly persuaded myself to do it the hard way.

Anyway, to control my living room lamp, I now have an R Pi with heliocron, a bit of Python, MQTT, and wifi to a Chinese switch flashed with Tasmota. What could possibly go wrong 😉

Feature: Add a simple graph showing solar elevation in the terminal with the report subcommand

It would be great if the report subcommand showed a simple line chart with time on the x axis and solar elevation on the y axis.

It would be even better if the chart could be annotated with, for example, sunrise, sunset and solar noon.

I've had a play around with textplots-rs, but it's missing a few key featrures:

  • specifying y axis range
  • specifying individual axis tick locations
  • time-series axis labels
  • annotations

Here is an example of what I can achieve with it up to its limitations:

Screenshot from 2020-12-28 17-36-35

And, for reference, this is the graph I would like to replicate:

example sunrise chart

cannot understand

Hi, thank you for sharing this software.
However i don't understand how i can connect the numbers with the sunrise/set times that i get
from arduino libraries and my domoticz program, they calculate 8.37 sunrise and 16.30 sunset.

i am using it on a raspberry zero raspbian buster.
systemtime reports to be oke. Longitude and latitude are in the config file.

could you give me a hint on what i can do? I also have troubles to understand the +01:00 i see in the rows


Latitude: 51.4000N
Longitude: 5.4670W

DATE

2021-12-15 12:00:00 +01:00

Solar noon is at: 2021-12-15 13:17:05 +01:00
The day length is: 7h 52m 40s

Sunrise is at: 2021-12-15 09:20:45 +01:00
Sunset is at: 2021-12-15 17:13:25 +01:00

Civil dawn is at: 2021-12-15 08:40:42 +01:00
Civil dusk is at: 2021-12-15 17:53:29 +01:00

New Zealand time zone and location seems to fail

So, I ran this command on my server at Midnight or just after, time zone config is in New Zealand Standard Time.
(this is a Debian 10 install - downloaded heliocron binary package)

root@hostname:/date : Tue Jun 28 00:10:45 NZST 2022
Then ran :
root@hostname:/heliocron -l 37.03216S -o 175.1220E wait --event sunrise && banner hello
Which results in this error
Runtime error: The chosen event occurred in the past: 2022-06-27 16:25:35 +12:00. Cannot wait a negative amount of time.

I have tried to run time zones, but all to no avail, even +18 hours results in a fail where it 'can not wait a negative amount of time'
I might be having a dumb moment here, and not seeing something, but just am really puzzled as to what is going on.

I was going to send a private message as it had GPS locations in, but managed to move them enough away into forest land near my house to be happy enough to post..

Could you please suggest anything I could try to see if I could resolve this..
The fish will thank you for their wakeup with the sun and sleep with the setting sun...

Add "poll" mode.

Once nice thing about sunwait is that it lets you ask the question "is it day or night right now" via sunwait poll. This is helpful for setting light vs dark themes. Could heliocron grow such an option?

Depending on seasons?

Is it possible to allow the definition of heliocron jobs not only in relation to sunrise/sunset times, but also depending on the current season?
For example: a heater must not necessarily be turned on in the summer time.

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.