I get the UK mains frequency by local measurement on an Arduino using (howls of fmea from the pro electricians?) a potential divider hidden inside a spare British mains plug. The 22 Meg resistor to Live! Must be safe for mains Voltages and provides a tiny ac current to a low resistor of the potential divider which is in the 20k to 200k range to mains Earth!. The potential divider goes into the base of an npn connected to mains Earth! and to GND and pin D3 (pullup; input) of an arduino, which does interrupt timer logic with 4 microseconds resolution.
In place of an API, you could buy an Arduino and do like mine. The most expensive component in my mains F probe is the new BS1363A plug, unless you scavenged a scrap one. My npn were an unknown ten pence three legs type from ebay with beta above 200.
In every mains cycle rising-to-rising of around 20 ms, the function micros() in arduino returns long integers which can be subtracted, giving a long integer of typically 19920 to 20120. Divide the (board dependent) clock calibration number such as 1000800 microticks per second by that, and it gives you The UK mains frequency in the latest 20ms cycle. For most applications you’ll want better accuracy at the expense of latency; for example I maintain an exponentially weighted rolling average with half second lag similar to F25 = 0.96F25 + 0.04F1; from latest cycle estimate F1 of frequency, which should always be inside 49.7 to 50.3 Hz; anything outside of that is a measurement fault.
As a bonus extra, with laborious calibration effort, the duration of the high until low from this single transister probe to interrupt-fine-timer gives some indication; good to about 2%, of the mains rms Voltage, so for example it can spot it straight away when my street is at 232 Volts instead of the more usual 242 Volts; perhaps indication of more local demand than could be visible from the national 50Hz alone. That seems to happen around most evening peaks; perhaps from many cookers being used in my street, so perhaps you could get most of this indication from only timer logic “while time is 5pm to 8pm”.
Rather than using such in hard logic, I’d prefer to “bump the thermostat”, for example tweaking the fridge sensor ON and OFF temperatures from your [4.5 6.5] to ( [5.0 6.0] - (F-50.0)*0.5/0.2 ) with of course numerical conditions checking sensible limits of how much thermostat-tweaking is allowed and whether to accept F as a valid Frequency near 50Hz or to ignore a measurement fault and revert to sensible defaults.
By the way, I also noticed a very ugly turn-on spike from the motor of my unmodified Zenith fridge, and not every time. If one is going to improve things anyway, then to synch your relay switching to the time of the next rising zero crossing of mains V after you decided to activate the fridge might improve that.
Whilst I would prefer an API to read a trusted local status and forecast from a “smart street” valid for everything below my local street transformer, my local DNO were dead against my instrumenting their street transformer, so it would need a private network such as a university electrical engineering building to demonstrate that such can be useful. In the meantime, we only have a national demand indication F to decide from.