Using millis for time delay for (push ON/OFF button)

henry it means that i had to use the else if loop right?

my final working code:)

void loop(){
  val = digitalRead(sensor);
  potval = analogRead(pot);
  timedelay = map(potval, 0, 1023, 20, 600);
  Serial.println(potval);
  Serial.println(timedelay);
  
  if(val == 1)
  {
    time = millis()/1000;
  }
  timep=millis()/1000;
  if( timep-time <= timedelay)
  {
    acon();
  }
  else
  {
    acoff();
  }
  delay(1000);  
}

void acon(){
  if(state == 0)
  {
    digitalWrite(led, HIGH);   
    delay(500);
    digitalWrite(led, LOW);
    state = 1;
    Serial.println("AC ON");
  }
}

void acoff(){
  if(state == 1)
  {
    digitalWrite(led, HIGH);   
    delay(500);
    digitalWrite(led, LOW);
    state = 0;
    Serial.println("AC OFF");
  }
}

crimony i did it the same way as your code, but using int and not boolean

if by mechanism you mean external feedback to see weather AC is on, i dont think it is required as the AC remote sends different signals for ON and OFF so even though ac is initially ON, the functions wont get reversed :smiley:

i tried overriding with external remote, works good without inverting the states of the AC