This snippet is for a helper that determines if it’s currently daytime based on the sun.
Create a new binary template helper and use this as your template:
{% set next_rising = as_local( as_datetime( state_attr('sun.sun', 'next_rising' ) ) ) %}
{% set next_setting = as_local( as_datetime( state_attr('sun.sun', 'next_setting' ) ) ) %}
{{
not (
next_rising.date() == now().date()
or next_setting.date().day == ( now() + timedelta(days=1) ).date().day
)
}}
I use sunrise and sunset for this helper, but you can also use dawn and dusk. Just replace next_rising
with next_dawn
and next_setting
with next_dusk
.
Since this helper is a sensor that changes based on the sun states, it can be used in automation triggers like turning on a porch light.
Leave a Reply to Getting the daily temperatures and precipitation from NWS forecasts in Home Assistant – Home Automation Lab Cancel reply