The precise estimation of small parameters is a challenging problem in quantum metrology. Here, we introduce a protocol for accurately measuring weak magnetic fields using a two-level magnetometer, which is coupled to two (hot and cold) thermal baths and operated as a two-stroke quantum thermal machine. Its working substance consists of a two-level system (TLS), generated by an unknown weak magnetic field acting on a qubit, and a second TLS arising due to the application of a known strong and tunable field on another qubit. Depending on this field, the machine may either act as an engine or a refrigerator. Under feasible conditions, determining this transition point allows to reduce the relative error of the measurement of the weak unknown magnetic field by the ratio of the temperatures of the colder bath to the hotter bath.