Esphome global variables for nspanel pop up

Hello… maybe someone can help me because I´m stuck.

My idea is to receive a pop up picture in my nspanel screen when someone rings the door bell.

Basically I have managed to the pop up part when the binary sensor goes on and desappearing when it goes off. GREAT RIGHT?? NO!!!

My problem now is that the screen detects the clicks no matter it is on or off!! meaning with or without picture…

My goal is to only detect the clicks on the screen when the picture and obvs the sensor are ON!! not when it´s OFF… is my understanding that I could make it work with a global variable that controls the time of the picture and then and only then, if the variable is ON to trigger the switch to open the door…

Thanks in advance…