Question about TimeAlarms lib; How to add alarms dynamically?

Hi Guys,

I'm currently building a traffic light clock for my little girl. The basic idea is simple: Red means stay in Bed, Orange means You may play but don't disturb your parents, and Green, well that's pretty much obvious.

To accomplish this, I make thankfull use of the TimeAlarms Library, which works perfectly.
However, I would like to make things a bit more usefull, by adding the option to configure the clock over the network. I have added an Ethernet shield, (time is also synced by NTP) and I receive a string from my webserver which contains information about the clocks configuration.

The string I receive looks something like this:

Red, 10,0,0~Green, 11,0,0~Orange, 12,0,0~Off, 13,0,0

Next step is to split the string by ~ and loop through all alarm instances. No problems there.
Finally, add an alarm instance for every item in the loop. This is where my problem is.

When I try to add an alarm at runtime, I get an error message: no matching function for call to 'TimeAlarmsClass::alarmRepeat(int, int, int, String&)'
Simplefied sample:

   String MethodName = "Red"; 
   int Hour = 10;
   int Minute = 0;
   int Second = 0;
   Alarm.alarmRepeat(Hour,Minute,Second, MethodName);

I understand why this happens: There is no matching function in the library that takes a string as a valid argument. So my question is: How do I cast a string to onTick_t type? Or is there another (better) way to dynamically add alarms to the TimeAlarms class?

Any help is greatly appreciated!

So my question is: How do I cast a string to onTick_t type?

You don't. By the time the compiler gets done, names are history. Forget trying to use a name.

Yeah, I kind of expected that.

How about a diffrent approach?
Something like:

//Code to receive delimeted string from server

//Code to split string into array 

// For each element in array:
//    {
//      Call parseAlarm with the values from the string
//   }
 
void ParseIAlarm(String MethodName, String Hour, String Minute, String Second){
      
 if (MethodName == "Red")
  SetRed(Hour.toInt(), Minute.toInt(), Second.toInt());
 
if (MethodName == "Green")
  SetGreen(Hour.toInt(), Minute.toInt(), Second.toInt());
   
//etc...
}

void SetRed(int Hour, int Minute, int Second){
  Alarm.alarmRepeat(Hour,Minute,Second, Red);      
}

void SetGreen(int Hour, int Minute, int Second){
  Alarm.alarmRepeat(Hour,Minute,Second, Green);      
}

void Red(){
 Serial.println("Red has been triggered"); 
}

void Green(){
 Serial.println("Green has been triggered"); 
}

Or I might choose to add a timer for every seccond and evaluate the conditions instead of working with alarms.

Anyway, Thank you for your response.
Tips or suggestions are still welcome!

Sorry, but I'm a bit confused.

You have a "traffic light" ok.
But why "alarms" to control things?

Why not have switches to set the "mode"?

You press a button for RED, ORANGE or GREEN.

By using alarms, it implies that the times are "regular". But kids upset their parents at will, and (probably) when ever they feel like it.

So to me buttons would be better.

But just my opinion.

Good luck.