LightBlog

mardi 4 avril 2017

How to Control your PC from your Android Device with Tasker [Part 4 – Screen Menu]

Ever used an app such as Join, Pushbullet, or Unified Remote and wished there was more they could offer? Looking for a way to control your PC from your Android device in a fully customizable way? Using the power of Tasker, AutoRemote, and EventGhost, we can integrate our Windows PC with our Android device to do anything we want.

This is the last part of this series. Please make sure you have read at least part 1. Part 2 and 3 expand on this work and are definitely worth checking out, too! There is also a video guiding you through these steps.

This sub-menu will control the screen timeout on a PC. I have added it, as I want to have an easy control over the timeout when I’m using a remote desktop. At the end of the tutorial, I will also show you how to set up other actions. The full project files are available at the end of this article for you to import.


EventGhost

The set up is very similar to the volume menu back in Part 2 of the tutorial. After an AutoRemote action is issued, EventGhost changes the screen timeout option on the PC then reports back to the device. Repeat this for each timeout option you want to have. For the sake of consistency, I have four.

You should know how to set up a trigger and issue the response already, if you’ve been following the previous tutorials (this is part 4 after all), so here is the screen action:

powercfg -Change -monitor-timeout-ac 5

Use the Windows Command option in EventGhost actions. Change the value to any number you wish.


Tasker

Open Sub-Menu Profile/ SubMenu Open

Create a new notification and link it to IF %ancomm ~ openscreen. If the screen icon from the first row is pressed  – this action will be called.

The notification is configured as follows:

  • Buttons – as per your liking, make sure the first row is consistent.
  • Actions – the first row starts with open (see template) but the screen menu icon should have openclose action assigned instead. The second row has actions ending with ‘‘…pc”. I used screen1pc,screen5pc,screen30pc,screen120pc.
  • Color – only a second color should be different.
  • Prefix for actions – buttontwo

Submenu Actions/Send AR

Since the framework is already done, we don’t need to add anything else. All that hard work from Part 1 onwards finally paid off.

PC Feedback/Notification

EventGhost will issue a reply when the screen timeout is changed through our screen menu. To simplify the process, the AutoRemote message is sent in this form pc=:=screen(value). This means that we have to intercept all the messages starting with (regex)screen.*

In a similar way to the power menu, I’m creating a variable %PcScreen and simply setting the value of it to the %arcomm. The value will get assigned to the default notification. At this stage go and update the default notifications (the ones that have only 4 icons) with this variable. Each notification should have %PcPowerontime,%PcVolume, and %PcScreen in the text field.

And that is all! Here’s a bonus “light menu” if you have some smart home lights.


Bonus – Lights Menu

Open Sub-Menu Profile/ SubMenu Open

Create a new notification and link it to IF %ancomm ~ openlight If the lights icon from the first row is pressed, this action will be called. Update the default notification and change the column count to 5 (see Part 1 of this series). You will have to change the following in each notification created so far:

  • Column count (5:4) to reflect number of your menus
  • Actions – add new action everywhere (one for menu, one for submenu)
  • Enabled – 1,1,1,1,1 (equal to number of icons)

Notification is configured as follows:

  • Buttons – as per your liking, make sure the first row is consistent.
  • Actions – the first row starts with open (see template) but the lights menu icon should have openclose action assigned instead. The second row has actions ending with ‘‘…tsk”. I used lighttsk as I only have one smart light.
  • Color – only a second color should be different.
  • Prefix for actions – buttontwo

Submenu Actions/Send AR

Our profile can intercept only actions ending with ‘…pc’, therefore we have to modify it. The profile context will respond to the regex “pc|tsk” and the task will contain an IF statement when sending the previously made AR action – IF %ancomm =R pc.

Add another action, Perform Task, and create a condition IF %ancomm =R tsk. The action to perform is %ancomm. It’s easier to rename a task to fit the bill than create a name matching profile.

Lighttsk Task

I only control one light at this time. The controller is simplistic as I made the WiFi module myself and I’m currently working on it. Here is how you create a toggle switch.

Create the variable %lightStatus and set it to 0. I’m using the HTTP Get request to turn on/off the light. When the %lightStatus = 0 the light is off, and when it’s 1 the light is on. Create the IF condition that checks the value of the variable, and sets the correct action then stops:

Task Description

lighttsk (26)
        A1: If [ %lightState ~ 0 ]
        A2: HTTP Get [ Server:Port:192.168.1.163/?pin=ON1 Path: Attributes: Cookies: User Agent:
            Timeout:10 Mime Type: Output File: Trust Any Certificate:Off Continue Task After Error:On ] 
        A3: Variable Set [ Name:%lightState To:1 Recurse Variables:Off Do Maths:Off Append:Off ] 
        A4: Stop [ With Error:Off Task: ] 
        A5: Else 
        A6: HTTP Get [ Server:Port:192.168.1.163/?pin=OFF1 Path: Attributes: Cookies: User Agent:
            Timeout:10 Mime Type: Output File: Trust Any Certificate:Off Continue Task After Error:On ] 
        A7: Variable Set [ Name:%lightState To:0 Recurse Variables:Off Do Maths:Off Append:Off ] 

For any other setups simply run the task that is named in the same way as the %anconn message issued by the sub-menu. If you need more than one menu, rinse and repeat the steps.


Download and Import

As always, I am providing a download link to the Tasker project file you can download and import. Download the below .prj.xml file and save it anywhere on your internal storage. Open Tasker and disable Beginner Mode in Preferences. Then, back at the main screen, long-press on the home icon in the bottom left corner. You should see a pop-up with an “import” option. Select that and look for the project file you just saved and select it to import. If successful, you should now see a new tab/icon at the bottom that contains all of the Profiles and Tasks that we mentioned in this article.

Download the PC Control Tasker Project from AndroidFileHost

The Material Design Icons that I used in this project are also found in this zip. Simply unzip the folder with the icons to the root directory of your internal storage. Finally, the configuration file for EventGhost that you can import is also contained in the above zip. Please note that I’ve removed my AutoRemote API key from the configuration file. You’ll need to enter your own to make this work.

This concludes this four part series on how to control your PC from your phone using Tasker, AutoRemote, and EventGhost. We hope that by this point you’ve learned how to make your own integrations. The possible customizations here are endless, limited only by your own imagination. While you can go the easy route and use Unified Remote, if you’re looking for something more customizable to your own preferences, then hopefully you’ve found my tutorials useful.



from xda-developers http://ift.tt/2nBGcTf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire