Is there a more elegant way to format this?

As a relative newbie and non-programmer I hammered out this value_template for a binary_sensor. It works well but looks like a big run-on sentence. Is there a way to format it in an easier to read indented stack? Thanks.

  sensors:
    day_night:
      value_template: "{{ ((state_attr('sun.sun', 'elevation') | float > 0) and (state_attr('sun.sun', 'rising') == true)) or ((state_attr('sun.sun', 'elevation') | float > -5) and (state_attr('sun.sun', 'rising') == false)) }}"

PS, the intent is to turn on a helper at 0° sun angle in the morning and turn it off at -5° at night.

  sensors:
    day_night:
      value_template: >-
         "{{ ((state_attr('sun.sun', 'elevation') | float > 0) and (state_attr('sun.sun', 'rising') == true)) or 
             ((state_attr('sun.sun', 'elevation') | float > -5) and (state_attr('sun.sun', 'rising') == false)) }}"

Would something like this make it more readable for you?

I prefer to set variables if I’m using something multiple times:

{% set rising = is_state_attr('sun.sun', 'rising', 'true') %}
{% set elevation = state_attr('sun.sun', 'elevation') | float(0) %}
{{ (elevation >= 0 and rising) or (elevation > -5 and not rising) }}

So to do it this way, is this how I would need to format it?

- platform: template
  sensors:
    day_night:
      {% set rising = is_state_attr('sun.sun', 'rising', 'true') %}
      {% set elevation = state_attr('sun.sun', 'elevation') | float(0) %}
      {{ (elevation >= 0 and rising) or (elevation > -5 and not rising) }}

You should be using the current template format instead of the legacy format.

template:
  - binary_sensor:
      - name: "Day Night"
        state: >
          {% set rising = is_state_attr('sun.sun', 'rising', 'true') %}
          {% set elevation = state_attr('sun.sun', 'elevation') | float(0) %}
          {{ (elevation >= 0 and rising) or (elevation > -5 and not rising) }}
        availability:  "{{ state_attr('sun.sun', 'elevation') | is_number }}"

This will create a sensor binary_sensor.day_night which will have the state on during your defined day time and off at night.