If you mean a script or automation instead of the dashboard interface changes the switch then you need to look at the parent_id instead. The user_id will be none for both your physical and automated change. Though the parent_id being none could be due to a change by the dashboard interface or the physical device.
If you want to distinguish between physical device, or automation or dashboard you need to check all three contexts.