Installing an old work electrical box. Place switch in the wall box.

How To Choose And Install A Programmable Wall Switch Timer
How to install a new light switch box. Screw a wire cap onto the pair of white wires and connect the twisted together. Run a 142 ground cable from the switch box to the electrical box where the light fixture is located. Wrap the body of the switch with electrical tape. Connect the ground wires with a 6 in long pigtail wire leading to the switch. Wiring a new switch and light from an outlet in this diagram power is taken from an existing wall outlet for a new switch and light fixture. Included in the tutorial are tips for making the box installation go much smoother and faster so you will be up and running quicker.
Connect the ground wire to the green screw on the opposite side of the switch. Gently bend the wires and push the switch into the wall box. Loop the black wires clockwise around the screws and tighten the screws. Push the new wired switch back into the electrical box and screw it in place. The switch comes first in the new part of the circuit and new 2 wire cable is run to it from the outlet. Strip the ends of the wires at the switch box.
Covering all bare wires and terminals with electrical tape ensures safety. In the tutorial how to install an electrical box in an existing wall we provide detailed photo rich how to instructions on easily installing the old work electrical box. Connect the neutral white wires with a wire connector. If the existing switch has a green ground wire attach the wire to the green screw terminal on the new switch or to the electrical box. Wrap a little more than 12 inch of the stripped wire clockwise around the terminal screws and tighten with a screwdriver. Figure 3 old work electrical box.
Connect the black wire to the brass screw and the neutral wire to the silver screw. Screw on the switch plate and turn on the power. From the switch new 2 wire cable is run to the new light location. All of the connections in the switch box can be made prior to turning any power off. Connect each of the black wires to one of the brass switch terminals and tighten the terminal with a screwdriver.