I wired a smoke detector to a switch loop that turns on a light. When I connected the smoke detector black wire to white wire and smoke detector white wire to black wire the smoke detectors would turn on/off when I would turn the switch in/off, same when I would connect black to black or white to white. So I did a bootleg ground where I connected the smoke detector black to the switch loop white (hot) wire and the smoke detector white to the ground wire and this keeps my smoke detector powered regardless of the switch position. Is this OK?
No, this is not OK. Neutral and ground are different wires for different uses. Is it likely to start a fire? No. But does it really make sense to wire up a smoke detector, of all things, knowingly incorrectly? No, it does not!
The good news is that:
- Smoke detectors are usually in the ceiling
- Light fixtures are usually in the ceiling
- A switch loop means you've got hot and neutral available together somewhere, usually at the light fixture or possibly at a junction box above the switch on the way to the light fixture.
So find where the wires in the switch loop are coming from. Wherever that is, you should find hot (connected to the switch loop hot) and neutral (either connected to the light fixture or going together with switched hot to the light fixture). Connect the smoke detector to hot and neutral from that location and you are all set.
or use a battery-powered smoke detector.
There are some places that require wired smoke detectors. Those typically (but not always) also require them to be linked together so that when one activates the others sound the alarm at the same time to get everyone out of the house. If that's the case then simply connecting hot and neutral isn't enough - you need to figure out how to connect to the other smoke detectors. Looking at the manual for one semi-random example, the Kidde PI2010, it uses 3-wire cable (black hot, white neutral, red signal) to connect detectors together. It clearly states (as I would expect) that you can't connect just the signal wire - if they are interconnected they must be on the same circuit using daisy-chained power wires as well. However, they can be installed individually, as long as they are on a non-switched (to avoid the problem you're having), non-GFCI (so that an unnoticed GFCI trip won't prevent smoke detectors from functioning, and also because GFCI protection is really not needed for a low-power plastic encased item stuck on the ceiling, like a smoke detector) circuit.