Skip to main content

๐ŸŒ Solar

The solar extension exists to make it easy to perform time math with reference points for the sun. It uses lat/long provided by Home Assistant, updating reference points nightly with the Scheduler.

๐ŸŒ… Reference Pointsโ€‹

NameDescription
dawnMarks the time when morning twilight begins, just before the sunrise.
sunriseEndIndicates the end of the sunrise, when the sun is fully above the horizon.
sunsetStartRepresents the start of the sunset, when the sun begins to descend below the horizon.
duskSignifies the end of the evening twilight, just after the sunset.
nightStartMarks the beginning of astronomical night, when the sun is sufficiently below the horizon.
nightEndIndicates the end of astronomical night, just before the beginning of morning twilight.
sunriseThe moment the upper edge of the sun appears on the horizon in the morning.
sunsetThe moment the upper edge of the sun disappears below the horizon in the evening.
solarNoonThe time when the sun reaches its highest point in the sky for the day, directly above the observer.

๐ŸŒž Usageโ€‹

Gathering reference pointsโ€‹

function whenIsDawn() {
return `dawn is at ${automation.solar.dawn.format("hh:mm")}`;
}

Quick mathโ€‹

Similar to working with automation.time, solar makes a few functions available for testing reference points.

function isDaytime() {
return automation.solar.isBetween("dawn", "dusk");
}

Attaching to eventsโ€‹

You can also use reference points as events!

automation.solar.onEvent({
context,
eventName: "dawn",
exec() {
logger.info("It is dawn!");
}
});

With offsetsโ€‹

solar.onEvent can take in offset times in a variety of formats:

FormatDescription
numberms
tuple[quantity, unit]
stringISO 8601 partial duration string: (#H)(#M)(#S)
objectmapping of units to quantities
Durationdayjs.duration object
functiona function that returns any of the above
automation.solar.onEvent({
eventName: "dawn",
offset: "2h10m",
exec: () => logger.info("2 hours 10 mins after dawn")
});
automation.solar.onEvent({
eventName: "dusk",
offset: "-15m",
exec: () => logger.info("15 mins before dusk")
});

Using a function, you can provide a different offset every day

automation.solar.onEvent({
eventName: "dusk",
offset: () => Math.floor(Math.random() * HOUR),
exec: () => logger.info("within an hour after dusk")
});