   }
 
   /* Initializing Switches */
-  if (Device.configuration.isSwitch[0]) {
-    Switch.begin(0);
-  }
-  if (Device.configuration.isSwitch[1]) {
-    ExternalSwitch.begin(1);
-  }
-
-  Pir.begin(0);
+  for (uint8_t i = 0; i < 5; i++) {
+    if (Device.configuration.isSwitch[i]) {
+      Switch[i].begin(i);
+    }
+  }
+
+  /* Initializing PIRs */
+  for (uint8_t i = 0; i < 4; i++) {
+    if (Device.configuration.isPIR[i]) {
+      Pir[i].begin(i);
+    }
+  }
 
   /* Initializing MQTT */
   if (Device.getMode() != MODE_ACCESS_POINT && Device.configuration.mqttAPI) {

  }

  /* Initializing relay and setting it's default state at power on*/
  if (Device.getMode() == MODE_NORMAL && Device.configuration.isRelay[0]) {
    Relay.begin(0);
    Relay.setRelayAfterRestoringPower();
  }

  /* Initialzing network */

AFEMQTT Mqtt;
AFEWebServer WebServer;
AFELED Led;
AFESwitch Switch[5];
AFESwitch ExternalSwitch;
AFERelay Relay[4];
MQTT MQTTConfiguration;
AFEPIR Pir[4];

void setup() {

