Distinguish between manual switch and automation

Hi everyone,

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”.

1 Like

The only way I know of is to have the automation turn on an input_boolean when it switches on the light.

If the boolean is on it means the light was turned on by the automation, if it’s not it wasn’t.

But how do I turn the boolean off again. An automation triggered by the state of the light would also fire when triggered by the motion sensor

I assume you have an automation to turn the light off again after no more motion so use that to turn off the boolean.

This kind of question is asked often but there aren’t many good workarounds for it. there always seems to be compromises.

There are multiple solutions depending on the situation. It all depends how the switch and motion sensor are linked to the link.

When an automation is triggered, the trigger variable (the documentation used to refer to it as the Trigger State Object) contains context. For example:


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.