How to create a time switch