Alerts: How to set "offline for 5 minutes"

I have a graph with multiple server online states (1/0). What is the correct way to setup “offline for 5 minutes”

I use: WHEN median ( ) OF query (A, 10m, now) IS BELOW 0.5
But this is not correct. If it goes online and offline again it could notify me wrong.

How do you do this?
Thank You