2ch rf relay for shutters

Hi everyone.
I have started making my own automations at home and i started with my shutters as i found it the cheapest solution.
I used 2ch rf relays one for up one for down as i dont need for now intermidiate positions, but i have a problem with my code and let me explain.
When i send the command for the first shutter to close or open it, i can not send a second command for the other shutter to close because of the delay function. How could i replace it? I use delay because my relays lock and i have to send a second command after a period of time, when it is closed to unlock it.
The code works fine but i have to wait for the first shutter to close in order to close the second one.
Here is the code to understand better what i mean.

#include <MQTTClient.h>
#include <ESP8266WiFi.h>
#include <RCSwitch.h>

const char* ssid = "********";
const char* password = "**********"; 

const char* subscribeTopic = "livingroom/shutters/#"; // subscribe to this topic; anything sent here will be passed into the messageReceived function
const char* server = "***.***.***.***"; // server or URL of MQTT broker
String clientName = "livingroomnode-"; // just a name used to talk to MQTT broker - doesn't actually matter. 

unsigned long resetPeriod = 86400000; // 1 day - this is the period after which we restart the CPU, to deal with odd memory leak errors

WiFiClient wifiClient;
MQTTClient client;
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {

  
  // Transmitter is connected to NodeMCU GPIO 2 / D4  
  mySwitch.enableTransmit(2);

  Serial.begin(115200);
  
  client.begin(server,wifiClient);
  Serial.print("Connecting to ");
  Serial.println(ssid);  
  WiFi.mode(WIFI_STA); //disables the built-in "doitwifi" being broadcast. 
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Generate client name based on MAC address and last 8 bits of microsecond counter
  uint8_t mac[6];
  WiFi.macAddress(mac);
  clientName += macToStr(mac);
  clientName += "-";
  clientName += String(micros() & 0xff, 16);

  Serial.print("Connecting to ");
  Serial.print(server);
  Serial.print(" as ");
  Serial.println(clientName);
  
  if (client.connect((char*) clientName.c_str())) {
    Serial.println("Connected to MQTT broker");
    Serial.print("Subscribed to: ");
    Serial.println(subscribeTopic);
    client.subscribe(subscribeTopic);

  }
  else {
    Serial.println("MQTT connect failed");
    Serial.println("Will reset and try again...");
    abort();
  }

  
}

void loop() {

  client.loop();

  // reset after a day to avoid memory leaks 
  if(millis()>resetPeriod){
    ESP.restart();
  }
}

/* This is where the magic happens, and you'll need to modify this to support custom items. At the moment, it listens
 *   to (first bit derived from channel name set at start):
 *   livingroom/control/switch/x/y (with payload value of on or off)
 *   and
 *   livingroom/control/screen (with payload value of up or down)
 *   You should be able to modify below to easily add more commands if needed
 */
    
void messageReceived(String topic, String payload, char * bytes, unsigned int length) {
  Serial.print("incoming: ");
  Serial.print(topic);
  Serial.print(" - ");
  Serial.print(payload);
  Serial.println();

  if (topic.indexOf("switch") >=0){
    //switch control, parse out the channel and plug id 
    
    int channel = getValue(topic,'/',3).toInt();
    int plug = getValue(topic,'/',4).toInt();
    
    if(payload == "on"){   
      mySwitch.switchOn(channel, plug);
    }
    else{
      mySwitch.switchOff(channel, plug);
    }
  }
  else if (topic.indexOf("left") >=0){
    //shutter left control
    if(payload == "up"){
      leftUp();
    }
    else if(payload == "down"){
      leftDown();
    }
  }

  else if (topic.indexOf("right") >=0){
    //shutter right control
    if(payload == "up"){
      rightUp();
    }
    else if(payload == "down"){
      rightDown();
    }
  }
  /* add another else if here to listen for more commands (or just modify the one above if you dont want screen) */
}

// Custom functions for RCSwitch. Define your own, then link them to an MQTT channel. 
// Note that my screen actually requires TWO button presses (not a long press, but two physical presses), so I'm delaying a bit then sending the same signal again

void leftUp(){
  mySwitch.setPulseLength(321);
  mySwitch.send(8390705,24);
  delay(24000);
  mySwitch.send(8390705,24);
}

void leftDown(){
  mySwitch.setPulseLength(358);
  mySwitch.send(8390706,24);
   delay(24000);
  mySwitch.send(8390706,24);
}

void rightUp(){
  mySwitch.setPulseLength(322);
  mySwitch.send(8573265,24);
   delay(24000);
   mySwitch.send(8573265,24);
}

void rightDown(){
   
  mySwitch.setPulseLength(322);
  mySwitch.send(8573266,24);
  delay(24000);
  mySwitch.send(8573266,24);
  
}


/*Utility functions, no need to edit below here */

String macToStr(const uint8_t* mac)
{
  String result;
  for (int i = 0; i < 6; ++i) {
    result += String(mac[i], 16);
    if (i < 5)
      result += ':';
  }
  return result;
}

// getValue function taken from http://arduino.stackexchange.com/questions/1013/how-do-i-split-an-incoming-string/1237
String getValue(String data, char separator, int index)
{
 int found = 0;
  int strIndex[] = {
0, -1  };
  int maxIndex = data.length()-1;
  for(int i=0; i<=maxIndex && found<=index; i++){
  if(data.charAt(i)==separator || i==maxIndex){
  found++;
  strIndex[0] = strIndex[1]+1;
  strIndex[1] = (i == maxIndex) ? i+1 : i;
  }
 }
  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

So change the delay period.. or better, use millis()

Allan.

Thanks for the immidiate reply.
I can not change the period because this is the time the shutters need to get on closed or open position.
As for millis i have no idea how to use it, any help appreciated.

Look in the learning section of this forum for a lot of help.

And look at the BlinkWithoutDelay example in the IDE..

Allan