Skip to content

Plugin sunrise and sunset

Martin Pihrt edited this page Oct 13, 2026 · 1 revision

Astro Sunrise and Sunset

Calculates astronomical dawn, sunrise, noon, sunset and dusk times for OSPy programs and mobile clients.

At a glance

Item Value
Version 1.0.6
Category Weather, climate and environmental sensors
Author Martin Pihrt
License GPL-3.0
OSPy 3.0.211 or newer
Python 3.8 or newer
Permissions network, subprocess, system
Hardware No dedicated hardware requirement declared
Dependencies None
Python/OS packages astral (optional), pytz (optional)
Interfaces Mobile API v1
Source Open the plug-in directory

What it is for

Calculates astronomical dawn, sunrise, noon, sunset and dusk times for OSPy programs and mobile clients.

How it works and how to configure it

Only for Python 3+

The plug-in includes a plugin.json manifest and reports its worker, Astral availability, location, sunrise, sunset, scheduled programs, dependency installation and calculation errors through the OSPy system health interface. The mobile interface provides today's astronomical values and a fixed 24-hour timeline with night before sunrise and after sunset; it does not expose irrelevant history-range controls.

From version 1.0.5 the plug-in is also the astronomical provider for native OSPy sunrise and sunset program types. It exposes a read-only availability check and the calculated dawn, sunrise, noon, sunset and dusk values for a requested date. OSPy keeps calendar filtering, offsets, allowed time windows and irrigation scheduling in the core; this plug-in remains responsible for Astral, location and timezone calculation. The older plug-in option for launching an existing program remains available and is not removed.

If the plug-in is disabled, Astral is unavailable or no valid location can be resolved, the provider returns no guessed time. OSPy therefore retains the saved solar program but does not generate its automatic occurrence until the provider recovers. Manual program control and non-solar programs are unaffected.

When the OSPy weather location is used, the displayed Astral region comes from the location detected by OSPy. Older installations use the detected country code until the weather location is looked up again.

Mobile application

Open Plug-ins and expand Astro Sunrise and Sunset operating data in the OSPy mobile application. The native 24-hour timeline always represents the current day, uses gray bands before sunrise and after sunset, marks sunrise, sunset and the current time, and therefore does not offer history-range buttons. The astronomical metrics and timeline refresh automatically while the panel remains expanded.

This extension requires the Astral Python package. If Astral is missing, the status page shows an Install libraries button and writes the installation progress to the status log. On Raspberry Pi OS install it with:

sudo apt install python3-astral

This extension allows you to run a specific program depending on sunrise or sunset. This extension calculate the following astronomical data.

  • Dawn The time in the morning when the sun is a specific number of degrees below the horizon.
  • Sunrise The time in the morning when the top of the sun breaks the horizon (asuming a location with no obscuring features.)
  • Noon The time when the sun is at highest point directly above the observer.
  • Sunset The time in the evening when the sun is about to disappear below the horizon (asuming a location with no obscuring features.)
  • Dusk The time in the evening when the sun is a specific number of degrees below the horizon.
  • Moon Phase The moon phase method returns an number describing the phase, where the value is between 0 and 27.99. The following lists the mapping of various values to the description of the phase of the moon.

More information can be found after installing the plugin in the plugin help.

In terms of economy and good usability of moisture, early morning watering is optimal. We can also spray the leaves, because they will dry out before the sun can burn them. Plants should not be sprayed at all at noon: water droplets act like small optical lenses on the leaves, in which the sun's rays concentrate and cause burns on the leaves. In addition, it is uneconomical, because part of the water evaporates already in the air and another part immediately upon impact with the hot ground. If the plants wither during the day, we will help them with moisture directly to the roots. In the evening it should be watered only to the roots. The sprinkled leaves do not have time to dry and there is a risk of fungal diseases. Otherwise, evening watering is advantageous because the water absorbs well into the soil overnight and the plants have it in store for the next hot day.

Plugin setup

  • Use astro plugin: If the box is checked, the plugin checks Sunrise and Sunset updates every hour.

  • City Location: Select a city from the Astral list to use its built-in location. Leave the city unselected to use the coordinates from OSPy weather settings and the time zone configured on the OSPy host. Weather and location must be enabled in OSPy. The plug-in no longer stores a separate manual location.

  • Show in footer: Show data from plugin in footer on home page.

  • Status: Status window from the plugin.

Script injection

