Toggle android focus mode from home assistant

I’d like to enable android focus mode on my phone when my phone is in my office. I can already detect the latter with ble tracking.

I currently use android wellbeing app for focus mode on my phone, which can be enabled and disabled in the quick settings menu of my phone. However, there are also other apps available that could be used, for example “Stay Focused”

In know there are a few things I can trigger on my phone from home assistant, with notification commands, like toggling dnd mode, which comes close (and I already use it when the phone is in my bedroom).

I thought I might be able to do it by broadcasting an intent? But I don’t know what to send

Any ideas?

Tasker can do this. Communication between tasker and HA via Tasker MQTT plugin.

I could not find how tasker could do this. I found that tasker is able to enable focus mode, but not to disable focus mode. That seems to be a limitation of the digital wellbeing app.

What I ended op doing is the following

  • I created a scene in tasker that is a fullscreen black page with just the word “focus!”
  • I created a profile in tasker that shows the scene whenever the screen is unlocked
  • I created another profile that turns on the previous profile when a system intent is received with the action “FOCUS_ENABLE”
  • I created yet another profile that turns it off on “FOCUS_DISABLE”

In Home Assistant, in an automation, I can send a “command_broadcast_intent” message:

service: notify.mobile_app_xxxxxx
data:
  message: command_broadcast_intent
  data:
    intent_package_name: net.dinglisch.android.taskerm
    intent_action: FOCUS_ENABLE

This is not completely the same as using focus mode on the phone, but has the same effect, it reminds me not to use my phone.

Using intents to trigger tasker profiles seems to be the cleanest way to do this.