By default smartctl ignores the power state of a disk. Ask a sleeping hard disk for its SMART data and it spins up to answer. For one manual check that’s fine. For a script that polls every disk every half hour, it means your disks barely get to sleep, and on a NAS with spin-down timers that’s the opposite of what you set up.
The -n option (long form --nocheck) tells smartctl to exit before it does any checks when the disk is in a low-power mode:
sudo smartctl -n standby -H /dev/sdb
With standby it leaves the disk alone in SLEEP or STANDBY mode, where most disks have stopped spinning, and the man page calls it probably what you want. sleep only skips disks in SLEEP mode. idle skips IDLE too, but most disks are still spinning in that state, so I’d leave that one alone. never is the default and checks the disk whatever it’s doing.
In a script the exit status is what you test. A skipped disk returns 2 by default, but smartctl also returns 2 when it can’t open or identify the device. The man page suggests giving the skip its own number:
sudo smartctl -n standby,3 -A /dev/sdb; echo $?
Now 3 means the disk was asleep and left alone, and 2 still means something went wrong.
The caveat is in the man page as well: the commands smartctl sends while it detects the device type can wake the disk before -n gets a say. If a disk still spins up, name the type yourself, for example -d sat. The option is ignored on devices that don’t support the power mode check, and it’s listed for ATA and SCSI only, so don’t count on it for an NVMe drive.
Further reading: smartctl man page (smartmontools)
Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid