Bit sensor not returning true even when template returns true

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 }}

Figured out that I shouldn’t prefix with “>-”

What does this supposed to do exactly? What are you trying to accomplish?

true if time is between sunset+30 mins and sunrise-30, false otherwise.

But figured that I shouldnt be starting with >- in the template

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.