Hi everyone, I’m relatively new to Home Assistant but have been a long-time programmer. One feature that I feel is missing and could greatly enhance debugging and automation logic is the ability to track who or what changed the state of an entity.
In many programming environments, it’s common to have both a last_triggered
(timestamp) and a last_triggered_by
(the ID of the user, service, or automation responsible for the change). While Home Assistant provides the last_triggered
timestamp, there’s no equivalent field to show what caused the state change.
Proposed Solution:
I propose introducing a new field in the attributes of each entity, such as:
last_triggered_by
: Contains the ID or name of the person, automation, or service responsible for the last state change.last_triggered_by_type
: Specifies the type of entity responsible, for example:person
,automation
,service
, ordevice
.last_triggered
: The timestamp of the last change.
This information could be recorded alongside the existing last_changed
timestamp, providing more detailed state change context.
Use Cases:
- Debugging Unintended State Changes:
- When an entity’s state changes unexpectedly, it would be much easier to identify whether the change was triggered by a person, an automation, or an external service.
- Example: If your thermostat unexpectedly changes temperature, you could check if it was manually adjusted by a user or triggered by an automation.
- Improving Automation Logic:
- More intelligent automations can be created by referencing who or what last interacted with an entity.
- Example: If a person manually changes the temperature, the automation could be temporarily paused to avoid overriding the manual change.
- Enhanced Security and Auditing:
- For security-critical entities (e.g., door locks, alarm systems), tracking who last changed the state would allow better monitoring and auditing of important actions.
Example Implementation:
Each entity could have two new fields added to its attributes:
{
"last_triggered": "2024-10-24T15:35:00.000Z",
"last_triggered_by": "person.kate",
"last_triggered_by_type": "person"
}
This information could be made available through the same API and UI views that display current entity attributes.
Conclusion:
By adding last_triggered_by
and last_triggered_type
attributes, Home Assistant would provide a more complete picture of entity state changes, improving debugging, automation design, and security tracking. This feature could benefit both advanced users and newcomers trying to understand their smart home’s behavior.
Thanks for considering this feature, and I’d be happy to provide further feedback or testing if needed!