How can i determine (in an automation) what triggered e.g. a Light to turn on?
In the Logbook i can see e.g. “turned on by userxyz/automationxyz”
If i could set up an automation “trigger: light1 turned on // condition: turned on = empty / turned on = not by userxyz/automationxyz” i could assume that its been turned on by the regular Wallswitch, and set it to 100% brightness.
That would do the Trick! But what is the corresponding Variable i should check?
By now i tried to find it out by Trial and Error with the Automation above and those Variables via Action/Notify (All with + without “.state” at the End):
{{ trigger.platform }}
{{ trigger.event }}
{{ trigger.entity_id }}
{{ trigger.from_state }}
{{ trigger.to_state }}
{{ trigger.context_id }}
{{ trigger.user_id }}
{{ trigger.parent_id }}
{{ trigger.event.data }}
{{ trigger.event.event_type }}
All threw out either nothing suitable, or nothing at all :-p
If context.id is not null and context.user_id and context.parent_id are null then it’s (very likely) the physical device that was responsible for the trigger.
Based on my own testing, this is combination of values that characterize each action:
Action
id
parent_id
user_id
Physical
Not Null
Null
Null
Automation
Not Null
Not Null
Null
UI
Not Null
Null
Not Null
A more comprehensive list of actions can be found here.
If you are saying that your testing shows that Physical and UI produce identical combinations then, unfortunately for you, there’s no available means of distinguishing between the two.
First of all: Thank you so much for your Effort!
Second: I got it working yeeha - nearly almost!
One Problem, better said strange Behavior, i still dont get: For testing Purpose i hooked up a really basic Automation (At Time xx.xx toggle Device).
That appeared to be physical switching (ID != None, ParentID == None, UserID == None)
But with my already set up, more complex, Automations, they can be correctly identified.
WTF.
Sure, i can and will ignore that, as it doesnt matter by now.
Just to let you (and maybe others with similar Problems) know what caused the irritation (and, in fact, not correct Interpretation).
In Case somebody want to use my “Debugging-Automation”:
It reacts to State Changes for a single Entity. For Action it has those three Options (Automation, Hardswitched, UI), and throws out a Notification with a Human Readable Result.
Last: Thanks again for Patience and Effort, really appreciate it! I just found out i still need to learn way more, as i clearly wouldnt have made it on my own. Great you helping guys are around, i hope soon i can give the community something back!
I have a follow up question on this. Is there a way to specify which device triggered the automation? I have some users who use multiple devices. Other than creating different users for each device, is there a way to do this?
I may have at least some insight into your “strange behavior” - it ties to the type of trigger event in the parent - please see this post in another thread on the same topic - would love to know if anyone has any new insights or ideas.
- condition: template
value_template: "{{ input_allow_device_trigger and trigger.to_state.context.id != none and trigger.to_state.context.parent_id == none and trigger.to_state.context.user_id == none }}"
- condition: template
value_template: "{{ input_allow_automation_trigger and trigger.to_state.context.id != none and trigger.to_state.context.parent_id != none and trigger.to_state.context.user_id == none }}"
- condition: template
value_template: "{{ input_allow_ui_trigger and trigger.to_state.context.id != none and trigger.to_state.context.parent_id == none and trigger.to_state.context.user_id != none }}"
I did log the variables using a automation and let an automation toggles a light by time trigger. There is a bug with timer and template triggers. The context is not set correctly. Most of my blueprints and automations are using template triggers.