White wires may not be mixed with or connected to bare or green ground wires. Its essential that you determine which black wire is hot before proceeding.

Wiring A 2 Way Switch
Light switch only has 2 wires. The blue wire is known as the switched live and takes power to the light. My old light switch in my bathroom only has two black wires connected to it. As stated already if you have a bare green wire it is the ground and goes on the green screw that is on the switch. An occupancy sensor that needs a neutral as well as the feed hot and hot to the light cannot be used where there are only two power wires not counting a bare or green ground wire entering the switch box. While a standard switch does in fact only have two wires connected to it plus ground things can get a bit more complicated with a smart switch or multi way switches. An incoming hot wire which is black.
Line this comes from the panel and is your hot wire. Ill take a moment to outline each wire its typical color and its use huge disclaimer your wiring may vary. A standard 2 wire lighting circuit is shown in figure 1. Two or three wires will be attached to the switch. Switched live is only live when the switch is on this is where it gets its name from. Depending on the manufacturer of the light fixture the.
However if you need to rewire a light switch or a plug socket you may occasionally come across two black wires. Black means hot white signifies neutral and green indicates ground. By your description though it doesnt sound like you have one. How to install a light fixture with two lead wires. Each light socket in a light fixture has its own black lead wire and white neutral wire. The easiest and safest way is to use a multimeter to test for current.
My apologies if this has been tackled before but im trying to replace an old light switch in my bathroom and the old one only had two black wires connected to it. The brown wire is live also know as permanent live this brings the live supply to the switch. A return wire which carries the load to the fixture and may be black red or any other color except green. And sometimes a grounding wire which is green or bare copperthere may be other wires in the box but you are only dealing with the ones connected directly to the switch.