Trigger automation on user user-driven state change

Hi!

TL;DR: I want device to be temporary excluded from automation when user interacts with it.

I have an automation that control a certain device. This automation takes into account current schedule, settings, presence at home etc.

A the same time user can manually control device from the Home Assistant UI and using control buttons on device itself (state changes are reflected to Home Assistant).

I want device to be excluded from automation for several hours if user interacted with it (both with on-device controls or from HA ui).

My idea is to create a boolean input “User interacted with device” if it is true do not apply automated changes. The only problem - I somehow have to set it to true ONLY if state change was made by user, not from other automations.

Is it possible to detect it? Or maybe I should archive what I need somehow differently?

@yavanosta You ever figure this out? This is EXACTLY what I want/need to do as well. I’ve used some other constraints to limit my automation, but there are still some edge cases I can’t prevent without being able to detect this. Seems like it should be pretty easy since the logs clearly show whether a user or an automation made the last change to a device, but I haven’t figured it out.

The context object contains information indicating who or what was responsible for causing the trigger.

Here’s an example employing context.

Unfortunately, at least in my case, the trigger isn’t the thing that I want to see who or what changed. General simplified automation:

Light sensor sees it’s bright outside and triggers an automation to turn off the lights.

Before turning them off, check whether an automation or a user made the last change to them (e.g. make sure a user didn’t set them the way they want them).

If you want to know who did what (and when) to an entity, all of that information is stored in the states table of Home Assistant’s database.

Sorry for the late reply. Thanks for the info!

I haven’t previously messed with the database in HA; honestly feels like more effort than I want to put into this. I was just hoping/thinking that there would be a more user-friendly way to pull this data out inside an automation.