It is midnight sun

The It is midnight sun condition passes during the midnight sun, the part of the year at high latitudes when the sun stays above the horizon for a full 24 hours and never sets. Home Assistant works this out from your home location.

Use it to adapt automations that normally rely on the sun setting. For example, keep blackout blinds closed at night through the bright season, or skip an automation that only makes sense once it gets dark outside.

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:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation, or select Create automation > Create new automation.
  3. In the And if section, select Add condition.
  4. From the search box, search for and select It is midnight sun.
  5. 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_midnight_sun. It has no options:

ConditionConditions are an optional part of an automation that will prevent an action from firing if they are not met. [Learn more]
condition: sun.is_midnight_sun

This passes only while the sun stays above the horizon around the clock.

Good to know

  • This condition does not use a target. It checks the sun at your configured home location.
  • The midnight sun only happens at high latitudes, roughly above the polar circles, during the local summer. Away from the poles, this condition never passes.
  • This condition follows the sun’s daily low, at solar midnight: it passes while that midnight low stays above the horizon, and turns off at the solar midnight when the low drops below it again. On a full midnight-sun day the sun never crosses the horizon, so Sunrise and Sunset do not fire and It is night does not pass.
  • On the day the midnight sun ends, the sun can briefly dip below the horizon around midnight before the condition turns off at solar midnight.
  • For the opposite time of year, when the sun stays below the horizon all day, use It is polar night.

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.

Tip

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: keep the bedroom dark during the midnight sun

When it is bedtime during the midnight sun, close the bedroom blackout blinds so the room stays dark even though the sun is still up.

  • Trigger: Time is 10:00 PM
  • Condition: It is midnight sun
  • Action: Close cover
    • Target: Bedroom blackout blinds
YAML example for closing blinds during the midnight sun
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Close blackout blinds during the midnight sun"
triggers:
  - trigger: time
    at: "22:00:00"
conditions:
  - condition: sun.is_midnight_sun
actions:
  - action: cover.close_cover
    target:
      entity_id: cover.bedroom_blackout_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.

Tip

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: