MQTT switch does not "Toggle"

Hi Guys,
I am new to HA, this is my first attempt at using it with a SONOFF switch and a raspberry Pi. OK, so I have
them all working with MQTT, node-RED and commands to turn on and off the SONOFF using HA Services,
turn_on and turn_off. However my UI switch, when I click on it, it only turns the SONOFF on, turns to the right
then shortly return left. When I click it again it does not turn the SONOFF off. In other words it does not act as
a toggle switch. I can turn the SONOFF on/off with node-RED injectors. How can I make it into a toggle switch?
This is how it is configured in HA:

switch:
  platform: mqtt
  name: "Living Room"
  state_topic: "home/sonoff/living_room/1/stat"
  command_topic: "home/sonoff/living_room/1"
  qos: 1
  payload_on: "on"
  payload_off: "off"
  retain: true

Thanks,
JE

It normally does this when it does not receive the MQTT message indicating the state has changed. Do you have the state_command correct? It looks like its missing an e off the end.

gpbenton, Thank you so much !!! That did it !!!
J

can you show your new code. I am having a similar problem and can’t seem to figure it out.

This is part of my configuration.yaml
Make sure that the topic in your .yaml matches with the Arduino code:
#define MQTT_TOPIC “home/sonoff/living_room/1”
#############################
switch lroom:
platform: mqtt
name: “Living Room”
state_topic: “home/sonoff/living_room/1”
command_topic: “home/sonoff/living_room/1”
qos: 0
payload_on: “on”
payload_off: “off”
optimistic: false
assumed_state: true
retain: true

automation lroom:
hide_entity: true
trigger:
platform: time
at: “19:10:00”
action:
service: homeassistant.turn_on
entity_id: switch.living_room