Automation trigger: local device control vs triggered by automation

Try this for a null value:

context:
  user_id: []

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:

Screenshot 2022-06-21 081430

The other option is to create a sensor like this that stores the last context and use that in a state condition: