Turn off lights only when turned on by specific automstio

When someone controls an entity via the Lovelace UI, Home Assistant knows who they are because they had to login with a user account. That means their actions are known and identified by a property called user_id. In contrast, an automation doesn’t identify itself with user_id so its value is none. It’s this difference that be used to determine if a trigger was caused by a person or an automation.

For example, the following condition checks if the State Trigger was caused by an automation (because it’s checking if user_id is none).

condition:
  - condition: template
    value_template: '{{ trigger.to_state.context.user_id == none }}'

The challenge of applying this technique to your situation is that your automation’s trigger is monitoring a motion sensor which is never turned on/off by a person via the Lovelace UI so the user_id will always be none.

I have an idea for how to achieve your goal but first I need to test it before I propose you try it.