 
       }
 
-      if ((( millis() - lastRelayActionmillis) > BETWEEN_RELAY_ACTIVE ) && ( relayIsReady == LOW ) && ( relaystatus == oldrelaystatus ))
+      if ( ( relayIsReady == LOW ) &&  (( millis() - lastRelayActionmillis) > BETWEEN_RELAY_ACTIVE ) && ( relaystatus == oldrelaystatus ))
       {
 
         if (DEBUG_PRINT) {

      if (((millis() - startMills) > REPORT_INTERVAL ) && ( getdalastempstatus == 0))
      {
        getdalastemp();
        getdalastempstatus = 1;
      }

      if (((millis() - startMills) > REPORT_INTERVAL ) && ( getdht22tempstatus == 0))
      {
        getdht22temp();
        getdht22tempstatus = 1;
      }

      if ((millis() - startMills) > REPORT_INTERVAL )
      {

            if (timeStatus() != timeNotSet) {
              timestamp = numberOfSecondsSinceEpochUTC(year(), month(), day(), hour(), minute(), second());
              millisnow = millisecond();
              //}

              if ( sensor_data.data1 < 0 ) {
                sensor_data.data1 = 0;
              }

              String udppayload = "current,test=current,measureno=";
              udppayload += sensor_data._salt;
              udppayload += ",unit=";

              /*
                switch (sensor_data.data2) {
                case 1:
                  udppayload += "mA devid=";
                  break;
                case 3:
                  udppayload += "µA devid=";
                  break;
                case 2:
                  udppayload += "nA devid=";
                  break;
                default:
                  udppayload += "middle devid=";
                  break;
                }
              */


              /*

                if ( sensor_data.data2 == 1) {
                udppayload += "mA devid=";
                }
                if ( sensor_data.data2 == 3) {
                udppayload += "µA devid=";
                }
                if ( sensor_data.data2 == 2) {
                udppayload += "nA devid=";
                }
              */
              udppayload += ampereunit[sensor_data.data2];
              udppayload += " devid=";

              udppayload += sensor_data.devid;
              udppayload += "i,volt=";
              udppayload += sensor_data.volt;
              udppayload += "i,ampere=";
              udppayload += sensor_data.data1;
              udppayload += " ";
              udppayload += timestamp;


              char buf[3];
              sprintf(buf, "%03d", millisnow);
              udppayload += buf;

              /*
                if ( millisnow > 99 ) {
                udppayload += millisnow;
                } else if ( millisnow > 9 && millisnow < 100 ) {
                udppayload += "0";
                udppayload += millisnow;
                } else {
                udppayload += "00";
                udppayload += millisnow;
                }
              */

              udppayload += "000000";

              sendUdpmsg(udppayload);
            }
          }
        }
      }
