Get the time since an entity's state was a certain value

I wonder if the history stats, which can track specific states, could be persuaded to do what you want.