pressing a keypad switching a relay is not a self-purpose
What kind of visual feedback is given to the user that the user is able to see that pressing a key on the keypad is really recognised by the device?
how many keypresses shall the user do?
What shall these keypressed represent?
one digit hour two digits minutes two digits seconds?
example : 23059
which means
2 hours
30 minutes
59 seconds
After entering the time. Shall the device be locked to strictly execute keep relay switched on for the given time ignoring any keypressed until the given time is over?
or
shall the device be able to react on keypad-presses at any time to switch off the relay on user-input?
This results in a number that increases 1 by 1 each second.
And comparing how much time has passed by is reduced to
if (SecondsOfDay > mySwitchOnTime) {
takeAction();
}
Of course this answer is not satifying. I have written this answer to set you into the position
of having too less information to make it work.
Where I'm in the position of having too less information from you to understand what you really want to do. The momentary poor information would force me to make a lot of assumptions writing down multiple suggestions. This is work I will not do.
You want help so it is you who has to provide a detailed description what you want.
One way to give such a description is
to just write down what a person that is just watching a user using your keypad can see:
user presses "C" on the keypad then .....
user presses .... on the keypad then ....