i have some hallway lights (controlled through a Fibaro z-wave switch) which can either be turned on and off by a motions sensor or by operating the wall switch.
Is there any smart way (without using too many input variables and stuff) to distinguish between “Has been turned on/off by motion sensors (=automation)” and “Has been turned on/off by all switch”.
When an automation is triggered, the trigger variable (the documentation used to refer to it as the Trigger State Object) contains context. For example:
trigger.to_state.context.user_id
If a person, who is logged into Home Assistant with their User account, turns on a light via the UI, and this action triggers an automation, then context.user_id identifies the User account (although not by name but by an account identifier; to get the name you have to perform a search using the identifier). Anyway, that is currently all that Home Assistant can tell you about who did what.
FWIW, I also use another home automation system and it can tell you the source of every action (i.e. it can tell you if it was another automation or script that caused it or an integration which would mean the source was the device itself). Maybe some day, this level of visibility will also be available in Home Assistant.