A class of inverse problems for restoring the right-hand side of a parabolic equation for a large class of positive operators with discrete spectrum is considered. The results on existence and uniqueness of solutions of these problems as well as on the fractional time diffusion (subdiffusion) equations are presented. Consequently, the obtained results are applied for the similar inverse problems for a large class of subelliptic diffusion and subdiffusion equations (with continuous spectrum). Such problems are modelled by using general homogeneous leftinvariant hypoelliptic operators on general graded Lie groups. A list of examples is discussed, including Sturm-Liouville problems, differential models with involution, fractional Sturm-Liouville operators, harmonic and anharmonic oscillators, Landau Hamiltonians, fractional Laplacians, and harmonic and anharmonic operators on the Heisenberg group. The rod cooling problem for the diffusion with involution is modelled numerically, showing how to find a "cooling function", and how the involution normally slows down the cooling speed of the rod.