I am able to publish auto discovered lights over MQTT but when I attempt to publish a switch it does not get discovered. I am publishing the following payload:
To recap, you’re using MQTT Discovery to create an MQTT Switch. You’re sending the following payload to this topic: homeassistant/switch/icue2mtt/icue_control/config
I don’t think so because a discovery message supports such a broad range of options that it can easily exceed 255 characters. Option names can be abbreviated but that’s a courtesy extended to devices that might have limited storage capacity:
Configuration variable names in the discovery payload may be abbreviated to conserve memory when sending a discovery message from memory constrained devices.
It even supports an abbreviation of the base topic (tilde is used like a variable):
A base topic ~ may be defined in the payload to conserve memory when the same topic base is used multiple times.
However, nowhere in the docs does it say the message must be <= 255 in length.
In this particular example, even if MQTT Switch supported JSON schema (like MQTT Light does), it lacks a state_value_template so it has no clue how to extract ON from {"state:"ON"}.
Thanks for the input. This is not a automation script but a C#.net MQTT client for exposing some functionality on a PC. I did realise I had made some assumptions and used a payload designed for a light as the model. I simplified my discovery payload to be:
{
"name":"iCue Control",
"unique_id":"icue_control",
"state_topic":"homeassistant/switch/icue2mtt/icue_control/state",
"command_topic":"homeassistant/switch/icue2mtt/icue_control/set"
}
It then discovered it. I changed the publish message sent in response to the state topic to simply return the string "ON" or "OFF" depending on the sate of the switch. It seems to work with some quircks:
* After toggling the switch from Home Assistant it jumps back to the original state after a few seconds and then after a bit longer it reverts back to the correct value
* The client seems to slow down home assistant. I am not sure if this could be addressed with the retain flags of QOS or some such