Headphone plugged/unplugged kode

Would it be possible to add a kode to detect if headphones have been connected or not

Something like -

$si(head)$ where 0 is not connected and 1 is connected

Android provides a way to know if audio devices are connected from N, i need to find a way to make it generic, because there are a lot of devices that might be there:


Tasker can probably be used for this in the meantime

Yes. I use MacroDroid, very similar to Tasker.