What invoked the action

Hi Guys.

I’m honestly not even sure what to google for this one.

I have Home Assistant up and running no problem.
I also have a couple of Sonoff devices linked to it with no problem.

I have a specific sonoff switch that I use to control the well pump.
What I want to do though is to figure out when the pump (Sonoff switch) was activated using the built in button and when it was activated using Home assistant.

We use the well water to keep a 2000L tank full of water that the house uses and then we also use the pump for day to day irrigation.

I have set up a 30min delay on the sonoff switch to automatically switch it off in the event that we forget to but this is now not enough time to fill up the tank.

I have float switches in the tank that is connected to esp that does work but the goal here is that if the sonoff switch was pressed on itself, then run for 30 mins, if the esp invoked the switch, then run until upper float switch has been reached… even if that may take 2 hours (for argument sake.)

The logbook is your friend. Once you have identified when the entity you’re interested has acted, you can then add it to the history view, along with other entities you think may be related to the issue you’re investigating.