You've probably already found Swaylock, but the configuration is a bit confusing. Here's my setup.

All of these codes are meant to be put in ~/.config/sway/config, unless stated otherwise

Idle lock

  1. Turn screen off in 9min30sec
  2. Lock screen in 10min (so 30sec after screen off)
  3. Lock screen when going to sleep
set $lock swaylock -c 550000
exec swayidle -w \
    timeout 600 $lock \
    timeout 570 'swaymsg "output * dpms off"' \
    resume 'swaymsg "output * dpms on"' \
    before-sleep $lock

Manual lock

  1. Win + l to lock the screen immediately
  2. in 10 sec also switch the screen off
set $lockman exec bash ~/.config/sway/
bindsym $mod+l exec $lockman

And the file ~/.config/sway/

# Times the screen off and puts it to background
swayidle \
    timeout 10 'swaymsg "output * dpms off"' \
    resume 'swaymsg "output * dpms on"' &
# Locks the screen immediately
swaylock -c 550000
# Kills last background task so idle timer doesn't keep running
kill %%

Fancy lock screen

blur and time

Just remove swaylock and instead install swaylock-effects.  In case you're in Arch that's yay -S swaylock-effects-git. The command will stay the same. And here's my command to use all the effects:

swaylock --clock --indicator --screenshots --effect-scale 0.4 --effect-vignette 0.2:0.5 --effect-blur 4x2 --datestr "%a %e.%m.%Y" --timestr "%k:%M"