Switching a relay on and off using "millis()" without interfering with the runtime of the other piece of code

If a voltage appears at the analog input the flag bRelay would be set to true:

    sensorValue = analogRead(sensorPin);
    voltage = sensorValue * (5.0 / 1023.0);
    if (Serial.available() > 0 || voltage > 2 ) 
    { 
        receivedChar = Serial.readStringUntil('#');      
        newData = true; 

        bRelay = true;  //...after the analog voltage is read from the analog pin...
    }

If "voltage" is greater than 2 this flag would be set.

That should then allow the relay() state machine to move out of the IDLE state. You might try adding some Serial.prints() to show where the code is getting to help understand what's going on.