Save and restore switch/dimmer states?

There’s an app called Lights On Motion Plus which does exactly what you described.