I have a bit sensor whose template is as below. However, it is returning as false even if I have verified the template to return true in developer tools.
Can someone help what I am doing wrong?
>-
{% set after_sunset = as_timestamp(state_attr('sun.sun', 'next_setting')) + 1800 %}
{% set before_sunrise = as_timestamp(state_attr('sun.sun', 'next_rising')) - 1800 %}
{% set now = as_timestamp(now()) %}
{{ after_sunset <= now or now <= before_sunrise }}
By definition, the attributes next_setting and next_rising are always in the future.
So after_sunset <= now is always false because either it is before today’s sunset or because it is after today’s sunset, when next_setting will be sometime tomorrow.
Also, now <= before_sunrise will always be true except for the 30 minutes before sunrise since you subtracted 1800 from next_rising.