Solid-state thermometry via ionic–electronic coupling in two-dimensional heterostructures