Hello, sorry I've been a while to get back to you it's been a bit busy here. I tried to write this in my break so I haven't tested it on an Arduino and even if I had I'm not an expert but it should work or at least give you a good head start on making it work. I haven't re printed all the code in the link you sent me I've just added some bits in red.. so basically copy the code from the link you provided then add the bits in red from below.
The hysteresis should be provided by the anti chatter counter in that if the value is around 1000 w difference between ch1 and ch2 the output wont change until it has been that way for more than 2000 programe cycles. I hope you find it helpful

int wavelengths = 50; //number of wavelengths to sample
int AntiChatter = 0; // used to ensure the output doesn’t chatterint inPinV = 1; //Analog input pin number that voltage signal is connected to
int inPinI_1 = 0; //Analog input pin number that current signal is connected to. Channel 1
int inPinI_2 = 2; //Analog input pin number that current signal is connected to. Channel 2
int RelayOn = 4; // pin four is the one to connect the opto isolator to but you can pick any pin other than 0,1 or 2void setup()
{
Serial.begin(9600);
pinMode(RelayOn,Output); // this sets the pin named RelayOn to an output }
unsigned long wtime;
void loop()
{
//-------------------------------------------------------------------------------------------
// 1) Calculate energy monitor values
//-------------------------------------------------------------------------------------------
ch1.emon_calc(inPinI_1,ICAL_1); //Energy Monitor calc function for channel 1, pass Arduino analog in pin nummber and calibration coefficient
ch2.emon_calc(inPinI_2,ICAL_2); //Energy Monitor calc function, for channel 2, pass Arduino analog in pin nummber and calibration coefficient
//delay(2000);
Serial.print("Channel 1 Real Power: "); Serial.println(ch1.realPower);
Serial.println("");
Serial.print("Channel 2 Real Power: "); Serial.println(ch2.realPower);
If (ch1.realPower > (ch2.realPower +1000)) {
// count the number of program cycles that ch1 is higher than ch2 by at least 1000
AntiChatter ++ ;
If (AntiChatter == 2000) {
// the state ch1 > (ch2 +1000 ) has been true for 2000 cycles
digitalWrite(RelayOn,HIGH); //turn the output on
//minus one off the Antichatter variable to clamp it at a max of 2000
AntiChatter -- ;
}
}
else{
// if ch1 isn’t > (ch2 +1000) then start counting down and when the AntiChatter counter reaches zero turn the output off
If (AntiChatter == 0) {
// the state ch1 <= (ch2 +1000 ) has been true for 2000 cycles
digitalWrite(RelayOn,LOW); //turn the output off
//add one off the Antichatter variable to clamp it at a min of 0
AntiChatter ++ ;
}
} ch1.wh = ch1.wh + ch1.whInc; //Accumulate wh for channel 1 until ethernet send
ch2.wh = ch2.wh + ch2.whInc; //Accumulate wh for channel 2 until ethernet send
}