Manual/ Automatic mode. Ethernet+ sensor+ rele

I have Sensors and relays, and I want to have a website that has the possibility of putting in automatic or manual mode. The automatic mode functions with if condition (if less than X temperature turns on a relay) and the manual mode has to check the state of the relays and turned them on or off, also to see sensor values??. I have done both sides, but not as separate function so what I want is that when one mode is avtivated, the other one not works . I would greatly appreciate your help .

#include <math.h>
#include <Wire.h>
#include <SPI.h>
#include "EEPROM.h"  //libreria para poder escribir y leer en la memoria no volatil de Arduino
#define DS1307_I2C_ADDRESS 0x68
#include "RTClib.h" // Incluye la librería RTClib
RTC_DS1307 RTC; // Crea el objeto RTC
#include <SPI.h>  //Importamos librería comunicación SPI
#include <Ethernet.h>  //Importamos librería Ethernet
RTC_DS1307 Reloj;  
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };//Ponemos la dirección MAC de la Ethernet Shield que está con una etiqueta debajo la placa
IPAddress ip(192,168,1,177); //Asingamos la IP al Arduino
EthernetServer server(80); //Creamos un servidor Web con el puerto 80 que es el puerto HTTP por defecto

//Pin digitales asociados al Relé
int ReleVent = 2; //Pin digital donde conectamos el relé asociado al ventilador

int ReleLuz = 8; //Pin digital donde asociamos el relé asociado a la luz
int ReleAgua = 7; //Pin digital donde conectamos el relé asociado al agua

//Luminosidad
float luminosidad;
int SensorLuminosidad=3;
const int ValorLuminosidad = 50;

//Temperatura
float temperatura;
int a;
int B=3975;                  //B value of the thermistor
float resistencia;
const int ValorCalor = 27; //Valor temperatura superior límite para activar ventiladores

//Humedad
int SensorHumedad=1;
float humedad;
const int ValorHumedad = 20; //Valor temperatura superior límite para activar ventiladores


String estado="OFF"; //Estado del Led inicialmente "OFF"
String estado2="OFF";
String estado3="OFF";
 
//RELOJ
//Convierte numeros decimales a BCD (binario decimal codificado)
byte decToBcd(byte val)
{
 return ( (val/10*16) + (val%10) ); 
}
byte bcdToDec(byte val)
{
  return ( (val/10*16) + (val%16) );
}

float Time, minTime, maxTime;
const int minHourValue=9;
const int maxHourValue=22;
const int minMinuteValue=30;
const int maxMinuteValue=30;
void setDateDs1307(byte *second,
        byte *minute,
        byte *hour,
        byte *dayOfWeek,
        byte *dayOfMonth,
        byte *month,
        byte *year)
        {
//Resetea el registro puntero
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.write((byte)0);
          Wire.endTransmission();
          Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
          //Necesitan enmascarar porque ciertos bits son de control
          *second = bcdToDec(Wire.read() & 0x7f);
          *minute = bcdToDec(Wire.read());
          *hour = bcdToDec(Wire.read() & 0x3f);
          *dayOfWeek = bcdToDec(Wire.read());
          *dayOfMonth = bcdToDec(Wire.read());
          *month = bcdToDec(Wire.read());
          *year = bcdToDec(Wire.read());
        }

