Sun elevation changed

The Sun elevation changed trigger fires when the sun’s elevation changes. Elevation is the angle between the sun and the horizon: 0° is right at the horizon, positive values are above it, and negative values are below it. Home Assistant recalculates the elevation continuously as the sun moves through the sky.

Use the threshold type to filter which changes matter. You can react to any change, or only to changes that land above an angle, below an angle, inside a range, or outside a range. This is handy for logging the sun’s path or for automations that should respond while the sun stays in a particular part of the sky.

Using this trigger from the user interface

If you prefer building automations visually, Home Assistant walks you through this trigger step by step. You pick what to watch, tweak a few options, and save. No YAML knowledge required.

To use this trigger in an automation:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation, or select Create automation > Create new automation.
  3. In the When section, select Add trigger.
  4. From the search box, search for and select Sun elevation changed.
  5. Under Threshold type, configure which changes fire the trigger:
    • Select Any change to fire on every elevation change, regardless of value.
    • Select Above or Below and enter an angle in degrees to fire only when the new elevation is above or below that angle.
    • Select In range and enter a lower and upper angle to fire only when the new elevation falls inside the range.
    • Select Outside range and enter a lower and upper angle to fire only when the new elevation is outside the range.
    • For each option except Any change, you can enter a fixed angle in degrees, or reference a sensor entity or a number helper entity that holds the angle.
  6. Select Save.

Options in the UI

Threshold type

Controls which changes fire the trigger. Angles are in degrees, where 0° is the horizon, positive is above, and negative is below.

  • Any change: fires on any elevation change, regardless of value.
  • Above or Below (exclusive): fires only when the new elevation is strictly above or below the angle.
  • In range (inclusive): fires when the new elevation is between the two angles, or equal to one of them.
  • Outside range (exclusive): fires when the new elevation is below the lower angle or above the upper angle.

For each mode except Any change you can enter a fixed angle in degrees, or reference a sensor entity or a number helper entity.

Using this trigger in YAML

If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required. For how an automation is built in YAML, refer to Automations in YAML.

In YAML, put the settings that are specific to this trigger under options. Keep target, if the trigger uses one, and general settings such as id, alias, enabled, and variables at the top level, next to trigger.

When this trigger starts an automation, it passes data about what happened to the automation. You can use this trigger data in the templates of your conditions and actions. To see which data is available, refer to Trigger data in templates.

In YAML, refer to this trigger as sun.elevation_changed. A basic example looks like this:

TriggerA trigger is the part of an automation that makes the automation start when something specific happens, for example, when the sun sets, a door opens, or a button is pressed. [Learn more]
trigger: sun.elevation_changed
options:
  threshold:
    type: any

This fires on every elevation change. To fire only while the new elevation is above an angle, use type: above with a value:

TriggerA trigger is the part of an automation that makes the automation start when something specific happens, for example, when the sun sets, a door opens, or a button is pressed. [Learn more]
trigger: sun.elevation_changed
options:
  threshold:
    type: above
    value:
      number: 30

Options in YAML

threshold map Required

A mapping that defines which kind of change fires the trigger. Angles are in degrees.

  • type: any: Fires on any change (no additional keys needed).
  • type: above (exclusive): Fires when the new elevation is strictly above value. Provide value with a number key (a fixed angle in degrees) or an entity key (an input_number, number, or sensor entity).
  • type: below (exclusive): Fires when the new elevation is strictly below value. Provide value with a number key (a fixed angle in degrees) or an entity key (an input_number, number, or sensor entity).
  • type: between (inclusive): Fires when the new elevation is between value_min and value_max, or equal to one of them. Provide both, each with a number key (a fixed angle in degrees) or an entity key.
  • type: outside (exclusive): Fires when the new elevation is below value_min or above value_max. Provide both, each with a number key (a fixed angle in degrees) or an entity key.

Good to know

  • This trigger does not use a target. It always watches the sun at your configured home location.
  • Elevation updates often, so Any change and the threshold types fire repeatedly while the sun is moving. If you want to react only to a single crossing of an angle, use Sun elevation crossed threshold instead.
  • The maximum elevation the sun reaches depends on your latitude and the time of year, so pick threshold angles that the sun actually reaches at your location.
  • To work with named twilight phases rather than raw angles, use Dawn and Dusk.

Try it yourself

Ready to test this? Go to Settings > Automations & scenes, create a new automation, and add this trigger. Save the automation, and then make the trigger react. For example, change the state of the targeted entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more], turn on a light that the trigger monitors, or change its brightness. To check whether the automation ran, open its traces.

For this trigger, there is no target entity to change. To test it, wait for the sun to move, or temporarily set a threshold the sun is about to pass.

More examples

Real scenarios where this trigger fires in automations and scripts. Copy any example and adapt it to your setup. In the visual editor, select the UI options listed in the example when they are available, or paste the YAML code.

Tip

You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the visual automation editor in Home Assistant, and press Ctrl+V (or Cmd+V on Mac). Home Assistant automatically converts the pasted YAML into the visual editor format, whether it’s a full automation, a single trigger, a condition, or an action.

Automation: dim the lights while the sun is high

While the sun’s elevation stays above 30°, keep the living room lights dimmed to save energy when there is plenty of daylight.

  • Trigger: Sun elevation changed
    • Threshold type: Above (30°)
  • Action: Turn on light (brightness 30%)
    • Target: Living room lights
YAML example for dimming lights while the sun is high
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Dim lights while the sun is high"
triggers:
  - trigger: sun.elevation_changed
    options:
      threshold:
        type: above
        value:
          number: 30
actions:
  - action: light.turn_on
    target:
      entity_id: light.living_room
    data:
      brightness_pct: 30

Still stuck?

To find out why the trigger didn’t react, make the change that it should react to, and then open the traces of the automation. If the automation didn’t run, there’s usually no trace, but some triggers record a Did not trigger trace. For details, refer to Testing automations. For common problems and their solutions, refer to Troubleshooting automations.

If that doesn’t help, the Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the trigger you’re using and what you expected to happen, or share on our subreddit /r/homeassistant.

Tip

AI assistants like ChatGPT or Claude can also explain triggers or suggest the right one when you describe what you want in plain language.

Related triggers

Explore related triggers: