Need help in Troubleshooting code!

What i want to do is monitor state of pin 7 when pinstate is high i will serially give command to on/off led on pin 13.
I give High to pin 7 from +5V pin that is why its configured as input.
To on led i enter "#A.on*"
To off led i enter "#A.off*"

I have added here1,2,3,4,5... to track execution of code.

The pin state detection is working and if i first give command to ON led it glows if i give OFF then it remains off.
Now the problem is it only works for 1st command then not. if i give ON first after it even if i give OFF command it will go through HERE1 loop and not turn off. Likewise if i first OFF it after it will not glow even if the command is of ON it will go through HERE5 loop.

I think maybe problem is with temp,

#define led 13
int temp = 0, i = 0;
char str[15];
int pinstate = 0;
int lastpinstate = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(7, INPUT);
  digitalWrite(13, HIGH);
  delay(3000);
  digitalWrite(13, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  pinstate = digitalRead(7);
  if (pinstate != lastpinstate)
  {
    if (digitalRead(7) == HIGH)
    {
      Serial.println("Pinstate High");
      if (temp == 0)
      {
        serialEvent();
        temp = 0;
        i = 0;
        Serial.println("Here2");
        delay(1000);
      }

    }
    else
    {
      Serial.println("Pinstate Low");
    }
  }
  lastpinstate = pinstate;
}

void serialEvent()
{
  while (Serial.available())
  {
    if (Serial.find("#A."))
    {
      delay(1000);
      while (Serial.available())
      {
        char inChar = Serial.read();
        str[i++] = inChar;
        if (inChar == '*')
        {
          check();
          temp = 1;
          return;
        }
      }
    }
  }
}

void check()
{
  Serial.println("Here3");
  if (!(strncmp(str, "on", 2)))
  {
    Serial.println("Here1");
    digitalWrite(13, HIGH);
    delay(200);
  }

  else if (!(strncmp(str, "off", 3)))
  {
    Serial.println("Here5");
    digitalWrite(13, LOW);
    delay(200);
  }
}

DG123:
I give High to pin 7 from +5V pin that is why its configured as input.

So how are you giving it LOW when the button or whatever is "off"?

  while (Serial.available())

{
    if (Serial.find("#A."))

This isn't going to work very well. If any serial character arrives, then it will wait for up to a second to see if it is followed by "#A." Having your sketch stop working for that amount of time is going to be a problem.

Look for "Serial input basics" for a better solution to parse commands.

why do you call serialEvent() yourself? This is called automatically for you at the end of every loop(). Not very robust either

How is your serial console configured? Are you sending CR and LF ?

What i want to do is monitor state of pin 7 when pinstate is high i will serially give command to on/off led on pin 13.

What, exactly, are you sending serial data to, that is going to off the LED on pin 13?

How do you plan to off the LED? Supply it with 80A of current because you failed to use a current limiting resistor?