Taking a drug is absolutely a habit, it's a habit of soothing an emotion or seeking an emotion. "My body feels this, therefore I will do that"
This is "bad, bored, tired" or anything else. "That" is the drug administration, experience, etc.
Much of addiction therapy is understanding that cycle and finding a different course of action between "my body feels this" and "doing other things instead of that drug"