Greetings,
Welcome to the forum.
I am not a HP employee.
You have provided a good description of the problem.
I would guess the power supply may be failing.
It would not hurt to replace the CR2032 motherboard battery also.
The replacement power supply is not available at HP Part surfer (Link).
Try Amazon, or Newegg, or eBay.
It maybe time to upgrade your PC.
Regards