Tasker is the best automation app for Android devices. It can hook into practically any event and trigger whatever action you want. If you also install its companion app, AutoRemote, then you can trigger tasks on your phone from any web client, such as HomeAssistant.
Here are some example automations