Detect trigger by service

Hey everyone.
I have a light switch light.balcony which I can switch using three different ways:

  1. with my hand
  2. through HA
  3. through HA automation when motion is detected

When I look to the logbook I see those different switches. And now is the question how I can detect those different switches in automation and use them?

For example I want to do “A” when I turn switch by myself. Or I want “B” when switch was turned on through the automation when motion was detected.

Here’s a logbook. And I hope that I made myself clear :slight_smile:

You may be able to use data.new_state.context.user_id. For example, when turned on through HA, it knew it was by Lev, as that was the account logged in. I don’t use HA automations, so I’m not sure what will show up in that case, but with luck it’s different (possibly the Supervisor account or the one created during setup?). I use Node Red for automations, and it is authenticated with a separate login, so I can differentiate. If I turn off a device at the switch, the userid is null.

Refer to the table in the following post


That’s it! Thanks alot.

1 Like