class myTimer{

private:
  static long segActual;    // Variable en la que se guarda en forma de segundos la hora actual para comparar con los objetos timer.
  long segEncendido;        // segundo del día en el que se enciende el timer. Las 00:00:00 == 0; las 00:01:00==60, las 23:59:59==86399.
  long segDuracion;         // segundos que durará encendido el relé correspondiente.

public:
  void setInicio(long hora, long minuto=0, long segundo=0){
    segEncendido=hora*3600+minuto*60+segundo;
  };
  void setDuracion(long horas, long minutos=0, long segundos=0){
    segDuracion=horas*3600+minutos*60+segundos;
  };
  static void setHora(long hora, long minuto, long segundo){
    segActual=hora*3600 + minuto*60 + segundo;
  };
  bool getActivado(void){
    long segDesdeEncendido = segActual-segEncendido;   //restamos el segundo del día de encendido
    Serial.print("Segundo actual: ");
    Serial.print(segActual);
    Serial.print(". Segundo de encendido: ");
    Serial.println(segEncendido); 
    if (segDesdeEncendido<0) segDesdeEncendido+=86400; // Si los segundos transcurridos son negativos sumamos un día, con lo que obtenemos los transcurridos desde el teórico encendido de ayer, que ya serán positivos.
    // Ya sólo queda comprobar que los segundos transcurridos sean menores a la duración de encendido del timer
    return (segDesdeEncendido<segDuracion);
  };
};
long myTimer::segActual=0;
myTimer tlluvia1,tlluvia2,tlluvia3,tlluvia4,tlluvia5,tlluvia6;
void setup()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Serial.begin(9600);
  Wire.begin();
  RTC.begin(); // Establece la velocidad de datos del RTC
  //byte second, minute, hour, dayOfWeek,dayOfMonth, month, year;
  pinMode(ReleAgua,OUTPUT); //Salida
  pinMode(ReleVent,OUTPUT); //Salida

  pinMode(ReleLuz,OUTPUT);
 
  // Inicializamos la comunicación Ethernet y el servidor
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print(F("server is at "));
  Serial.println(Ethernet.localIP());
 
 tlluvia1.setInicio(0,43,0);        //inicio a las 10:00:00
  tlluvia1.setDuracion(0,0,30);  
  //Duración 20 segundos
  tlluvia2.setInicio(0,44,0);           //inicio a las 12:00:00
  tlluvia2.setDuracion(0,0,20);     //Duración 20 segundos
  
  tlluvia3.setInicio(0,45);           //inicio a las 14:00:00
  tlluvia3.setDuracion(0,0,20);   //Duración 20 segundos
  /*
  tlluvia4.setInicio(22,32);           //inicio a las 16:00:00
  tlluvia4.setDuracion(0,0,20);     //Duración 20 segundos
  tlluvia5.setInicio(22,33);           //inicio a las 18:00:00
  tlluvia5.setDuracion(0,0,20);     //Duración 20 segundos
  tlluvia6.setInicio(22,34);           //inicio a las 20:00:00
  tlluvia6.setDuracion(0,0,20);     //Duración 20 segundos
*/
 
}
 
