The sound bar is designed to be connected to your TV and turn on and off when your TV turns on and off.
Since most cable boxes never turn off, this will cause the bar to never turn off and not stay off if you turn it off with the remote. It's best if the bar is connected to the TV so it will turn on and off with the TV.
If you have the bar connected directly to a Smart TV with an optical cable and it is, seemingly, powering on by itself at random times, then it is likely an internet connection issue.
Smart TV's are constantly doing background maintenance and updates through the internet, even when the TV is powered off. This internet signal can sometimes "leak" into the optical connection on the TV and cause the soundbar to power on, thinking that it is about to receive and output signal.
To resolve this, you can try to turn off any Auto-Update features on your TV, or you may turn off the internet connection entirely.