Lion battery backup that sends sms when power lost

Hello,

I'm building an alarm to send a text message when the AC-power fails. the problem I have,, When power is fails the alarm send the SMS each loop endlessly until power is restored.

I want it to send only one text-message when the power fails and happy one when power is restored. B :blush:

AC power is measured via pin 2 going incoming stream before "battery charger module"

The Alarm make a restart when it go to backup power because its a small powerdip between AC power and batterypower but when its go from AC to Battery its no dip so it dont work with "do this one time"

 check = digitalRead(Powercheck);  \\ Reading pin 2, if AC = Power on 5v+ 
  if (check == LOW) {
    
                    lcd.setCursor(0,0);
                    lcd.print("Power Fail");
                    lcd.setCursor(0,1);
                    lcd.print("Skickar SMS");
                    lcd.setCursor(0,1);
                    lcd.print("+46706XXXXXXXX");
                    
                    sms.SendSMS("+46706xxxxxxx", "Warning! Power FAIL!");
                               
                    delay(3000);
  
                       }
                      
  else {
                    lcd.print("Power Online");
                    lcd.setCursor(0,1);
                    lcd.print("");
                    delay(400);
                    lcd.clear();
  }

This is untested but will give you an idea of what todo

In your code, before void.setup() add something like:

char Electricity = 1;

Then, add another if() statement around the current one as such:

if(Electricity == 1)
{
  // run code to send SMS
}else{
// do nothing;

Lastly, in the if statement you have, add the following to the if and else parts respectively:

char Electricity = 0;
char Electricity = 1;