MQTT Switch doesn't stay on

my MQTT switch (servo blinds) doesn’t stay “ON” even payload and state are the same (chcecked by subcsribing to state topic).
Here is part of my comfig-yaml:

switch 2:  
      platform: mqtt
      name: "Blinds"
      state_topic: "blinds/state"
      command_topic: "blinds/command"
      payload_on: "open"
      payload_off: "close"
      optimistic: false
      qos: 1
      retain: true

I am using this code:

Code is working fine but my switch can only open blinds. I have to close them using Developeer Tools–>Services. Only change I made is rename states from opened–>open and closed–>close

Any idea?

Thank you.


You need to change this to “open” to match the payload_on parameter.

Also, you need to remove the quotes from the payload_on and payload_off parameters.

Hmm why do you say that the payload_on/off need the quotes removing? I’ve always used quotes on mine and they have always worked fine, also every example in the docs have the quotes. Is there some change I’m not aware of?

I already changed it:

   void servo_move() {
  Serial.println("State Change. Rotating Servo");
  if ( dirc == 180) {
  else if (dirc == 0) {

And I removed quotes from my yaml file. It didnt help.

Any other suggestions?

Thank you.

Next problem I see is that

const char* topic_state = "/blinds/state";

does not match

      state_topic: "blinds/state"

The first ‘/’ is significant.

1 Like

If it works for you, then maybe I’m wrong. But I never have, and I had some problem with them in.

That was it!
Thank you very much!

OK :slight_smile: , the only problems I’ve had with payload is when I’ve used a different case between HA and the Arduino.