(1) If the tenant fails to comply with any portion of RCW 59.18.130 or 59.18.140 , and such noncompliance can (a) substantially affect the health and safety of the tenant or other tenants, or substantially increase the hazards of fire or accident, and (b) be remedied by repair, replacement of a damaged item, or cleaning, the tenant shall comply within thirty days after written notice by the landlord specifying the noncompliance, or, in the case of emergency as promptly as conditions require. If the tenant fails to remedy the noncompliance within that period the landlord may enter the dwelling unit and cause the work to be done and submit an itemized bill of the actual and reasonable cost of repair, to be payable on the next date when periodic rent is due, or on terms mutually agreed to by the landlord and tenant, or immediately if the rental agreement has terminated. The tenant shall have a defense to an unlawful detainer action filed solely on this ground if it is determined at the hearing authorized under the provisions of chapter 59.12 RCW that the tenant is in substantial compliance with the provisions of this section, or if the tenant remedies the noncomplying condition within the thirty day period provided for above or any shorter period determined at the hearing to have been required because of an emergency: PROVIDED, That if the defective condition is remedied after the commencement of an unlawful detainer action, the tenant may be liable to the landlord for statutory costs and reasonable attorneys' fees.