Binary sensor and availability

I like to create a binary sensor where the availability is set depending on another entity

- binary_sensor:
    - unique_id: "b_700_close_cover_garden"
      availability: >-
        {% if (is_state('cover.velux_cover_garden', 'open') or is_state('cover.velux_cover_garden', 'closed')) and
              ((state_attr('cover.velux_cover_garden', 'current_position') | int(100)) > 0) %}
          True
        {% else %}
          False
        {% endif %}
      icon: mdi:arrow-down-bold-box-outline
      state: >
        {% if (is_state('cover.velux_cover_garden', 'open') or is_state('cover.velux_cover_garden', 'closed')) and
              ((state_attr('cover.velux_cover_garden', 'current_position') | int(100)) > 0) %}
          True
        {% else %}
          False
        {% endif %}
      attributes:
        friendly_name: "B-700: Close Cover Garden"
        cover_state: >
          {{ states('cover.velux_cover_garden') | title }}

    - unique_id: "b_701_open_cover_garden"
      icon: mdi:arrow-up-bold-box-outline
      state: >
        {% if (is_state('cover.velux_cover_garden', 'open') or is_state('cover.velux_cover_garden', 'closed')) and
              ((state_attr('cover.velux_cover_garden', 'current_position') | int(100)) < 100) %}
          True
        {% else %}
          False
        {% endif %}
      availability: >
        {% if (is_state('cover.velux_cover_garden', 'open') or is_state('cover.velux_cover_garden', 'closed')) and
              ((state_attr('cover.velux_cover_garden', 'current_position') | int(100)) < 100) %}
          True
        {% else %}
          False
        {% endif %}
      attributes:
        friendly_name: "B-701: Open Cover Garden"
        cover_state: >
          {{ states('cover.velux_cover_garden') | title }}

Now my problem is that the first sensor is created, the second not. The second is only created if I either comment out the “availability” part or use the same as in the first sensor. However the only difference is that either a > 0 or a < 100 is used. The > 0 is working, the < 100 for some reason not. Does anybody know why this does not work?
P.S. I use the same code for the state, and there it works for both sensors.

You have more issues than that.

Your availability template is the same as your state template. So your binary sensor will only ever be on or unavailable. You will never see the off state.

When do you actually want the binary sensor to be unavailable?

Thanks for the answer… I managed it now with your answer.

Could you share your final solution?

There are other optimisations you can do. e.g. instead of a template like this:

      state: >
        {% if (is_state('cover.velux_cover_garden', 'open') or is_state('cover.velux_cover_garden', 'closed')) and
              ((state_attr('cover.velux_cover_garden', 'current_position') | int(100)) > 0) %}
          True
        {% else %}
          False
        {% endif %}

You can do:

      state: >
        {{ has_value('cover.velux_cover_garden') and
           state_attr('cover.velux_cover_garden', 'current_position') | int(100) > 0) }}

I don’t need a solution, I didn’t use the sensor anymore. However I can use the hints you gave in my other sensors