However you need to check more than just one context and I think you may have it back to front, both physical device and automation return a null user_id context:
The other option is to create a sensor like this that stores the last context and use that in a state condition: