I want to on and off the pin using sensor value and wifi esp8266

i want to on and off the pin using sensor value.if sensor value high relay pin/valve should on. but if we send on command from wifi it should on the relay even though the sensor value is low.

i have written code but when im making on from wifi module while sensor is high . after few seconds it goes off

code/sketch
#include "SoftwareSerial.h"
#include <SPI.h>
//#define digmoisturePin 52
#define digmoisturePin 11
SoftwareSerial esp(8,9);

int relay = 6;
int number = 1 ;
void setup() {
esp.begin(9600);
esp.println("AT+CWMODE=3");
delay(50);
if (esp.find("OK"))
{
Serial.println("MODE 3 ACTIVATED");
}
else{
Serial.println("NOT ACTIVATED");
}
// }
//MULTIPLE CONNECTIONS//
esp.println("AT+CIPMUX=1");
delay(500);
if (esp.find("OK"))
{
Serial.println("tcp initiated");
}
//HTTP PORT //
esp.println("AT+CIPSERVER=1,80");
delay(500);
if (esp.find("OK"))
{
Serial.println("ok");
}
else {
Serial.println("denied");
}
pinMode(relay, LOW);
Serial.begin(9600);
esp.begin(9600);
// setting the led pins to outputs
pinMode(digmoisturePin, INPUT);

// setting the relay pin to outputs
pinMode(relay, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
Serial.println(esp.read());
Serial.println(esp.read());
if(esp.available() > 0)
{
delay(2000);
wifiControl();

}
else
{
//Serial.println(esp.read());//-1

}
Serial.println("Read");
if(digitalRead(digmoisturePin) == HIGH){
Serial.println("1");
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
delay(1000);
}
else {

Serial.println("0");
pinMode(relay, OUTPUT);
delay(1000);

String incomingByte1=esp.readString();
int SemicolonPosition1 = incomingByte1.indexOf(':');
if(incomingByte1.charAt(SemicolonPosition1 + 2) == 'N' ||incomingByte1.charAt(SemicolonPosition1 + 2) == 'n')
{
//number=2 ;
Serial.println("inner loop ON");
Serial.println(esp.read());
digitalWrite(relay, HIGH);
}
else
{

digitalWrite(relay, LOW);

}
delay(1000);

}
}
void wifiControl()
{

if (esp.available() > 0) {

// String incomingByte = esp.readString();
String incomingByte=esp.readString();

int SemicolonPosition = incomingByte.indexOf(':');
//Serial.println(spacePosition);
if (incomingByte.charAt(SemicolonPosition + 2) == 'N') {
enter code here Serial.println("Valve switched ON");
digitalWrite(11,LOW);
digitalWrite(relay,HIGH);
esp.println("AT+CIPSEND=0,8");
esp.println("WATER ON");
Serial.println("ten sec delay");
delay(10000);
}
if (incomingByte.charAt(SemicolonPosition + 2) == 'F') {
Serial.println("Valve Switched OFF");
digitalWrite(relay,LOW);
digitalWrite(11,HIGH);
esp.println("AT+CIPSEND=0,9");
delay(1000);

}
delay(1000); // delay 1 second between reads
}
}

attached code

post_sample_wifi_smart_garden.ino (2.76 KB)