202670

Sun

The Sun integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] calculates sun-related times such as sunrise, sunset, dawn, and dusk based on your configured home location. This means that all time-based calculations and triggers will be accurate for your specific location, as defined in your basic configuration.

The sun integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] will use the location as configured in your Home Assistant configuration to track if the sun is above or below the horizon. The sun can be used within automations as a trigger with an optional offset to simulate dawn/dusk or as a condition with an optional offset to test if the sun has already set or risen.

Configured by default

This integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] is configured and installed by default, so you don’t need to set it up yourself, unless you’ve disabled or removed the default_config: line from your YAML configuration.

If that is the case, follow the steps below to set it up.

Configuration

To add the Sun service to your Home Assistant instance, use this My button:

Manual configuration steps

If the above My button doesn’t work, you can also perform the following steps manually:

YAML configuration

Alternatively, you can configure and set up this integration manually via YAML. To enable the sun integration in your installation, add the following to your configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file. After changing the configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes.

# Example configuration.yaml entry
sun:

Automation trigger

Home Assistant provides a set of dedicated sun triggers for sunrise, sunset, dawn, dusk, solar noon, solar midnight, and the sun’s elevation. See the list of triggers below for the full set.

The classic sun trigger described here is still supported and is the one to use when you need a fixed time offset before or after sunrise or sunset.

The sun’s event listener performs the action when the sun rises or sets, with an optional offset.

The sun trigger needs the trigger type sun, an event (sunset or sunrise), and an optional offset:

triggers:
 - trigger: sun
 event: sunrise
 # Fire one hour before sunrise.
 offset: "-01:00:00"

The following keys are available:

  • event: Required. Either sunrise or sunset.
  • offset: Optional. A time offset relative to the sun event, specified as a number of seconds or in HH:MM:SS format. A negative value fires the trigger before the sun event, a positive value fires it after.

For example, if sunrise is at 06:00 and you set offset: "-01:00:00", the automation runs at 05:00. With offset: "01:00:00", it runs at 07:00. The same rule applies to sunset.

Tip

Because the duration of twilight varies throughout the year, a fixed offset is not always the best way to trigger automations around dawn or dusk. For more precise dawn or dusk automations, use a sun elevation trigger instead.

Maintains entity sun.sun

Possible state Description
above_horizon When the sun is above the horizon.
below_horizon When the sun is below the horizon.

List of triggers

The Sun integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following triggers. Each link below opens a dedicated page with examples, fields, and a step-by-step UI walkthrough.

  • Dawn (sun.dawn) Triggers at dawn, when civil, nautical, or astronomical twilight begins.

  • Dusk (sun.dusk) Triggers at dusk, when civil, nautical, or astronomical twilight ends.

  • Sun elevation changed (sun.elevation_changed) Triggers whenever the sun’s elevation changes, optionally limited to a threshold or range you set.

  • Sun elevation crossed threshold (sun.elevation_crossed_threshold) Triggers when the sun’s elevation crosses a threshold you set.

  • Solar midnight (sun.solar_midnight) Triggers when the sun reaches its lowest point.

  • Solar noon (sun.solar_noon) Triggers when the sun reaches its highest point.

  • Sunrise (sun.sunrise) Triggers when the sun rises.

  • Sunset (sun.sunset) Triggers when the sun sets.

For an overview of every trigger across all integrations, see the triggers reference.

List of conditions

The Sun integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following conditions. Each link below opens a dedicated page with examples, fields, and a step-by-step UI walkthrough.

For an overview of every condition across all integrations, see the conditions reference.

Sensors

The sensors are also available as attributes on the sun.sun entity for backward compatibility.

Sensors Description
Next rising Date and time of the next sun rising (in UTC).
Next setting Date and time of the next sun setting (in UTC).
Next dawn Date and time of the next dawn (in UTC).
Next dusk Date and time of the next dusk (in UTC).
Next noon Date and time of the next solar noon (in UTC).
Next midnight Date and time of the next solar midnight (in UTC).
Elevation Solar elevation. This is the angle between the sun and the horizon. Negative values mean the sun is below the horizon.
Azimuth Solar azimuth. The angle is shown clockwise from north.

Binary sensors

The binary sensors are also available as attributes on the sun.sun entity for backward compatibility.

Sensors Description
Solar rising on when the sun is currently rising (after solar midnight and before solar noon).

Related topics

Help us improve our documentation

Suggest an edit to this page, or provide/view feedback for this page.

AltStyle によって変換されたページ (->オリジナル) /