HomeTaskerTurn any dock into Smart Dock with Tasker

Turn any dock into Smart Dock with Tasker

Continue where you left off

How often do we get engrossed with something on our mobile phones? It could be a passionate conversation with your buddy or another rabbit hole with dozens of links to follow. It often leads us to our computers and laptop to continue our exploration. If only there was a seamless way of transitioning the content of your mobile onto the computer without messing around with extra buttons. Something like a Smart Dock…

Smart Dock

I will be honest with you guys, it only recently occurred to do this, even though I had everything needed in my previous Tasker projects, just not in this specific combination. The smart dock is a virtual concept. You can use any dock, phone holder or simply replace the trigger with something more suiting your needs.

I went with the dock, as Android 10 removed, a very much liked by me, custom icons from the navigation bar. I had an array of insanely useful actions, which became obsolete thanks to another Android update that curbed personalisation. The Navigation icon is still there in Android (enable Accessibility button to see it), but not available to us – common folk.

How does it work?

Tasker detects when the phone is docked (or put into a certain position) thanks to the relatively new sensors feature and sends the information about the application or page currently opened on your phone to an active computer. What’s an “active computer” you may ask? In case you have more than one device at home, Smart Dock can detect which computer to cast the information to.

You have the ability to define smart dock behaviour. It’s possible to detect various docks, pick applications that are cast to computers or even add operational hours if you want to personalise the behaviour further. In this project I will show you how to make it work with the 3 most common mobile use cases:

  • application
  • web page
  • YouTube

I mentioned YouTube separately, as resuming a specific video is slightly more complicated and requires a modified task. To make it all happen, you will need the following:

Smart Dock – the trigger

I have a Xiaomi Battery Dock (review), which I modded recently to make it truly wireless by cutting the cord off and replacing it with a USB-C port. It’s a perfect companion and my phone is often docked next to my computer. The phone starts wireless charging when it’s docked, and I can define the spatial orientation by pulling raw data from Tasker Sensor action. The naming convention for sensors may vary from phone to phone, try a couple of them responsible for orientation in 3D. I also tied that with Screen On, so I don’t have accidental triggers unnecessary.

Tasker Profile: Docked
Profile: SD Docked
	Restore: no
	State: Power [ Source:Wireless ]
	State: Any Sensor [ Output Variables:* Type:9 Interval (ms):1000 Interval Type (Check Help):Throttle 
	Convert Orientation:Off ] 
	[ %as_values1 > -1.03828 & %as_values1 < 0.96515
	& %as_values2 < 10.19302 & %as_values2 > 8.18816
	& %as_values3 > 2.41429 & %as_values3 < 4.42737 ]
	State: Display State [ Is:On ]   

If your dock has no charging, sensor data should be enough to detect the position. Feel free to experiment with extra conditions until you are happy with the result.

Active PC

I covered this topic extensively in my other write up. If you want details, read that. In short, EventGhost is installed on each computer and it uses AutoRemote to send the information with the name of the computer whenever the system boots or stops idling. Tasker stores the name of the computer that had been used last in a variable %ACTIVEPC.

Tasker Profile: Active PC
    Profile: SD Active PC 
    	Restore: no
    	Event: AutoRemote [ Configuration:activePC ]
    Enter: SD Set Active PC 
    	A1: Variable Set [ Name:%ACTIVEPC To:%arcomm Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:On ]     

Smart Dock cast application to computer

Most of the apps will open as URL counterparts on a computer, but you can get more creative with it. When a compatible app is opened on your mobile, it sets a variable %APPCURRENT to its name. This is used by the main profile to determine what IF action Tasker will execute.

For each app, you will have to create a separate profile that sets the %APPCURRENT on entry and resets the value to none on exit. To open the associated URL on a computer, you have 2 choices:

AutoRemote + EventGhost

EventGhost has the ability to open web pages on your PC based on triggers from AutoRemote (more about AutoRemote). You can send a message to open a hardcoded in EventGhost URL, or specify the URL in Tasker and sent it from there.

Based on %APPCURRENT and target device (%ACTIVEPC) AutoRemote message is sent to EventGhost and executed. I picked the dynamic EventGhost profile as I can use it later with Chrome URLs. My AutoRemote message looks like this URL=:=%CLIP (or fixed URL).

On the EventGhost side, a Python script is handing Chrome and opening the browser windows:

import webbrowser
url = eg.event.payload.arcomm
chrome_path = 'C:/Program Files/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open(url)
Join

It's possible to do this without EventGhost, but you will lose the ability to set an active PC. Join has the ability to push an URL to another device, which will open it automatically. If you only have one computer, you will find the Join route easier.

URL Pushes for need a target device (%ACTIVEPC) and URL to push, which is hardcoded based on %APPCURRENT value:

%APPCURRENTURL
Facebookhttps://www.facebook.com
Twitterhttps://twitter.com/home
Facebook Messengerhttps://www.facebook.com/messages/

and so on... In both cases, you will need either AutoRemote or Join extensions added to a Chromium based browser.

