Sun is up
The Sun is up condition passes when the sun is above the horizon at your location. Home Assistant works this out from your home location, so it stays accurate as sunrise and sunset shift through the seasons.
Use it to gate an automation so it only runs during daylight, like skipping the porch light when the sun is already up, or only watering the garden after the sun has risen.
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 is up.
- Select Save.
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. For how an automation is built in YAML, refer to Automations in YAML.
In YAML, put the settings that are specific to this condition under options. Keep target, if the condition uses one, and general settings such as alias and enabled at the top level, next to condition.
In YAML, refer to this condition as sun.is_up. It has no options:
condition: sun.is_up
This passes while the sun is above the horizon.
Good to know
- This condition does not use a target. It checks the sun at your configured home location.
- “Up” uses the same horizon definition as sunrise and sunset, so the condition flips at exactly those moments. For the opposite check, use Sun is set.
- This is a point-in-time check. It reflects whether the sun is up at the moment the automation runs, not whether it rose or set.
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. In the visual editor, select the UI options listed in the example or paste the YAML code.
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: only turn on the porch light after dark
When motion is detected at the front door, turn on the porch light, but only when the sun is down.
-
Trigger: State changed
- Entity: Front door motion sensor
- To: Detected
-
Condition: Not
- Condition: Sun is up
-
Action: Turn on light
- Target: Porch light
YAML example for motion lighting only after dark
alias: "Porch light on motion after dark"
triggers:
- trigger: state
entity_id: binary_sensor.front_door_motion
to: "on"
conditions:
- condition: not
conditions:
- condition: sun.is_up
actions:
- action: light.turn_on
target:
entity_id: light.porch
Still stuck?
To find out why the condition didn’t pass, check it live in the automation editor, and look at the trace of the run. 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 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
Explore related conditions:
-
Sun is set: Tests if the sun is set.
-
It is morning twilight: Tests if it is morning twilight, optionally of a specific type.
-
Sun elevation: Tests the sun’s elevation against a threshold you set.