Comparing up to 4 numbers if conditions are met

Right now I have the following algorithm which is obviously not good enough for what I need.

I need that referenceTemp to take the value of the smallest temperature in any of the ENABLED rooms and only if none of the rooms are enabled then the reference temp can take the value of temp.

Can someone give me some guidance, please? I cannot figure out the algorithm.

      case 2: { // Item 2
        Serial.println("Multiple Rooms Mode is selected");
        //referenceTemp = temp; // temporary unavailable
        // check if any of the selected temperatures is bellow the tempset
        if (EnableLocal == 1){
          Serial.println("Local is Enabled");
              if (temp <= bottomTreshold){
                referenceTemp = temp; 
                Serial.println("Local referenceTemp= " + String(referenceTemp));
              }          
        }
        if (EnableRoom1 == 1){
          Serial.println("Room 1 is enabled");
          if (room1Status == 1)
            {
              if (room1Temp <= bottomTreshold){
                referenceTemp = room1Temp; 
                Serial.println("Room1 referenceTemp= " + String(room1Temp));
              }        
            }     
        }
        if (EnableRoom2 == 1){
          Serial.println("Room 2 is enabled");
          if (room2Status == 1)
            {
              if (room2Temp <= bottomTreshold){
                referenceTemp = room2Temp;
                Serial.println("Room2 referenceTemp= " + String(room2Temp)); 
              }        
            } 
        }
        if (EnableRoom3 == 1){
          Serial.println("Room 3 is enabled");
          if (room3Status == 1)
            {
              if (room3Temp <= bottomTreshold){
                referenceTemp = room3Temp;
                Serial.println("Room3 referenceTemp= " + String(room3Temp)); 
              }        
            } 
        }

        break;
      }

why not use a for loop to check if a room is enabled and w/in the lop check status and threshold?

Can you give me an example, please? I cannot understand exactly how can I exclude the disabled rooms from the comparison.

I need the referenceTemp to take the value of the smallest enabled temp (temp, room1Temp,room2Temp,room3Temp,room4Temp) and if none are enabled or with the status ==1, then take the Local value (which is temp).

case 2:
{ // Item 2
  // I need that referenceTemp to take the value of the smallest temperature in any of the ENABLED
  // rooms and only if none of the rooms are enabled then the reference temp can take the value of temp.


  if (!EnableLocal && !EnableRoom1 && !EnableRoom2 && !EnableRoom3)
  {
    Serial.println("No rooms enabled.");
    referenceTemp = temp;
  }
  else // At lest one room is enabled
  {
    boolean enabledRoomFound = false;


    Serial.println("Multiple Rooms Mode is selected");


    if (EnableLocal) {
      Serial.println("Local is Enabled");
      referenceTemp = localTemp;
      enabledRoomFound = true;
      Serial.print("Local referenceTemp= ");
      Serial.println(referenceTemp);
    }


    if (EnableRoom1)
    {
      Serial.println("Room 1 is enabled");
      if (!enabledRoomFound || room1Temp < referenceTemp)
      {
        referenceTemp = room1Temp;
        enabledRoomFound = true;
        Serial.print("Room1 referenceTemp= ");
        Serial.println(referenceTemp);
      }
    }


    if (EnableRoom2)
    {
      Serial.println("Room 2 is enabled");
      if (!enabledRoomFound || room2Temp < referenceTemp)
      {
        referenceTemp = room2Temp;
        enabledRoomFound = true;
        Serial.print("Room2 referenceTemp= ");
        Serial.println(referenceTemp);
      }
    }


    if (EnableRoom3)
    {
      Serial.println("Room 3 is enabled");
      if (!enabledRoomFound || room3Temp < referenceTemp)
      {
        referenceTemp = room3Temp;
        enabledRoomFound = true;
        Serial.print("Room3 referenceTemp= ");
        Serial.println(referenceTemp);
      }
    }


    break;

Thanks alot! I’m testing this now.

Your example just opened my eyes. Instead of comparing it with the threshold, I just had to compare the room temperature with the referenceTemp every time.

LE:

I think this works fine for me. Thanks a lot for your help!!

      case 2: { // Item 2
        Serial.println("Multiple Rooms Mode is selected");
        boolean enabledRoomFound = false;   
        if (!EnableLocal && !EnableRoom1 && !EnableRoom2 && !EnableRoom3)
        {
          Serial.println("No rooms enabled.");
          enabledRoomFound = false;
          //referenceTemp = temp;
          //EnableLocal = 1;
        }
        else // At lest one room is enabled
        {
          if (EnableLocal == true){
            Serial.println("Local is Enabled");
            if (temp <= referenceTemp){
              referenceTemp = temp; 
              Serial.println("Local referenceTemp= " + String(referenceTemp)); 
              enabledRoomFound = true;
            }
          }
          if (EnableRoom1 == true){
            Serial.println("Room 1 is enabled");
            if (room1Status == true)
            {
              if (room1Temp <= referenceTemp){
              referenceTemp = room1Temp; 
              Serial.println("Room1 referenceTemp= " + String(room1Temp));
              enabledRoomFound = true;
              }        
            }     
          }
          if (EnableRoom2 == true){
            Serial.println("Room 2 is enabled");
            if (room2Status == true)
            {
              if (room2Temp <= referenceTemp){
              referenceTemp = room2Temp;
              Serial.println("Room2 referenceTemp= " + String(room2Temp));
              enabledRoomFound = true;
              }        
            } 
          }
          if (EnableRoom3 == true){
            Serial.println("Room 3 is enabled");
            if (room3Status == true)
            {
              if (room3Temp <= referenceTemp){
              referenceTemp = room3Temp;
              Serial.println("Room3 referenceTemp= " + String(room3Temp));
              enabledRoomFound = true;
              }        
            } 
          }
        }
        if (enabledRoomFound == false)
        { 
          //Failsafe for the situation when Local is DISABLED and no other remote Room sensors are available
          referenceTemp = temp;
          EnableLocal = 1;
          Serial.println("No remote sensors are enabled or online! Switch to Local");
        }
        break;  
      }