Easy way is to use a template binary sensor. You might look into the template card for lovelace. I don’t have experience with it, but glancing at the examples leads me to believe you can achieve what you’re after.