Sync status of dropdowns to KNX System

I have an automation in which I react to status changes of dropdowns. I would now like to synchronise the status of the dropdown (e.g. input_select.lennard) to my KNX system. To do this, I must first check the status of the entity on the KNX bus and compare it to the value of my dropdown.
I have 6 entities (switches) and I have to find the right one. The entities all have the same structure e.g. ‘switch.lennard_schlafstatus’. In the example, the name lennard is the variable part that must be replaced according to the trigger of the automation.

Get the Status of Person XX from KNX:{% set knx = states(‘switch.XX_schlafstatus’) %}

Trigger (person) of the automation: {{trigger.entity_id.replace(‘input_select.’, ‘’)}}

  1. How can I replace XX in “switch.XX_schlafstatus” with the trigger entity_id in this statement to get the value of the switch?

  2. The values of the switch must then be mapped from 0 to “Zuhause” and 1 to “Schlafend” in order to compare the status on the KNX bus and the dropdown. How can I do this?

I’ve made quite a bit of progress, with the help of variables I’m now able to query the status of the switch. Now I just need to build the part to actually update the sleep status on the KNX bus if necessary.

choose:
  - conditions:
      - condition: trigger
        id:
          - Schlafend
          - Zuhause
    sequence:
      - variables:
          entity_name: "{{ trigger.entity_id.replace('input_select.', '') }}"
          knx_entity: "{{ 'switch.' + entity_name + '_schlafstatus' }}"
          knx_status: "{{ 'Zuhause' if is_state(knx_entity, 'off') else 'Schlafend' }}"
      - service: notify.mobile_app_thomas_iphone
        metadata: {}
        data:
          title: KNX Schlafstatus ermittelt
          message: >-
            Auf dem KNX Bus ist der Schlafstatus von {{ entity_name}} = {{
            knx_status }}