There is an example that is exactly like what you want in the Rule Machine documentation. I'd highly recommend reading it before you try much: [Released] Rule 4.0. That being said, you could also use the built-in Motion Lighting app (with a lot less effort) to get the same result, so that would be my recommendation if you aren't doing this to learn or don't want anything with more complicated logic or actions (much of which Motion Lighting could still handle).