Plugin adds display of sunrise and sunset times in the homepage schedule (javascript injection). https://github.com/martinpihrt/OSPy-plugins/tree/master/plugins/sunrise_and_sunset/static/images/sun_home.png

In-app help and settings notes

The following notes are generated from the help page shipped with this plug-in. Field names are also explained directly in the OSPy settings page.

This extension allows you to run a specific program depending on sunrise or sunset.

This extension calculate the following astronomical data

  • Dawn

The time in the morning when the sun is a specific number of degrees below the horizon.

  • Sunrise

The time in the morning when the top of the sun breaks the horizon (asuming a location with no obscuring features.)

  • Noon

The time when the sun is at highest point directly above the observer.

  • Sunset

The time in the evening when the sun is about to disappear below the horizon (asuming a location with no obscuring features.)

  • Dusk

The time in the evening when the sun is a specific number of degrees below the horizon.

Effect of Elevation

Times Of The Sun

The times of the sun that you experience depend on what obscurs your view of it. It may either be obscured by the horizon or some other geographical feature (e.g. mountains)

If what obscures you at ground level is the horizon and you are at a elevation above ground level then the times of the sun depends on how far further round the earth you can see due to your elevation (the sun rises earlier and sets later).

The extra angle you can see round the earth is determined by calculating the angle α in the image below based on your elevation above ground level, and adding this to the depression angle for the sun calculations.

If your view is obscured by some other geographical feature than the horizon, then the adjustment angle is based on how far you are above or below the feature and your distance to it.

For the first case i.e. obscured by the horizon you need to pass a single float to the Observer as its elevation. For the second case pass a tuple of 2 floats. The first being the vertical distance to the top of the feature and the second the horizontal distance to the feature.

Elevation Of The Sun

Even though an observers elevation can significantly affect the times of the sun the same is not true for the elevation angle from the observer to the sun.

As an example the diagram below shows the difference in angle between an observer at ground level and one on the ISS orbiting 408 km above the earth.

The largest difference between the two angles is when the angle at ground level is 1 degree. The difference then is approximately 0.15 degrees.

At the summit of mount Everest (8,848 m) the maximum difference is 0.00338821 degrees.

Due to the very small difference the astral package does not currently adjust the solar elevation for changes in observer elevation.

  • Moon Phase

The phase of the moon for a specified date.

The moon phase method returns an number describing the phase, where the value is between 0 and 27.99. The following lists the mapping of various values to the description of the phase of the moon.

If for example the number returned was 27.99 then the moon would be almost at the New Moon phase, and if it was 24.00 it would be half way between the Last Quarter and a New Moon.

Note

The moon phase does not depend on your location. However what the moon actually looks like to you does depend on your location. If you are in the southern hemisphere it looks different than if you were in the northern hemisphere.

New moon

First quarter

Full moon

Last quarter

The top animation shows the Moons orbit as it would be seen looking down on Earth from high above the North Pole, and it shows the Moons phases as they would be seen from most places in the northern hemisphere.

The bottom animation shows the Moons orbit as it would be seen looking down on Earth from high above the South Pole, and it shows the Moons phases as they would be seen from most places in the southern hemisphere.

Select a city from the list or leave it unselected to use the location from OSPy weather settings and the time zone configured on the OSPy host.

Mobile application

The mobile application shows a fixed 24-hour timeline for the current day. Gray areas represent night before sunrise and after sunset, and markers show sunrise, sunset and the current time. This view has no history-range controls and refreshes automatically while expanded.

Cities for location

The module includes location and time zone data for the following cities. The list includes all capital cities plus some from the UK. The list also includes the US state capitals and some other US cities.

US Cities

Installation

This plug-in needs the Astral Python package. If Astral is missing, the status page shows an Install libraries button and writes installation progress to the status log. On Raspberry Pi OS install it with: sudo apt install python3-astral

Script injection

Plugin adds display of sunrise and sunset times in the homepage schedule (javascript injection).

Example Image on the Github

License

This module is licensed under the terms of the Apache V2.0 license.

Dependencies

Astral has one required external Python dependency on pytz.

Astral on the Github

Related links and diagrams

elevation horizon

elevation sun

Moon-Phases-N

Moon-Phases-S

Support

Check OSPy → Diagnostics first and remove passwords, tokens, private addresses and other secrets before sharing logs. Report reproducible plug-in problems in the OSPy-plugins issue tracker.

Back to the plug-in catalog

Clone this wiki locally