void loop()
{
  



  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  
DateTime now = Reloj.now();        //Obtiene la fecha y hora del RTC

  myTimer::setHora(now.hour(),now.minute(),now.second()); // Aquí le enviaríamos la hora obtenida de nuestro reloj.
   luminosidad = analogRead(SensorLuminosidad);
  luminosidad= (luminosidad)/10;
  a=analogRead(0);
  humedad=analogRead(SensorHumedad);
  humedad = (humedad)/10;
  resistencia=(float)(1023-a)*10000/a; //get the resistance of the sensor;
  temperatura=1/(log(resistencia/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
  //
 
   Serial.print("La Temperatura actual es "); // Nos escribe por el puerto serie la temperatura existente
  Serial.println(temperatura);
  Serial.print("La Humedad actual es (0-100%) "); // Nos escribe por el puerto serie la temperatura existente
  Serial.println(humedad);
   Serial.print("La Luminosidad actual es (0-100%) "); // Nos escribe por el puerto serie la temperatura existente
  Serial.println(luminosidad);
   delay(1000);
  
}
//MANUAL MODE
  EthernetClient client = server.available(); //Creamos un cliente Web
  //Cuando detecte un cliente a través de una petición HTTP
  if (client) {
    Serial.println(F("new client"));
    boolean currentLineIsBlank = true; //Una petición HTTP acaba con una línea en blanco
    String cadena=""; //Creamos una cadena de caracteres vacía
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();//Leemos la petición HTTP carácter por carácter
        Serial.write(c);//Visualizamos la petición HTTP por el Monitor Serial
        cadena.concat(c);//Unimos el String 'cadena' con la petición HTTP (c). De esta manera convertimos la petición HTTP a un String
       
         //Ya que hemos convertido la petición HTTP a una cadena de caracteres, ahora podremos buscar partes del texto.
         int posicion=cadena.indexOf("VENTILADOR="); //Guardamos la posición de la instancia "LED=" a la variable 'posicion'
 
          if(cadena.substring(posicion)=="VENTILADOR=ON")//Si a la posición 'posicion' hay "LED=ON"
          {
            digitalWrite(ReleVent,HIGH);
            estado="ON";
          }
          if(cadena.substring(posicion)=="VENTILADOR=OFF")//Si a la posición 'posicion' hay "LED=OFF"
          {
            digitalWrite(ReleVent,LOW);
            estado="OFF";
          }
          
 int posicion2=cadena.indexOf("LUZ="); //Guardamos la posición de la instancia "LED=" a la variable 'posicion'
 
          if(cadena.substring(posicion2)=="LUZ=ON")//Si a la posición 'posicion' hay "LED=ON"
          {
            digitalWrite(ReleLuz,HIGH);
            estado2="ON";
          }
          if(cadena.substring(posicion2)=="LUZ=OFF")//Si a la posición 'posicion' hay "LED=OFF"
          {
            digitalWrite(ReleLuz,LOW);
            estado2="OFF";
          }
          
 int posicion3=cadena.indexOf("RIEGO="); //Guardamos la posición de la instancia "LED=" a la variable 'posicion'
 
          if(cadena.substring(posicion3)=="RIEGO=ON")//Si a la posición 'posicion' hay "LED=ON"
          {
            digitalWrite(ReleAgua,HIGH);
            estado3="ON";
          }
          if(cadena.substring(posicion3)=="RIEGO=OFF")//Si a la posición 'posicion' hay "LED=OFF"
          {
            digitalWrite(ReleAgua,LOW);
            estado3="OFF";
          }

        //Cuando reciba una línea en blanco, quiere decir que la petición HTTP ha acabado y el servidor Web está listo para enviar una respuesta
        if (c == '\n' && currentLineIsBlank) {
 
            // Enviamos al cliente una respuesta HTTP
            client.println(F("HTTP/1.1 200 OK"));
            client.println(F("Content-Type: text/html"));
            client.println();
 
            //Página web en formato HTML
            client.println(F("<html>"));
            client.println(F("<head>"));
            client.println(F("</head>"));
            client.println(F("<body>"));
            client.println(F("<h1 align='center'>ADRIAN SANZ</h1><h3 align='center'>AUTOMATIZACION</h3>"));
            //Creamos los botones. Para enviar parametres a través de HTML se utiliza el metodo URL encode. Los parámetros se envian a través del símbolo '?'
            client.println(F("<div style='text-align:center;'>"));
            //boton Luz
            
            client.println(F("<button onClick=location.href='./?LUZ=ON\' style='margin:auto;background-color: #eb772a;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>"));
            client.println(F("ON"));
            client.println(F("</button>"));
            client.println(F("<button onClick=location.href='./?LUZ=OFF\' style='margin:auto;background-color: #eb772a;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>"));
            client.println(F("OFF"));
            client.println(F("</button>"));
            client.println(F("

"));
            client.println(F("<b>LUZ = "));
            client.print(estado2);
            
            //Boton Ventilador
             client.println(F("<button onClick=location.href='./?VENTILADOR=ON\' style='margin:auto;background-color: #84B1FF;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>"));
            client.println(F("ON"));
            client.println(F("</button>"));
            client.println(F("<button onClick=location.href='./?VENTILADOR=OFF\' style='margin:auto;background-color: #84B1FF;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>"));
            client.println(F("OFF"));
            client.println(F("</button>"));
            client.println(F("

"));
            client.println(F("<b>VENTILADOR = "));
            client.print(estado);
            
            //Boton Agua
             client.println(F("<button onClick=location.href='./?RIEGO=ON\' style='margin:auto;background-color: #29db85;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>"));
            client.println(F("ON"));
            client.println(F("</button>"));
            client.println(F("<button onClick=location.href='./?RIEGO=OFF\' style='margin:auto;background-color: #29db85;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>"));
            client.println(F("OFF"));
            client.println(F("</button>"));
            client.println(F("

"));
            client.println(F("<b>RIEGO = "));
            client.print(estado3);
            client.print(F("La humedad actual es "));
            client.print(humedad);
            client.print(F("La temperatura actual es "));
            client.print(temperatura);
            client.print(F("La luminosidad actual es "));
            client.print(luminosidad);
           
           
            client.println(F("</b>
"));
            client.println(F("</b></body>"));
            client.println(F("</html>"));
            break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    //Dar tiempo al navegador para recibir los datos
    delay(1);
    client.stop();// Cierra la conexión
  }

  
  //AUTOMATIC MODE
  
  
  if (tlluvia1.getActivado()) {
    digitalWrite(ReleAgua,HIGH);
  }
else{
    digitalWrite(ReleAgua,LOW);
}
 if (tlluvia2.getActivado()) {
    digitalWrite(ReleAgua,HIGH);
  }
else{
    digitalWrite(ReleAgua,LOW);
}
 if (tlluvia3.getActivado()) {
    digitalWrite(ReleLuz,HIGH);
  }
else{
    digitalWrite(ReleLuz,LOW);
}

//

   if (temperatura > ValorCalor)
  {
    digitalWrite (ReleVent,HIGH); //Se activa el relé del ventilador (4) cuando temperatura > 26 grados
  }
  else
  {
  digitalWrite (ReleVent,LOW); //Se desactiva el relé del ventilador (4) cuando la temperatura < 26 grados
  }
  if (humedad < ValorHumedad)
  {
    digitalWrite (ReleAgua,HIGH); //Se activa el relé del agua (2) cuando humedad < 40
  }
  else
  {
    digitalWrite (ReleAgua,LOW); //Se desactiva el relé del agua
  }
  
  
}

I'm not going to piece together code splattered over three posts. Post ALL of your code as an attachment.

The code does something. Don't expect us to guess what it actually does.

You want it to do something. All we can surmise now is that what it does is not what you want. Don't expect us to guess. Define clearly what the code does that you don't want or doesn't do that you do want.