  The threshold-$k$ metric dimension ($\mathrm{Tmd}_k$) of a graph is the
minimum number of sensors -- a subset of the vertex set -- needed to uniquely
identify any vertex in the graph, solely based on its distances from the
sensors, when the measuring radius of a sensor is $k$. We give a sharp lower
bound on the $\mathrm{Tmd}_k$ of trees, depending only on the number of
vertices $n$ and the measuring radius $k$. This sharp lower bound grows
linearly in $n$ with leading coefficient $3/(k^2+4k+3+\mathbf{1}\{k\equiv
1\pmod 3\})$, disproving earlier conjectures by Tillquist et al. in
arXiv:2106.14314 that suspected $n/(\lfloor k^2/4\rfloor +2k)$ as main order
term. We provide a construction for the largest possible trees with a given
$\mathrm{Tmd}_k$ value. The proof that our optimal construction cannot be
improved relies on edge-rewiring procedures of arbitrary (suboptimal) trees
with arbitrary resolving sets, which reveal the structure of how small subsets
of sensors measure and resolve certain areas in the tree that we call the
attraction of those sensors. The notion of `attraction of sensors' might be
useful in other contexts beyond trees to solve related problems. We also
provide an improved lower bound on the $\mathrm{Tmd}_k$ of arbitrary trees that
takes into account the structural properties of the tree, in particular, the
number and length of simple paths of degree-two vertices terminating in leaf
vertices. This bound complements arXiv:2106.14314, where only trees without
degree-two vertices were considered, except the simple case of a single path.
