Auto-Discovery not working for binary_sensors

Hello,

I have created a python-script to parse my heating control and to publish the sensors to mqtt (published here in the community).

Unfortunately, it works only for sensors, not for binary sensors. The sensor is discovered:

2024-01-12 10:31:51.759 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.mqtt entity: binary_sensor.uvr_ta_designer_anf_kessel_zustand_ein_aus
2024-01-12 10:31:51.760 DEBUG (MainThread) [homeassistant.components.mqtt.discovery] Pending discovery for (‘binary_sensor’, ‘UVR_TA-Designer_binary_sensor_anf_kessel_zustand__ein_aus_’): deque([{‘device_class’: ‘power’, ‘name’: ‘anf_kessel_zustand__ein_aus_’, ‘state_topic’: ‘homeassistant/binary_sensor/UVR_TA-Designer/state’, ‘unit_of_measurement’: ‘On/Off’, ‘value_template’: ‘{{ value_json.anf_kessel_zustand__ein_aus_}}’, ‘unique_id’: ‘uvr_ta-designer_binary_sensor_anf_kessel_zustand__ein_aus_xxxzzzaaa’, ‘device’: {‘identifiers’: [‘uvr_ta-designerxxxzzzaaa’], ‘name’: ‘Uvr_ta-designer’}, ‘platform’: ‘mqtt’}])
2024-01-12 10:31:51.760 DEBUG (MainThread) [homeassistant.components.mqtt.discovery] Process discovery payload {‘device_class’: ‘power’, ‘name’: ‘anf_kessel_zustand__ein_aus_’, ‘state_topic’: ‘homeassistant/binary_sensor/UVR_TA-Designer/state’, ‘unit_of_measurement’: ‘On/Off’, ‘value_template’: ‘{{ value_json.anf_kessel_zustand__ein_aus_}}’, ‘unique_id’: ‘uvr_ta-designer_binary_sensor_anf_kessel_zustand__ein_aus_xxxzzzaaa’, ‘device’: {‘identifiers’: [‘uvr_ta-designerxxxzzzaaa’], ‘name’: ‘Uvr_ta-designer’}, ‘platform’: ‘mqtt’}
2024-01-12 10:31:51.760 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: binary_sensor UVR_TA-Designer_binary_sensor_anf_kessel_zustand__ein_aus_, sending update
2024-01-12 10:31:51.760 DEBUG (MainThread) [homeassistant.components.mqtt.mixins] Got update for entity with hash: (‘binary_sensor’, ‘UVR_TA-Designer_binary_sensor_anf_kessel_zustand__ein_aus_’) ‘{‘device_class’: ‘power’, ‘name’: ‘anf_kessel_zustand__ein_aus_’, ‘state_topic’: ‘homeassistant/binary_sensor/UVR_TA-Designer/state’, ‘unit_of_measurement’: ‘On/Off’, ‘value_template’: ‘{{ value_json.anf_kessel_zustand__ein_aus_}}’, ‘unique_id’: ‘uvr_ta-designer_binary_sensor_anf_kessel_zustand__ein_aus_xxxzzzaaa’, ‘device’: {‘identifiers’: [‘uvr_ta-designerxxxzzzaaa’], ‘name’: ‘Uvr_ta-designer’}, ‘platform’: ‘mqtt’}’
2024-01-12 10:31:51.760 DEBUG (MainThread) [homeassistant.components.mqtt.mixins] Ignoring unchanged update for: binary_sensor.uvr_ta_designer_anf_kessel_zustand_ein_aus

So, it should expect
{“anf_kessel_zustand__ein_aus_”: “1”} on homeassistant/binary_sensor/UVR_TA-Designer/state

But when I send data, I get:

2024-01-12 11:25:30.245 DEBUG (MainThread) [homeassistant.components.mqtt.models] Rendering incoming payload ‘{“anf_kessel_zustand__ein_aus_”: “0”}’
with variables {‘entity_id’: ‘binary_sensor.uvr_ta_designer_anf_kessel_zustand_ein_aus’, ‘name’: ‘anf_kessel_zustand__ein_aus_’, ‘this’: <template TemplateStateFromEntityId(binary_sensor.uvr_ta_designer_anf_kessel_zustand_ein_aus)>} and Template<template=({{ value_json.anf_kessel_zustand__ein_aus_}}) renders=12>
2024-01-12 11:25:30.245 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: binary_sensor.uvr_ta_designer_anf_kessel_zustand_ein_aus with state topic: homeassistant/binary_sensor/UVR_TA-Designer/state. Payload: ‘{“anf_kessel_zustand__ein_aus_”: “0”}’, template output: ‘0’, with value template ‘Template<template=({{ value_json.anf_kessel_zustand__ein_aus_}}) renders=13>’

What am I overlooking… I have spent hours already on it, but I fear I need an independent set of eyes…

Here a bit nicer formated, what I send:

'homeassistant/binary_sensor/UVR_TA-Designer_binary_sensor_anf_kessel_zustand__ein_aus_/config'
{"device_class": "power", "name": "anf_kessel_zustand__ein_aus_", "state_topic": "homeassistant/binary_sensor/UVR_TA-Designer/state", "unit_of_measurement": "On/Off", "value_template": "{{ value_json.anf_kessel_zustand__ein_aus_}}", "unique_id": "uvr_ta-designer_binary_sensor_anf_kessel_zustand__ein_aus_xxxzzzaaa", "device": {"identifiers": ["uvr_ta-designerxxxzzzaaa"], "name": "Uvr_ta-designer"}}

and

homeassistant/binary_sensor/UVR_TA-Designer/state

this payload:

{“vergl__2_status_wa___wb___diff”: 1.0, …, “anf_kessel_zustand__ein_aus_”: 0.0, “pumpe-hzkr_1_zustand__ein_aus_”: 1.0, “pumpe-hzkr_2_zustand__ein_aus_”: 0.0, …}

Greetings,
Hendrik

I finally found it:
the payload must be “on” or “off”.
I had tested that, but that was before I fixed another issue…