Entity Attribute stating if state was last changed by UI or by Code/Automation

Context can determine if the change was made by the ui, an automation or the physical device: