New window sensor via mqtt

Hi all,
I have a window open/close sensor which sends data via mqtt.
The topic for this sensor is “shellies/shellydw2-bad/sensor/state” which can be close or open.
My idea was to create a helper whithin devices. So I now have a binary sensor template that looks like this:

mqtt:
  - sensor:
    state_topic: "shellies/shellydw2-bad/sensor/state"
    payload_on: "open"
    payload_off: "close"

But something is wrong, the sensor stays in closed status all the time. I see in mqtt explorer that the topic is updating. (The show as option is window, therefore it is shown as closed i guess instead of on off)

so seems I found a problem, this works now:

mqtt:
  - binary_sensor:
      name: "Badfenster Kontakt"
      device_class: "window"
      state_topic: "shellies/shellydw2-bad/sensor/state"
      payload_on: "open"
      payload_off: "close"

I put it in confuguration.yaml. Can someone explain the difference between putting it there and creating a helper in the gui? The problem was the indentation.

I don’t think you can create a mqtt sensor with a helper, only template sensors.