Automation differentiating whether triggered by 'service light.' or light button

I would like to make my automation for a specific light (triggered by the light being switched on) become different whether the light was switched on by hand or by another automation or a scene.
I don’t want to put extra code in all corresponding automations and scene triggers. So I want to make an automation triggered by ‘light turned on or off’, and then have a condition that determines if it was triggered either by service.light_on or another service, or by hand. Switching ‘by hand’ means that someone pushed the physical switch on the wall connected to the Zigbee dimmer behind it, connected to the actual bulb. In that case, HA just registered that the light went on, not by some internal mechanism.
Now, there is no entity I can check to base the further automation handling on. How could that be fixed?

Yes there is. In fact there are three properties you can test to determine what switched your light, context_id, parent_id and user_id. The state of these three properties will tell you.

See the examples here:

2 Likes