Note that the redirection characters "separate" execution and privileges. On this command:
sudo echo disk > /sys/power/state
What you're doing is running echo disk
as root (pointless) and then piping that, as your normal user, into a file that's owned by root, that's why you get permission denied.
This is a very common use case, what you need to do is sudo the part that actually writes to the file instead, something like this works:
echo disk | sudo tee /sys/power/state
You can also create a shell script (a file) with:
echo disk > /sys/power/state
Name it, for instance, script.sh, then run chmod 755 script.sh
and run that with sudo:
sudo /wherever/you/put/this/script.sh
As for running a command without needing a password, that's been discussed before: How do I sudo without having to enter my password?. It can be somewhat insecure; you can control which user gets to execute which command as root without password, but in this case you'd need to allow execution of the tee
command which could allow malicious users to overwrite any file as root. So use with caution and please read all the documentation and understand the security implications of doing this.