Use the ‘if’ condition in the template, so that the value of the sensor only updates how you want it to update. See here for some examples: Template - Home Assistant
You could keep the sensor as is, and use a condition in the automation when you are actually using the sensor. E.g. if you only want to do something when the garage light is off AND this sensor is triggered, then add that as a condition to an automation.
Is it possible to make it keep the value it already has, in case the light is on? Now the value is just empty. I’m guessing I need something in the else part.