Sensor state in attribute templates

Is it possible to check sensor state in attribute templates?
For example after black out server was rebooted without internet connection

binary_sensor:
    platform: template
    sensors:
        my_sensor:
            value_template: >
                {% if states.sensor.sensor2.state == 'unknown' or 'unavailable' or 'null' or 'none' %}
                    {{ 'unknown' }}
                {% else %}
                    {% if states.sensor.sensor2.state|float == true %}
                        {{ true }}
                    {% else %}
                        {{ false }}
                    {% endif %}
                {% endif %}
            attribute_templates:
                my_attribute1: >
                    {% if states.sensor.sensor2.state != 'unknown' or 'unavailable' or 'null' or 'none' %}
                        {{ true }}
                    {% endif %}
                my_attribute2: >
                    {% if states.sensor.sensor2.state != 'unknown' or 'unavailable' or 'null' or 'none' %}
                        {{ true }}
                    {% endif %}

For value_template if working, but for attribute_templates in log i got error: “TemplateError(‘TypeError: ‘NoneType’ object is not iterable’) while processing template”

Try this:

binary_sensor:
  platform: template
  sensors:
    my_sensor:
      value_template: >
        {% if states('sensor.sensor2') in ['unknown', 'unavailable', 'null', 'none'] %}
          unknown
        {% else %}
          {{ states('sensor.sensor2') }}
        {% endif %}
      attribute_templates:
        my_attribute1: >
          {{ states('sensor.sensor2') not in ['unknown', 'unavailable', 'null', 'none'] }}
        my_attribute2: >
          {{ states('sensor.sensor2') not in ['unknown', 'unavailable', 'null', 'none'] }}

Not sure why you have two identical attributes.

They are not identical, it’s just for example.

Thank you. It works!