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.

Yes, I figured when it didn’t work. The current setting I have is below in case anyone is looking for.

{% set now = as_timestamp(now()) %}
{% set after_dark = as_timestamp(state_attr('sun.sun', 'next_setting')) - 1800 %}
{% set before_bright = as_timestamp(state_attr('sun.sun', 'next_rising')) + 1800 %}
{% if (states('sun.sun') == 'below_horizon') %} 
  {{ true }}
{% else %}
  {{now <= before_bright or now >= after_dark}}
{% endif %}

Are you sure? Your before_bright variable will always be in the future because you’re setting it to the next time the sun rises plus 30 minutes. The means your template is equal to true if the sun is below the horizon or otherwise it is true because now is always before next time the sun rises plus 30 minutes.