MQTT Switch with multiline state_on and state_off

I am connecting my Nissan LEAF to Home Assistant through MQTT (OVMS v3). The climate controls work by sending console commands to a “command” topic and responses come from a “respose” topic. The complication is that the response is a multiline response. I got my yaml code from here, and I assume it works for the author, but I can’t get it to work. The YAML seems to match the string in MQTT. Are there any debug tools I can use to see what it is HA is seeing?

Config:

mqtt:
  switch:
  - name: Leaf Climate Conrol
    qos: 1
    command_topic: "ovms/mqttuser/STICKY/client/home-assistant/command/1"
    state_topic: "ovms/mqttuser/STICKY/client/home-assistant/response/1"
    state_on: |
      Climate Control
      on

    state_off: |
      Climate Control
      off

    payload_on: "climatecontrol on"
    payload_off: "climatecontrol off"

MQTT transactions:

ovms/mqttuser/STICKY/client/home-assistant/command/1 climatecontrol off
ovms/mqttuser/STICKY/client/home-assistant/response/1 Climate Control 
off

ovms/mqttuser/STICKY/event clock.2231

(I included the 'clock` event to show there are two carriage returns after the response)

I expect the switch state to be set to “Off” when the response topic is sent. Instead it always shows state “Unknown.”

What is wrong here?

Ugh, thanks emacs.

Turns out there’s a trailing space in the message, and I have configured emacs (text editing program) to remove trailing spaces when saving (because usually that’s AWESOME). This also explains why the original author’s version would work.

Here’s the fixed config:

mqtt:
  switch:
  - name: Leaf Climate Control
    qos: 1
    command_topic: "ovms/mqttuser/STICKY/client/home-assistant/command/1"
    state_topic: "ovms/mqttuser/STICKY/client/home-assistant/response/1"
    state_on: "Climate Control \non\n"
    state_off: "Climate Control \noff\n"

    payload_on: "climatecontrol on"
    payload_off: "climatecontrol off"

Now to talk with the OVMS developers to see why in the world they thought newlines and trailing spaces are a good idea…

For anyone trying to do this, I’ve uploaded my full configs to github: