Trigger a switch when button is pressed AND entity change not older than time

Hello,
I tried to solve this but I can´t figure out how to do it. I try so set up an automation that:

Trigger:
button press (entity changes from off to on)

Condition:
onyl if the change of the ssid from my phone (freshly connected to wifi due to coming home) is not older than x minutes.

→ this should make sure that the automation is only active when I recently came home.

Then:
Turn entity on

I only made automations through the ui but I understand the basics of yaml. But I can´t find a way to do it.

Maybe with a helper binary sensor that is only true when the condition is met but that state template js is out of my abilities.

Any help appreciated.