If I understand you correctly, you want to switch on and off something using sms. If this is the case then you should delate all the sms from the phone used for this purpose.

A) I suggest you to use memory location "MT" instead of "ME"

Command : AT+CPMS=MT

B) list all sms contained in MT memory location with:

Command : AT+CMGL=0 - "list all received unread"
AT+CMGL=1 - "list all received read"
AT+CMGL=2 - "list all stored unsent"
AT+CMGL=3 - "list all stored sent"
AT+CMGL=4 - "list all sms present"

C) Delete all the MT memory location with:

Command : AT+CMGD=X " where X= sms number"

D) when phone memory location is clean than check the presence of new sms with :

Command AT^SMGR=1

phone answer will be different if sms is present or not, so act in function of the answer obtained. If not sms present delay for as long as you like and then read location again and so on.
If sms is present then decode it. Do the action required and then delete the sms with:

Command : AT+CMGD=1

and return enquiring for the presence of new sms.

Hope it will help.

Al.