I’ve just had what seems like a very similar problem with my Samsung TV. Rapidly turning on and off. Changed the TV with another Samsung. Same problem. Every other appliance in the room was working fine so I ruled out an electrical problem.
If I moved it to another room it worked again. If I stood in front of it, it worked again.
Long story short, it was the Amazon fire stick remote which had gone crazy and was sending a signal to turn on/off the TV in rapid succession. Took out the batteries from the remote and the TV was fine after that.
Is it possible that in the room in which the TV doesn’t work you have one remote which could be causing a similar problem? Or maybe another device that communicates to the TV and sends it a signal to turn off/on?