This should help. This FAQ ( this is a clickable link) explains how you use custom code in SmartThings:
After you’ve read that, people have suggested two different possible custom code solutions for you to consider.
Flexilighting is specific to lighting. The author has already given you the link to the code that you would copy.
Rule Machine is a comprehensive rules engine with many different options. You’ll find its code and discussion with its author in the following topic: