I am trying to create a binary_sensor programmatically, by sending an autodiscovery payload (this is Node.js but the problem is the content of the payload and not the specific language)
I am not sure I understand how (or why) it is way off. The documentation that you mentioned (and that I used) list all elements as optional except state_topic - so why isn’t my definition transformed into a binary sensor?
Is there a mandatory entry I missed? Ore one that breaks the sensor?
The code I provided is TypeScript, what you are checking against a JSON validator is an object (dict in Python) that is serialized before being sent out (the JSON.stringify function).
You can see in the MQTT screenshot that what is sent is a proper JSON.
I’m not sure what your issue is: make sure the name (here, hello) is the same in the config topic and the JSON definition.
It’s not the name length either. Once I’d deleted the hello sensor (same unique_id!) and re-issued the command with the stupid long name in the config topic and the name field, that worked too: