Many tenants erroneously believe that if the landlord is trying to evict them, and that landlord has not fixed the heater or the leaking faucet, then they don’t have to pay rent. While that is true in some instances, it isn’t always.
For example, let’s say the toilet overflows in the tenancy and you fail to fix it. The tenant absolutely has the right to refuse to pay rent. After all, who should pay rent for a place filled with human waste? If the landlord then attempts to evict you on the basis that you have failed to pay rent, and you raise that defense in your answer to the Complaint for Unlawful Detainer, then the Judge must determine what the value of the rental was, tell the landlord he cannot have possession, order that the rent be reduced to what the tenancy is worth, and award the tenant costs and attorney fees. See California Code of Civil Procedure 1174.2 and 1174.21.
The mistake that many tenants make is believing that it is always an issue at trial. It isn’t. If the landlord is evicting you based upon another reason, such as breach of your lease agreement, then habitability is not a defense. If you have five cats and your lease agreement provides that you can have one, you cannot raise the issue of habitability. You can only ask that your rent be reduced.