I’m experimenting with an automation where I need to do conditions based on what actually triggers a state change, so it looks like context
(id
, parent_id
and user_id
) is the most useful for sorting that out. However, I couldn’t find detailed documentation on what those mean.
I created a small automation to try a few things:
alias: TEST self-trigger
mode: queued
trigger:
- platform: state
entity_id:
- light.kitchen_main
action:
- delay: '00:00:10'
- service: light.toggle
target:
entity_id: light.kitchen_main
For reference, light.kitchen_main
is a Zooz ZEN32 switch, and references both the physical button and the actual light (relay).
I triggered the automation in a few different ways and compared the traces, but it doesn’t totally make sense to me.
Raw results
Press physical light switch
this:
context:
id: "01GWTTCKR661MQ09AMC3C7NQ9N"
parent_id: null
user_id: "9d0e6801adcc465099cce98b282c2be6"
trigger:
from_state:
context:
id: "01GWTPDXQTJDHSZD9R53VWQZ3K"
parent_id: "01GWTPDXQKBT4M6YBCYK1EFR6H"
user_id: null
to_state:
context:
id: "01GWTTCYQ8GEKYG3GNDF797JVS"
parent_id: null
user_id: null
10 seconds later, automation toggles light, triggering itself to start again
this:
context:
id: "01GWTTCYQHHZ4X465GEBHCZE8E"
parent_id: "01GWTTCYQ8GEKYG3GNDF797JVS"
user_id: null
trigger:
from_state:
context:
id: "01GWTTCYQ8GEKYG3GNDF797JVS"
parent_id: null
user_id: null
to_state:
context:
id: "01GWTTCYQHHZ4X465GEBHCZE8E"
parent_id: "01GWTTCYQ8GEKYG3GNDF797JVS"
user_id: null
Created a second automation that toggles the light, “Run” manually
this:
context:
id: "01GWTTHNPM2Y2NCQDW3YHTDKNF"
parent_id: null
user_id: "9d0e6801adcc465099cce98b282c2be6"
trigger:
from_state:
context:
id: "01GWTTCYQHHZ4X465GEBHCZE8E"
parent_id: "01GWTTCYQ8GEKYG3GNDF797JVS"
user_id: null
to_state:
context:
id: "01GWTTJ4NDTJ6WXQG5VRVY75VY"
parent_id: null
user_id: null
Second automation, triggered by a fixed time condition
this:
context:
id: "01GWTX9YT03EA0P8WWBEMRV11N"
parent_id: null
user_id: "9d0e6801adcc465099cce98b282c2be6"
trigger:
from_state:
context:
id: "01GWTTJ4NDTJ6WXQG5VRVY75VY"
parent_id: null
user_id: null
to_state:
context:
id: "01GWTXAFJDCZAXC20C6FWEX3T8"
parent_id: null
user_id: null
Switch toggled in Lovelace
this:
context:
id: "01GWTYGS1K8WEFTMGWHNT9PASF"
parent_id: null
user_id: "9d0e6801adcc465099cce98b282c2be6"
trigger:
from_state:
context:
id: "01GWTXAFJDCZAXC20C6FWEX3T8"
parent_id: null
user_id: null
to_state:
context:
id: "01GWTYGSG1W3DRFHZMAWN1JWQ5"
parent_id: null
user_id: "9d0e6801adcc465099cce98b282c2be6"
I’ll try to summarize my observations here, based on which of id
parent_id
and user_id
have non-null values.
Trigger Action | this .context
|
trigger .to_state .context
|
Notes |
---|---|---|---|
Physical switch or Another automation |
id user_id
|
id |
id : different valuesuser_id : “owner” user |
Lovelace |
id user_id
|
id user_id
|
id : different valuesuser_id : same (logged-in user) |
Self-triggered |
id parent_id |
id parent_id |
id : same valuesparent_id : same values, and equal to to_state.context.id of the original execution |
?? |
id parent_id
|
id |
id : different values |
I didn’t include from_state.context
because it is always the same as the previous to_state.context
, (which makes sense)
Note: The last situation I found in another automation, but I haven’t figured out how to trigger it yet. I also can’t find anything with that id
in prior traces.
What I’d like to figure out:
- Why is there a different
context
for what I assume is the actual automation (this.context
), and the trigger (trigger.to_state.context
)? I would have assumed the trigger is the context but clearly it’s not. - What does the context
id
represent and where does it come from?- Is there a way to look up what an
id
is, either in templates or the log?
- Is there a way to look up what an
- In what cases is
parent_id
populated? - Is my assumption that
user_id
is the owner user (in case of physical trigger) correct?