Table showing only change of state

My IOT sensors record the current state to the database every few minutes.

I’d like to be able to create a table that provides the state changes only.

Can anyone advise how I filter for only where state changes?