Is there a way to turn off notifications automatically when I connect to AirPlay?

Solution 1:

Open System Preferences → Notifications, select Do Not Disturb in the sidebar and enable ‘Turn on Do Not Disturb: When mirroring to TVs and projectors’.

If you enable AirPlay without mirroring, then Do Not Disturb is not activated, but the notifications only appear on your primary monitor anyway.