timer-machine / timer-machine-android

⏲ A highly customizable interval timer app for Android
GNU General Public License v3.0
193 stars 16 forks source link

[FR] Launch timer on broadcast intent #61

Open Zocker1999NET opened 11 months ago

Zocker1999NET commented 11 months ago

A mechanism allowing third-party apps to launch timers (similar to the schedule) would be really, really helpful (compare to https://github.com/Razeeman/Android-SimpleTimeTracker/issues/11). This could then by triggered by other apps (Automate, Easer, Home-Assistant, …) allowing more advanced schedules.

Context

I want a timer to start when I wakeup (or more certain, a fixed time after that). This app’s scheduling feature is not enough as I wake up every day at a different time, depending on how long I was awake. Changing a schedule everyday is not feasible for me as I will forget that I need to adapt that app as well (sometimes even forget to adapt my alarm). However, my Home-Assistant already knows & detects it when I (want to) wake up (it reads the phone’s alarm, detects longer usage of phone and if I turn on the light). In this case, Home-Assistant could just trigger the timer of TimerMachine by sending an intent broadcast (e.g. my Home-Assistant already triggers time tracking on SimpleTimeTracker in some cases).

PS: I love the customization possibilities of this app :heart: That’s why I want to integrate it in my daily life with the help of automations.

DeweyReed commented 11 months ago

The app supports Tasker plugins and events, and they also work for Automate.

Zocker1999NET commented 10 months ago

Oh, you probably mean the tasker API? I did not know something like that existed in the first place.

I mainly use Home-Assistant for triggering automations on Android, before I used Easer; both do not support that API directly. I won't use Automate & Tasker as those are not open source.

If I understand the API from the doc above correctly, it just uses broadcast intents so it should be possible to trigger it via e.g. Home-Assistant. Is there a docu for this API specific to this app?

DeweyReed commented 10 months ago

Home-Assistant supports third-party add-ons, but it looks pretty challenging. I don't have a plan supporting this feature.

Zocker1999NET commented 7 months ago

(Sorry for the late answer.)

I think we have a misunderstanding: I did not ask for specific support with Home-Assistant. I used Home-Assistant as an example as that is a software which I would like to integrate with this app.

What I mean is that this app could implement specific broadcast intents it listens to which could trigger actions similar to the existing Tasker API. However, instead of the Tasker API, which’s implementation seems closed sourced (or at least not good documented), such a general API would allow users to integrate this app with others (e.g. Easer, Home-Assitant, etc.).

For example, Simple Time Tracker implemented a such API by defining some app-specific broadcast intents it listens to. That API is documented here.

Home-Assistant, on the other hand, implements a general feature allowing users to send broadcast intents via their companion app, documented here.

This allows users to integrate those two apps/services together (e.g. letting Home-Assistant starting the "sleep" activity on the time tracker when I turn off my lights) without both of them providing explicit support for each other (a config example is attached below). This also allows users to integrate Simple Time Tracker to Tasker or Automate, as those also allow users to send arbitrary broadcast intents. Through the special Tasker API (usage documented here) seems to provide a more user-friendlier way, as Tasker can so list all actions supported by a specific app.

As of now, this app seems to only support the special Tasker API. And as that specific API has no good public documentation (I haven’t found one so far), this does not allow integration with other automation apps. A more general broadcast intent API could provide support for that and (I assume, I might be wrong) should be fairly simple to implement. In case of Simple Time Tracker, it required changes to the manifest and adding a relatively simple broadcast listener; this was the first commit, which also adds a documentation of that API into the app.

I hope this makes my point clear. I accept it if you do not want to implement this yourself, it would be great if you would accept a PR implementing that.

Config Example for Integrating Home-Assistant to Simple Time Tracker The Simple Time Tracker API looks like this [quoted here](https://github.com/Razeeman/Android-SimpleTimeTracker/issues/11#issuecomment-1297153794): Action - "com.razeeman.util.simpletimetracker.ACTION_START_ACTIVITY" or "com.razeeman.util.simpletimetracker.ACTION_STOP_ACTIVITY". Extra - "extra_activity_name" with activity name that should be started or stopped. Package - "com.razeeman.util.simpletimetracker". Optional parameters for starting activity: Extra - "extra_record_comment" with record comment. Extra - "extra_record_tag" with the name of a record tag. In Home-Assistant, a service call which calls this API may look like this: ```yaml # untested config, for demonstration purposes - service: notify.mobile_app_ data: message: "command_broadcast_intent" data: # package name of the target app intent_package_name: "com.razeeman.util.simpletimetracker.ACTION_START_ACTIVITY" # action to trigger intent_action: "com.urbandroid.sleep.alarmclock.ALARM_STATE_CHANGE" # extra’s as defined by the API (format is a little bit obscure in Home-Assistant) intent_extras: "extra_activity_name:Sleeping,extra_record_comment:automatically triggered by Home-Assistant" ```
DeweyReed commented 6 months ago

Thank you for the explanation! The app uses the open-sourced Tasker plugin library, although Tasker itself isn't, allowing integration from other automation apps, like Automate.

https://github.com/joaomgcd/TaskerPluginSample

Providing a general broadcast intent to start any timer should be easy, but the tricky part is ensuring the app can start in the background, which is getting harder and harder as Android evolves. I'll look into it and see what I can do.