Checking last state change initiator

I’m working on an automation for a motion sensor to turn on/off the light. However if the light was already manually turned on, I’d like to not have the motion sensor control it. Humans take priority over the motion sensor.

I don’t see any way to detect what initiated the turning on of the light. Any ideas on how to accomplish this?

You can use a condition that says the automation should only work if the light is turned off?

 condition:
  condition: state
  entity_id: light.living_room
  state: off
1 Like

Make a virtual switch (template switch, MQTT switch or other switch that is not a physical switch).

Make an automation that sets the virtual switch off when the state of the light switches to off.

Make the automation that turns on the light also turn on the virtual switch at the same time.

If the light is manually turned on, the virtual switch will still be off.

Make the automation that turns the light off conditional on the virtual switch being on.

1 Like

The work of the ‘initiator’ is already crooked… Arranging checks in order to build automation for oneself, in order to at least somehow correctly indicate the initiator, is a gesture. It would be better if they made an additional parameter to different services for manually entering the initiator…