Create a derivative binary sensor [Solved]

Try this automation code-

trigger:
  - platform: state
    entity_id: group.living_room_windows
    to: 'on'
  - platform: state
    entity_id: person.your_name
    to: not_home
condition:
  - condition: state
    entity_id: person.your_name
    state: not_home
action:
  - repeat:
      until:
        - condition: state
          entity_id: group.living_room_windows
          state: 'off'
      sequence:
        - service: notify.mobile_app_your_name
          data:
            message: >-
              {% set x = expand('group.living_room_windows') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
              Alert! {{ x | join(', ') }} {{ 'are' if x | count > 1 else 'is' }} open in the living room.
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0

Alternative message YAML code (credit to Taras) to make the “comma” as well as “is” or “and” written correctly-

action:
  - repeat:
      until:
        - condition: state
          entity_id: group.living_room_windows
          state: 'off'
      sequence:
        - service: notify.mobile_app_your_name
          data:
            message: >-
              {% set windows = expand('group.living_room_windows') | selectattr('state', 'eq', 'on') | map(attribute='name') | list | join(", ") %}
              {% set x = ', and ' if windows.split(', ') | count > 2 else ' and ' %}
              Alert! {{x.join(windows.rsplit(', ', 1))}} {{'are' if windows.split(', ') | count > 1 else 'is' }} open in the living room.
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0