Let’s start with addressing the ridiculous number of brackets…
but also point out that this is the legacy template sensor, which you can still use, but should really be creating new sensors the new way.
template:
sensor:
- name: Front Door Status
unique_id: front-door-status-9ff7b07a-9d76-48aa-99f8-931126715014
state: >-
{% if is_state('lock.front_door','unlocked') and not is_state('binary_sensor.door_front_entry_window_door_is_open','open') %}
Unlocked
{% elif is_state('lock.front_door','locked') and not is_state('binary_sensor.door_front_entry_window_door_is_open','closed') %}
Open
{% elif is_state('lock.front_door','locked') and not is_state('binary_sensor.door_front_entry_window_door_is_open','open') %}
Unlocked
{% else %}
Unknown
{% endif %}
Additional errors were, trying to use state_attr to access the STATE of the entity, and not the attributes of the entity. The use of Capital letters (Locked, Unlocked, Open, Closed) which is how they are displayed in the UI but internally they are lowercase - (locked, unlocked, open, closed)
Now let’s look again at what you were trying to achieve:
state: >-
{% if is_state('lock.front_door','unlocked') %}
Unlocked
{% elif is_state('binary_sensor.door_front_entry_window_door_is_open','open') %}
Open
{% elif is_state('lock.front_door','locked') and is_state('binary_sensor.door_front_entry_window_door_is_open','closed') %}
Locked
{% else %}
Unknown
{% endif %}
If the front door is unlocked, it doesn’t matter about the state of the binary sensor - it’s unlocked.
If the binary sensor is open, it doesn’t matter about the state of the front door, it’s open.
If both the front door is locked and the binary sensor is closed, then it’s locked.
Hope that helps.
Those binary sensors, might need to be changed to on for open and off for closed, I’m not sure about that part.