Switch State Not Working

Hi, I’m new to HA and trying to configure a light with an ESP8266 through MQTT.
My configuration is below. light on/off works fine. But after I switch it on, switch doesn’t stay on in HA web ui. It goes back to off after a second.
My ESP is sending either “on” or “off” to the state topic when switch is toggled. I’m not sure what is wrong here.
Can anyone help me here please?

light 6:
platform: mqtt
name: “Front Yard Light”
state_topic: “frontYardLight_2BEF4D/state”
command_topic: “frontYardLight_2BEF4D/rpc”
payload_on: “{method:“Control”,args:{state:1}}”
payload_off: “{method:“Control”,args:{state:0}}”

If the light turns on and then off again then you know the ESP is subscribed to the command_topic. My first guess would be the ESP code isn’t updating the state.

My MQTT light object looks like this:

  - platform: mqtt_json  
    name: "Office LED"  
    state_topic: "ntalekt/sensornode1"  
    command_topic: "ntalekt/sensornode1/set"  
    brightness: true  
    flash: true  
    rgb: true  
    optimistic: false  
    qos: 0

This indicates that HA did not receive the ‘state_topic’ message and payload to indicate the light had actually switched.

Then you should have

   payload_on: on
   payload_off: off

There seems to be a limitation that the command topic and state topic have to send the same payload, so I’m not sure what you are using as a payload is going to work.

Can you explain what you are doing with that payload, it does seem interesting.

Hi, yes, this is a new POC i’m trying with Mongoose OS. You can read it out. It seems to be so easy to get a ESP8266 to flash with it and control remotely, like logs, OTA etc through RPC calls. This payload you see is an RPC call to my ESP to control one GPIO pin.

what i understood from your answer is that the payload and state should be same for HA to work properly. I’ll try to change my config that way. Thank you very much for your reply.

Actually I tested the state queue and i can see messages are coming up the expected way. may be as gpbenton mentioned the value itself is not right and it should be same as payload?

This worked after I change the values. Thank you so much!!! :slight_smile:

1 Like