Tasker Profile: Set Active app: Facebook
    Profile: SD Facebook (4)
    	Restore: no
    	Application: Facebook
    Enter: SD ActiveApp Facebook 
    	A1: Variable Set [ Name:%APPCURRENT To:Facebook Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:On ] 
    
    Exit: SD ActiveApp Reset 
    	A1: Variable Set [ Name:%APPCURRENT To:none Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:On ]     
Tasker Task: Dock+
	
	A13: If [ %APPCURRENT ~ Facebook ]
	
	A14: [X] Join Send Push [ Configuration:Url: https://www.facebook.com/
Device Name: %ACTIVEPC Timeout (Seconds):60 Structure Output:On ] 
	A15: AutoRemote Message [ Configuration:Recipient: %ACTIVEPC
Message: URL=:=https://www.facebook.com/
Time to Live: 30 Timeout (Seconds):200 Structure Output:On ] 
	A16: End If 

Smart Dock - Chrome URLs

Add Chrome (or whatever web browser you are using) to the list of apps that contribute their name to %APPCURRENT. Capturing URL is actually hard due to security concerns. You don't want to expose that natively to other apps you have on phone. This is where AutoInput comes in handy.

I use it more nowadays thanks to the ability to enable and disable the service as needed. To capture URL, AutoInput needs 2 actions: tap on the URL field then tap on "copy". If the downloaded profile isn't working for your browser, you need to re-teach these.

A copied URL is stored in %CLIP and can be easily sent to EventGhost via AutoRemote (optionally to Join). To display the page on your computer the EventGhost profile from the application section is used.

Tasker Task: Facebook

	A7: If [ %APPCURRENT ~ Chrome ]
	
	A8: AutoInput Action [ Configuration:Type: Id
Value: com.android.chrome:id/url_bar
Action : Click
Manage Accessibility Service: Enable Before Action Timeout (Seconds):10 Structure Output:On Continue Task After Error:On ] 
	
	A9: AutoInput Action [ Configuration:Type: Text
Value: Copy link
Action : Click
Manage Accessibility Service: Disable After Action Timeout (Seconds):5 Structure Output:On Continue Task After Error:On ] 
	
	A10: [X] Join Send Push [ Configuration:Url: %CLIP
Device Name: %ACTIVEPC Timeout (Seconds):60 Structure Output:On ] 
	A11: AutoRemote Message [ Configuration:Recipient: %ACTIVEPC
Message: URL=:=%CLIP
Time to Live: 30 Timeout (Seconds):200 Structure Output:On ] 
	A12: End If 

Smart Dock - YouTube

To make this work with YouTube, we have to change the AutoInput actions. I'm still going for the share option, but you could always take a look at Cast action and open the browser in a YouTubeTV mode instead or cast it to a smart TV or projector.

While Casting might be better for resuming the playback, my method only launches the video URL from the beginning. It's not ideal, but with a mouse at your disposal, finding the moment on the timeline where you left off is a minor inconvenience.

For YouTube, select share and then copy link action. By now you should feel very familiar with the process and how the URL will be handled.

Tasker Profile: Facebook

	A1: If [ %APPCURRENT ~ YouTube ]
	
	A2: AutoInput Action [ Configuration:Type: Text
Value: Share
Action : Click
Manage Accessibility Service: Enable Before Action Timeout (Seconds):10 Structure Output:On Continue Task After Error:On ] 
	
	A3: AutoInput Action [ Configuration:Type: Text
Value: Copy link
Action : Click
Manage Accessibility Service: Disable After Action Timeout (Seconds):5 Structure Output:On Continue Task After Error:On ] 
	
	A4: [X] Join Send Push [ Configuration:Url: %CLIP
Device Name: %ACTIVEPC Timeout (Seconds):60 Structure Output:On ] 
	A5: AutoRemote Message [ Configuration:Recipient: %ACTIVEPC
Message: URL=:=%CLIP
Time to Live: 30 Timeout (Seconds):200 Structure Output:On ] 
	A6: End If 

Final thoughts

I'm still sour over my NavBar actions not being used any more. I noticed that Tasker gained the ability to add Smart Home tiles into notification shade, which gave me a couple of ideas. Expect something along these lines soon. I hope you enjoy the project. Let me know what do you think in this Reddit thread.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

How to wake on LAN computers and put it to sleep with Power Menu,...

0
How to Wake on LAN properly via Android, Alexa, Google Assistant and Web

7 awesome Bluetooth keyboard shortcuts for Android

0
7 unique Android shortcuts that you can add to any Bluetooth keyboard.

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile

One thing that Join app can’t do and how to fix it with Tasker

0
It's not possible to share the clipboard automatically between join accounts registered to 2 different emails. But you can fix this with tasker.

Essential Guides

Tasker: Seconds into DD:HH:MM:SS (dynamic)

0
It's time to.... ok it's a pun, but I will show you how to master time and convert seconds to DD:HH:MM:SS dynamically

4 ways to organise Tasker projects

0
Keep your Tasker tidy!

A better way to store Tasker credentials

0
The more clever way of managing credentials

Annoyed with dozens of AutoApps populating your app drawer? Here is a fix!

0
Clear your app drawer from the clutter in seconds

Putting AutoTools pie chart to a good use – SSID logger

0
Who wants a piece of the pie (chart)?