Air Source Heat Pump Cycling

Hello,

How might I create a sensor (true/false) that detects the behaviour shown in the energy usage for the latter part of this graph, from 1800 - 0200ish: