How to convert an 3 state Homematic window sensor into 2 state binary_sensor?

Hi,
I get crazy to modify a Homematic window Sensor Typ HM-Sec-RHS-2 into a binary sensor.
I think I need to do so that I can use it in my sensor group.
I tried already

but I get no state. I think is is related that the HM Sensor can have 3 state.
0 = CLOSED should be OFF
1 = TILTED should be ON
2 = OPEN should be ON

Can someone guide me how to modify this?

in the meantime I tried several codes, still no success.
Below 2 Ideas, has nobody a hint for me?

template:
  - binary_sensor:
      - name: Balkontuer_Drehgriffsensor
        state: >
          {{ is_state('sensor_wz_terrassentuer.CLOSED', "off")
             or is_state('sensor_wz_terrassentuer.tilted', "on")
             or is_state('sensor_wz_terrassentuer.OPEN', "on") }}

- platform: template
  sensor:
      - friendly_name: Balkontuer_Drehgriffsensor
        value_template  "{% if is_state('sensor_wz_terassentuer', 'CLOSED') %}off
                         {% elif is_state('sensor_wz_terrassentuer', 'TILTED') %}on
                         {% elif is_state('sensor_wz_terrassentuer', 'OPEN') %}on       
                         {% endif %}"

I don’t know where you find your coding samples, but that should work:

{{ not is_state('sensor.wz_terrassentuer', "CLOSED") }}

Hi, I entered in /config/configuration.yaml

template:
  - binary_sensor:
      - name: Balkontuer_Drehgriffsensor
        state: >
          {{ not is_state('sensor.wz_terrassentuer', "CLOSED") }}

It doesn matter if the window is open or closed, I get always “True” in the Template Editor or “on” in Zustand

Try ´closed´ (lowercase)

Hi, I entered in /config/configuration.yaml

template:
  - binary_sensor:
      - name: Balkontuer_Drehgriffsensor
        state: >
          {{ not is_state('sensor.wz_terrassentuer', "closed") }}

still no change. I get from sensor.wz_terassentuer CLOSED or OPEN but the binary_sensor.balkontuer_drehgriffsensor stay always at “on”

This is working code from my environment:

template:
  - name: Türgriffkontakt KU
    unique_id: "tuergriffkontakt_ku"
    device_class: "door"
    state: >
      {{ not is_state('sensor.turgriffkontakt_ku', 'closed') }}

Replace “closed” with the relevant return type of your sensor.

Hi, finally it works with

template:
  - binary_sensor:
      - name: Balkontuer_Drehgriffsensor
        state: >
          {{ not is_state('sensor.wz_terassentuer_state', "CLOSED") }}

thanks for you patience :slight_smile: