Sunrise Sunset Trigger

Triggers when sunrise or sunset occurs at specified location

Overview

This node triggers workflows based on sunrise or sunset events at a specified geographic location. It is useful for automating tasks that depend on natural light conditions, such as turning lights on/off, adjusting smart home devices, or scheduling outdoor activities.

The node allows you to specify the latitude and longitude of the location, choose whether to trigger on sunrise or sunset, and select the exact type of event time (e.g., actual sunrise, civil twilight begin). It also supports specifying a timezone to correctly calculate local event times.

Practical examples:

  • Automatically turn on garden lights at sunset.
  • Start morning routines at sunrise.
  • Trigger notifications when astronomical twilight begins for astronomy enthusiasts.

Properties

Name Meaning
Latitude Latitude of the location in decimal degrees (e.g., 36.7201600). Required.
Longitude Longitude of the location in decimal degrees (e.g., -4.4203400). Required.
Event Type The type of event to trigger on: Sunrise or Sunset.
Time Event The specific twilight time to use: Actual Time, Civil Twilight Begin, Civil Twilight End, Nautical Twilight Begin, Nautical Twilight End, Astronomical Twilight Begin, or Astronomical Twilight End.
Timezone The timezone to use for event time calculation (e.g., Europe/Madrid). Defaults to system timezone if left empty.

Output

The node outputs JSON data containing information about the sunrise or sunset event times for up to 7 days starting from the current day. Each output item includes:

  • date: The date of the event (YYYY-MM-DD).
  • utcTime: The event time in UTC ISO 8601 format.
  • localTime: The event time converted to the specified or system timezone.
  • event: The event type (sunrise or sunset).
  • timeEvent: The specific twilight time used (e.g., actual, civil_twilight_begin).
  • timezone: The timezone used for local time conversion.
  • raw: The full raw response from the external API providing sunrise/sunset data.

The node does not output binary data.

Dependencies

  • External API: The node fetches sunrise and sunset times from the public API at https://api.sunrise-sunset.org.
  • Timezone handling: Uses the moment-timezone library to handle timezone conversions.
  • Requires internet access to query the external API.
  • No credentials are required for this API.

Troubleshooting

  • Missing or invalid latitude/longitude: The node throws errors if latitude or longitude are missing, not numbers, or out of valid ranges (latitude must be between -90 and 90; longitude between -180 and 180).
  • API request failures: If the external API returns an error or unexpected data, the node logs the error and skips that day's data.
  • Timezone issues: If an invalid timezone string is provided, the node falls back to the system timezone.
  • No output emitted: Ensure the node is triggered manually or by an appropriate schedule since it only emits data when triggered.

Links and References

Discussion