Trigger only on state change not initiated by HA

Hi, apologies if this has been answered previously, but the topic is really hard to search for.

Is it possible to trigger an automation based on a device changing state, but ONLY when that state change was not initiated by HA?

For example, let’s say I have a switch that can be controlled via MQTT messages from HA, but ALSO from an external source. When HA receives a state change message from the switch, is it possible to detect that the change was commanded by the external source and not by HA?

No, this is not currently possible with HA. It is an often requested feature though.

As a work-around, you can create an input_boolean for control from the front end and hide the switch. Then you would be able to automate based on the input boolean or externally controlled switch states.

Thank you. I did end up using an input_boolean.