Right now context only contains an id, user_id, and parent_id. It would be very useful to have additional information available in context so that automations may react not only to a state changing but also what caused the state to change. To do this context could be expanded to include the following:
root_entity_id: the entity id that started the overall set of state changes / events
entity_chain: list of entity ids starting from root_entity_id that led to this current context
With these two fields we could support the following use cases:
- Only trigger an automation if a state change was by an interaction with a particular physical device. Ex: Disable motion lighting auto-off automation when someone changes light level from a physical switch but not when light level is changed by other automations.
- Only trigger an automation if a state change was caused by a particular other automation or script. Ex: Ignore light brightness change if the change was triggered by a circadian lighting automation.
The ability to customize context would also be useful. For example if an automation could add arbitrary data to context (like event_data but available to all things that change as a result of the automation’s actions). That would allow for significantly smarter automations that can add context about why changes are happening so that downstream consumers of changes can make better decisions.