How to get second last state

As title, I need to get the state previous to the last one of a sensor, how can I do that?