It is night
The It is night condition passes during true darkness: when the sun is 18° or more below the horizon, the point where even astronomical twilight has ended and the sky is fully dark. Home Assistant works this out from your home location.
Use it when you want an automation to run only in the dead of night, not merely after sunset. For example, dim status lights to their lowest level, or run a stargazing scene that only makes sense once the sky is fully dark.
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: It is night.
- 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.
In YAML, refer to this condition as sun.is_night. It has no options:
condition: sun.is_night
This passes only while the sky is fully dark.
Good to know
- This condition does not use a target. It checks the sun at your configured home location.
- Night here means the sun is at or below -18° elevation (the end of astronomical twilight). This is stricter than Sun is set, which passes during twilight as well.
- At high latitudes in summer, the sun may never drop below -18°. On those days this condition never passes. The same can happen with Sun is set when the sun does not set at all.
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: dim the hallway night light in the dead of night
When motion is detected in the hallway during full darkness, turn the light on at a low brightness instead of full power.
- Trigger: Motion detected in the hallway
- Condition: Sun: It is night
- Action: Turn on the hallway light at 10% brightness
YAML example for a dim night light
alias: "Dim hallway light at night"
triggers:
- trigger: state
entity_id: binary_sensor.hallway_motion
to: "on"
conditions:
- condition: sun.is_night
actions:
- action: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 10
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 set: Tests if the sun is set.
-
It is evening twilight: Tests if it is evening twilight, optionally of a specific type.
-
It is morning twilight: Tests if it is morning twilight, optionally of a specific type.