Sun elevation
The Sun elevation condition passes when the sun’s elevation meets a threshold you set. 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 works this out from your home location.
Because elevation tracks the real position of the sun, it adapts to the seasons in a way a fixed clock time cannot. Use it to gate an automation on how high or low the sun actually is, like only closing the blinds while the sun sits low enough to cause glare.
Using this condition from the user interface
If you prefer building automations visually, Home Assistant walks you through this condition step by step. You pick what to check, tweak a few options, and save. No YAML knowledge required.
To use this condition in an automation:
- Go to Settings > Automations & scenes.
- Open an existing automation, or select Create automation > Create new automation.
- In the And if section, select Add condition.
- From the search box, search for and select Sun: Sun elevation.
- Under Threshold type, choose how the elevation is compared:
- Select Above or Below and enter an angle in degrees.
- Select In range and enter a lower and upper angle.
- Select Outside range and enter a lower and upper angle.
- For each option, you can enter a fixed angle in degrees, or reference a sensor entity or a number helper entity that holds the angle.
- Select Save.
Options in the UI
How the sun’s elevation is compared. Angles are in degrees, where 0° is the horizon, positive is above, and negative is below.
- Above (exclusive): passes when the elevation is strictly above the angle.
- Below (exclusive): passes when the elevation is strictly below the angle.
- In range (exclusive): passes when the elevation is strictly between the two angles.
- Outside range (inclusive): passes when the elevation is at or beyond either angle.
For each mode you can enter a fixed angle in degrees, or reference a sensor entity or a number helper entity.
Using this condition 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.
In YAML, refer to this condition as sun.elevation. A basic example looks like this:
condition: sun.elevation
options:
threshold:
type: below
value:
number: 4
This passes while the sun is below 4° of elevation, a common stand-in for “it is getting dark.”
Options in YAML
How the sun’s elevation is compared. Angles are in degrees.
-
type: above(exclusive): Passes when the elevation is strictly abovevalue. Providevaluewith anumberkey (a fixed angle in degrees) or anentitykey (aninput_number,number, orsensorentity). -
type: below(exclusive): Passes when the elevation is strictly belowvalue. Providevaluewith anumberkey (a fixed angle in degrees) or anentitykey (aninput_number,number, orsensorentity). -
type: between(exclusive): Passes when the elevation is strictly betweenvalue_minandvalue_max. Provide both, each with anumberkey (a fixed angle in degrees) or anentitykey. -
type: outside(inclusive): Passes when the elevation is at or beyondvalue_minorvalue_max. Provide both, each with anumberkey (a fixed angle in degrees) or anentitykey.
Good to know
- This condition does not use a target. It always checks the sun at your configured home location.
- A threshold around 0° corresponds roughly to sunrise and sunset. For those, Sun is up and Sun is set are simpler. Reach for Sun elevation when you need a specific angle.
- The maximum elevation the sun reaches depends on your latitude and the time of year, so pick angles the sun actually reaches at your location.
- When you use an entity as the threshold, its value is read at the moment the condition runs. It is not tracked continuously. Instead, the entity value is re-evaluated each time the automation fires.
Try it yourself
Ready to test this? Go to Settings > Automations & scenes, open an automation, and add this condition. Trigger the automation with and without the condition met, and watch whether it continues or stops.
More examples
Real scenarios where this condition gates an automation. Copy any example and adapt it to your setup.
You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the 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: close blinds only while the sun is low
When the patio is occupied, close the west-facing blinds, but only while the sun sits low in the sky (below 15° of elevation), where it causes the most glare.
- Trigger: Patio occupancy detected
- Condition: Sun: Sun elevation (below 15°)
-
Action: Close cover
- Target: West-facing blinds
YAML example for glare-based blinds
alias: "Close blinds against low sun"
triggers:
- trigger: state
entity_id: binary_sensor.patio_occupancy
to: "on"
conditions:
- condition: sun.elevation
options:
threshold:
type: below
value:
number: 15
actions:
- action: cover.close_cover
target:
entity_id: cover.west_blinds
Still stuck?
The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the condition you’re using and what you expected to happen, or share on our subreddit /r/homeassistant.
AI assistants like ChatGPT or Claude can also explain conditions or suggest the right one when you describe what you want in plain language.
Related conditions
These conditions work well alongside this one:
-
Sun is up: Tests if the sun is up.
-
Sun is set: Tests if the sun is set.
-
It is night: Tests if it is night.