Install an occupancy sensor, old switch has 3 black wires
WARNING: This procedure requires working on live wiring. If you're not comfortable with that, contact a local licensed Electrician.


Turn the light switch off, then use a multimeter/voltmeter to check for voltage between the ground and the terminals on the switch. One terminal will read line voltage (120 volts), while the other should read 0 volts.

Once you know what's what, turn off power to the circuit and verify that it's off. 

The terminal that reads line voltage, is the line side terminal.  If that's the terminal with one wire, attach the single wire to the black wire of the new switch. If it's the terminal with two wires, attach both of those wires to the black wire of the new switch. 

Attach the wire(s) from the other terminal (the 0 volt terminal), to the red (load) wire of the new switch.

Connect the white wire from the new switch, in with the other white wires in the box. Connect the green wire from the new switch, in with the other grounds in the box.

Use twist-on wire connectors, or other approved means to make the connections. Make sure you use connectors rated for the number, and size of wires you're connecting.