execution once when the value is the same.... 
#include <LiquidCrystal.h>
#include <DS3231.h>
#include <Wire.h>
#include <VirtualWire.h>
#include <PinChangeInterruptHandler.h>
#include <IRremote.h>
#include <Keypad.h>
DS3231 rtc(SDA, SCL); //real time clock connect
#define DS3231_I2C_ADDRESS 104
byte seconds, minutes, hours, day, date, month, year;
#define NODE_ID 0
#define RELAY_ON 0
#define RELAY_OFF 1
unsigned int power[] = {8930, 4462, 574, 554, 570, 530, 598, 1654,
574, 526, 598, 526, 574, 554, 574, 526,
598, 526, 574, 1654, 598, 1654, 574, 530,
594, 1658, 574, 1654, 574, 1650, 602, 1654,
574, 1654, 574, 554, 570, 530, 598, 1654,
574, 526, 598, 526, 574, 554, 570, 530,
598, 526, 574, 1654, 598, 1654, 574, 526,
598, 1658, 570, 1658, 570, 1654, 602, 1654,
574, 1654, 574, 1000
};
IRsend irsend;
int val ;
int x = 0;
int y = 0;
int z = 0;
int BZ = 12;
int relay = 45;
int LEDKEYPAD = 10;
int menu = 0;
int p = 0;
int A = 0;
int hourupg;
int minupg;
int yearupg;
int monthupg;
int dayupg;
int secupg;
int i = 0;
int b = 0;
int pausa = 1;
byte tMSB, tLSB; // temperature bytes here
float temp3231; // not used
LiquidCrystal lcd(4, 5, 6, 7, 8, 11);
int irf ;
const int OnHour = 20;
const int OnMin = 20;
const int OffHour = 20;
const int OffMin = 50;
char tecla;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [ROWS] = {53, 51, 49, 47};
byte colPins [COLS] = {22, 24, 26, 28};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Time t;
void setup()
{
lcd.begin(20, 4);
lcd.clear();
rtc.begin(); //begin real time clock
t = rtc.getTime();
pinMode (9, OUTPUT); //output used in library
pinMode (BZ, OUTPUT); //output used in library
pinMode (LEDKEYPAD, OUTPUT); //output used in library
pinMode (relay, OUTPUT); //output used in library
digitalWrite(relay, RELAY_OFF);
}
void loop() {
t = rtc.getTime();
char customKey = customKeypad.getKey();
if (rtc.getTemp() - 18.7 >= 30) {
digitalWrite(relay, LOW);
irsend.sendRaw(power, 67, 32);
digitalWrite(relay, HIGH);
delay(500);
}
if (rtc.getTemp() - 18.7 <= 25) {
digitalWrite(relay, LOW);
irsend.sendRaw(power, 67, 32);
digitalWrite(relay, HIGH);
delay(500);
}
z = 0;
y = 0;
tecla = customKeypad.getKey();
MSNinicio();
if (tecla) // Check for a valid key.
{
switch (tecla)
{
case 'A':
Beep();
digitalWrite(relay, LOW);
irsend.sendRaw(power, 67, 32);
digitalWrite(relay, HIGH);
delay(10);
lcd.clear();
lcd.setCursor (3, 0);
lcd.print("Air Condition");
lcd.setCursor (7, 2);
lcd.print("Open");
lcd.setCursor (7, 3);
lcd.print("Close");
delay(1000);
lcd.clear();
break;
}
}
}
void ora() {
while (y < 1)
{
tecla = customKeypad.getKey(); //CHOOSE SENSOR
if (tecla == '1') {
Beep();
menu = menu + 1;
if (menu == 2) {
p = 1;
}
if (menu == 1) {
p = 0;
}
}
if (menu == 0)
{
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("1: RYTHMISI ORAS");
lcd.setCursor (0, 3);
lcd.print("D: EXIT");
}
if (menu == 1)
{
DisplaySetHour(); // set hour
}
if (menu == 2)
{
DisplaySetMinute(); // set minute
}
if (menu == 3)
{
DisplaySetDay(); // set day
}
if (menu == 4)
{
DisplaySetMonth(); // set Month
}
if (menu == 5)
{
DisplaySetYear(); // set year
//check error if min,hour,day,month,year = 0 print error
if (minupg <= 0 && hourupg <= 0 && dayupg <= 0 && monthupg <= 0 && yearupg <= 0)
{
menu = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ERROR ");
}
}
if (menu == 6)
{
StoreAgg(); //setup time date to DS3231
delay(500);
menu = 0; // return to main menu
for (i = 0; i < 1; i++) {
MSNinicio();
lcd.setCursor (0, 1);
delay(200);
lcd.print(i);
}
y = 1;
z = 1;
}
if (tecla == 'D') {
Beep();
for (i = 0; i < 1; i++) {
MSNinicio();
lcd.setCursor (0, 1);
delay(200);
lcd.print(i);
lcd.clear();
}
y = 1;
z = 1;
}
}
}
void MSNinicio() {
lcd.setCursor(0, 0);
lcd.print("Fv Park Georgas");
lcd.setCursor(0, 2);
lcd.print(rtc.getDateStr()); // Print date to LCD
lcd.setCursor(0, 3);
lcd.print(rtc.getTimeStr());
lcd.setCursor(15, 3);
lcd.print(rtc.getTemp() - 18.7);
}
void Beep()
{
digitalWrite(BZ, HIGH);
digitalWrite(LEDKEYPAD, HIGH);
delay(50);
digitalWrite(BZ, LOW);
digitalWrite(LEDKEYPAD, LOW);
delay(50);
digitalWrite(LEDKEYPAD, HIGH);
delay(50);
digitalWrite(LEDKEYPAD, LOW);
delay(50);
digitalWrite(LEDKEYPAD, HIGH);
delay(50);
digitalWrite(LEDKEYPAD, LOW);
delay(50);
digitalWrite(LEDKEYPAD, HIGH);
delay(50);
digitalWrite(LEDKEYPAD, LOW);
delay(50);
digitalWrite(LEDKEYPAD, HIGH);
delay(50);
digitalWrite(LEDKEYPAD, LOW);
}
//end of loop