This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.

[TUTORIAL] Using Tasker together with Homey

PhuturistPhuturist Member
edited December 2017 in Questions & Help
I have seen some requests on the forum for more details about using Tasker in combination with the Homey API. Since I had some time this evening I have tried this out myself with a little help of superice and decided to share my experiences here.

What is this tutorial for?

If you need to read this, then this tutorial is probably not for you. I'm going to assume you know your way around Tasker (Android Automation App) and you know how to create Profiles and Tasks within Tasker. If so, with this tutorial you should get an idea on how to use Tasker in combination with the Homey API.

Index of Tasker Use Cases


Replace the Homey presence detection with the more reliable Tasker presence detection

In this tutorial I'm going to set the presence of a user based on a Profile event within Tasker (for instance, being connected to you Home Wifi network). In the next post a tutorial on how to add Homescreen shortcuts to trigger flows will follow.

Prerequisites

  • A working Homey
  • An Android smartphone with Tasker installed
  • A Tasker plugin called RESTask installed which enables an extra plugin in Tasker
  • The external URL to your Homey (it looks something like this: https://ID.homey.athom.com/ and can be found by going to my.athom.com and login to your Homey from outside your own network)
  • Your bearer token (can be found by going to my.athom.com and inspect the URL linked to the Homey icon. The url contains a parameter called bearer_token which is the token you need to have)

Creating "At Home" Task

Add a new task in Tasker called something like "At Home". Create a new action within the task and select the RESTask plugin (it's under the plugins category). Click on the configuration button and use the following settings for configuring the RESTask action where you replace the tags with your own external URL and bearer token.

Settings Tab of new RESTask action

  • Request Type: PUT
  • Host: https://ID.homey.athom.com/api/manager/presence
  • Enable Custom Body: Yes
  • Custom Body: {"present": true}

Header Tab of new RESTask action

  • Add new header with name "Content-Type" and value "application/json" (without the quotes)
  • Add new header with name "Authorization" and value "Bearer <<token>>" (without the quotes and replace <<token>> with your token and leave a space between the word Bearer and your actual token)
Save and test the action, you should now be able to set the presence of the user with the bearer token you used as being at home.

Creating "Away" Task

Add a new task in Tasker called something like "Away". Create a new action within the task and select the RESTask plugin (it's under the plugins category). Click on the configuration button and use the following settings for configuring the RESTask action where you replace the tags with your own external URL and bearer token.

Settings Tab of new RESTask action

  • Request Type: PUT
  • Host: https://ID.homey.athom.com/api/manager/presence
  • Enable Custom Body: Yes
  • Custom Body: {"present": false}

Header Tab of new RESTask action

  • Add new header with name "Content-Type" and value "application/json" (without the quotes)
  • Add new header with name "Authorization" and value "Bearer <<token>>" (without the quotes and replace <<token>> with your token)
Save and test the action, you should now be able to set the presence of the user with the bearer token you used as being away.

With these Tasker Tasks you can create a profile in Tasker that will trigger these actions, for instance based on your smartphone being connected to your Home Wifi network. But better yet, this is just an example on how to use Tasker in combination with the Homey API. You can use the BetterLogic app with it's API to create any kind of variable that you like which you can set with Tasker based on events on your smartphone and you can then create flows within Homey based on the change of this variable. The possibilities are endless! Please share your use cases in this thread as it might help other people as well.
«13

Comments

  • PhuturistPhuturist Member
    edited May 2016

    Creating shortcut buttons for Homey through Tasker by Android

    This tutorial will explain how to create shortcut buttons in Android using Tasker for Android. These buttons can be placed on your Homescreen and trigger any flow you want. In the future this functionality will probably be part of the Homey Android app but for now you can use this tutorial.

    Prerequisites

    • A working Homey
    • An Android smartphone with Tasker installed
    • A Tasker plugin called RESTask installed which enables an extra plugin in Tasker
    • The external URL to your Homey (it looks something like this https://ID.homey.athom.com/ and can be found by going to my.athom.com and login to your Homey from outside your own network)
    • Your bearer token (can be found by going to my.athom.com and inspect the URL linked to the Homey icon. The url contains a parameter called bearer_token which is the token you need to have)
    • BetterLogic app installed and a variable created that you want to update

    Create "Set variable x" task

    Add a new task in Tasker called something like "Set variable x". Create a new action within the task and select the RESTask plugin (it's under the plugins category). Click on the configuration button and use the following settings for configuring the RESTask action where you replace the tags with your own external URL and bearer token.

    Settings Tab of new RESTask action

    Header Tab of new RESTask action (needed from BetterLogic v0.9.0 and higher)

    • Add new header with name "Authorization" and value "Bearer <<token>>" (without the quotes and replace <<token>> with your token and leave a space between the word Bearer and your actual token)

    Create a shortcut on a Homescreen which sets the variable

    Go to one of your Homescreens and start the "Add a shortcut" wizard (most likely by long pressing on your Homescreen and selecting the right option). In the list for adding a shortcut select Task Shortcut with the Tasker logo. In the next list select the task you have just created. Note: you might have to add a task icon to the task before being able to set it as a shortcut by selecting the icon at the bottom right and setting an icon.

    Once done you now have a button on your Homescreen which will set the BetterLogic variable to it's desired value. Based on the change of this variable to a specific value you can trigger any flow within Homey!
  • Nice tutorial! I'm not using Tasker yet, but am definately looking into it soon!
  • @Phuturist nice write-up! My compliments on the clear explanation :)
  • @Phuturist Good tutorials! How did you learn about the presence API? Would be nice to use it with my GPS tracker app.

  • @Phuturist Good tutorials! How did you learn about the presence API? Would be nice to use it with my GPS tracker app.

    By asking @superice for an example on Slack after he offered to do this here on the forum ... :wink: 
  • JesperJesper Member
    edited March 2016
    Hello Phututist

    Thanks for setting up the tutorial. I was just trying to create an at home task. However, when I test the action I get the following error in tasker.

    [Edit]

    Nevermind already got the At home and Away action working in Tasker

    You actually do need a space between Bearer and your token. For me the value for the header authorization looks like this: "Bearer 12324234bfgbgb4234242vdvf335vd43".

  • Jesper said:

    You actually do need a space between Bearer and your token. For me the value for the header authorization looks like this: "Bearer 12324234bfgbgb4234242vdvf335vd43".

    I have made it more explicit in the tutorial, thanks. Also update the shortcut buttons with the new toggle feature and API authorization for the BetterLogic app version 0.9.0 which will be available in the app store soon.
  • PeaoPeao Member
    I am getting an error when testing myRESTask configuration. I double checked it, I can't find any mistake.

    Return code:
    404
    Return data:
    {"status":404,"message":"not_found"}

    The Request Type is correct, the Host is correct and I added a Header with: Bearer XXXXXXXXXXXXX (including the space).
    I tried different types of variables but none is working.
  • not direct related to Homey, but just an example of what is possible with Tasker:
    http://tasker.wikidot.com/profile-index

    could be interesting for Athom to make a Homey plugin so one could directly select device (id) or flows within Homey.
  • Peao said:
    I am getting an error when testing myRESTask configuration. I double checked it, I can't find any mistake.

    Return code:
    404
    Return data:
    {"status":404,"message":"not_found"}

    The Request Type is correct, the Host is correct and I added a Header with: Bearer XXXXXXXXXXXXX (including the space).
    I tried different types of variables but none is working.
    Are you using the correct request type (PUT).
  • PeaoPeao Member
    edited May 2016
    Yes, maybe these screens are helping. [Screens removed from HTML view, because they were too big :smiley: ]
  • PhuturistPhuturist Member
    edited May 2016
    @Peao I noticed an error in the host config of RESTask in my tutorial. It was missing the app name of the Better Logic app. I have edited my tutorial, please update your host in RESTask config.
  • PeaoPeao Member
    Thanks that worked! :smiley: 

  • WeezulWeezul Member
    edited May 2016
    Excellent write-up! Is it possible to disable Homey automatically updating presence values? I would like the presence to only change when I set it manually via the API

    EDIT: I just realized that Homey presence by default only gets updated in the mobile app. This used to be parametrised in the app, so I guess once the Setup view is back, this problem would resolve itself :)
  • WeezulWeezul Member
    I keep getting an error that the presence is invalid. Also calling hte API from directly (I mean, outside of Tasker). I assume I have mistyped something, or has the API changed?

    Body is exactly as specified above:
    {"present": false}
    or
    {"present": true}
  • Weezul said:
    I keep getting an error that the presence is invalid. Also calling hte API from directly (I mean, outside of Tasker). I assume I have mistyped something, or has the API changed?

    Body is exactly as specified above:
    {"present": false}
    or
    {"present": true}
    Nope, still works as described in the tutorial. You must have made a type-o somewhere.
  • WeezulWeezul Member
    Thanks, will check it out again!
  • Hi - great tutorial.

    I found the ID for my external URL homey id by going to the system informatins tab / page, its called "Athom Cloud ID"

    http://[local homey ip]/manager/settings/#homey:manager:system
  • If you have the full version of unified remote android on your phone you can go to tasker -> plugins -> unified remote to send (unified remote) commands to your desktop/mediaserver!
  • @Phuturist
    Thank you very much for the excellent tutorials!

    If you have the full version of unified remote android on your phone you can go to tasker -> plugins -> unified remote to send (unified remote) commands to your desktop/mediaserver!

    So far it is only obvious to me how I can use my phone to send commands to Homey. But how can I use Homey to send commands to my phone?
  • perhaps you should look at the app    HTTP    in the appstore.
    I think that should work for you
  • G4nd41f said:
    @Phuturist
    Thank you very much for the excellent tutorials!

    If you have the full version of unified remote android on your phone you can go to tasker -> plugins -> unified remote to send (unified remote) commands to your desktop/mediaserver!

    So far it is only obvious to me how I can use my phone to send commands to Homey. But how can I use Homey to send commands to my phone?
    As mentioned by WathLamers you can use the HTTP app to send HTTP request but you would need to know the address of your phone. In your home network this is easy but when you are outside it's harder.

    May I ask what you are trying to achieve, maybe there are different solutions.
  • I am trying to switch my monitor output from my standard monitor to projector and vice versa. Right now I am using the IFTT app to create a file in my dropbox. A script on my computer is looking for a file in my dropbox with a specfic name and if it detects on it sends the necessary keystrokes. This does not work really reliable and sometimes has a long delay. I am already using Unified Remote, so I think this might be faster...
  • edited October 2016
    G4nd41f said:
    @Phuturist
    Thank you very much for the excellent tutorials!

    If you have the full version of unified remote android on your phone you can go to tasker -> plugins -> unified remote to send (unified remote) commands to your desktop/mediaserver!

    So far it is only obvious to me how I can use my phone to send commands to Homey. But how can I use Homey to send commands to my phone?
    You can use Homey to trigger IFTTT recipes (with the homey http APP or the ifttt APP), and when you get a notification on your phone with the word "PCOFF" or "PCON" in it: tasker will intercept and send a unified remote command to the only connected server (which is your PC).
     
  • WeezulWeezul Member
    edited November 2016
    Since the last update this (Tasker RESTTasker calling Homey API) is not working for me anymore... I get a result back, but Homey does not register me as "Present"... anyone else have this?

    I also changed phones, so it could be that, but thought I would ask here before starting a possibly painstaking (Typing bearer tokens and long urls into Tasker :P) process of debugging.

    EDIT: Disregard! It is werking afterall
  • So far tasker and Homey work great together! I am thinking of a different way for my phone to get information from tasker. Is there maybe a possibility to get the state of a betterlogic variable? Somehow with a GET request or is that not permitted by Homey?
  • Excellent tutorial! Thanks a lot @Phuturist for showing us how to integrate Tasker and Homey. Working very very smoothly. As a new Homey user, this was somewhere on top of my todo list, you made it a piece of cake for the REST of us (pun intended).

    My phone is usually connected to my LAN via VPN (OpenVPN Connect), so I replaced the external Homey URL https://ID.homey.athom.com/ with the internal Homey URL http://<Homey-IP-address>/ in the RESTask settings, which works perfectly as well.

    The excellent location based profiles in Tasker (using cell tower ID's + wifi networks + GPS, if needed) greatly improve the presence detection en geofencing options for young Homey B)

    Like Phuturist said, as a first "Hello World" example, this is only the beginning. Integrating these two provide nearly limitless possibilities together, and I'm curious what other users have crafted. One of my examples:
    My Tasker calculates how late I'll be arriving home in the evening, triggered by a location I pass on the route from work to home on workday evenings. It automagically informs the home front in advance, with a text message containing the expected arrival time. Till now... because Homey + RESTask open up some very creative options for bringing the news  o:)
  • Thank you for the credits, good to hear my efforts are appreciated.

    I recently created the other was around communication. Something on Homey triggers a flow which sends a request to your phone. This request is picked up in Tasker allowing you to trigger actions on your phone (for instance, I used it to be able to control my robot vacuum cleaner which does not have an open api).

    It requires a paid app called Autoremote. If anyone is interested I could create a tutorial for it.
  • Phuturist said:
     If anyone is interested I could create a tutorial for it.
    I would love to learn about this!
  • G4nd41f said:
    Phuturist said:
     If anyone is interested I could create a tutorial for it.
    I would love to learn about this!
    You can see my Tutorial here: https://forum.athom.com/discussion/2015/android-spotify-deezer-sonos-multiroom-homey-workaround

    It's not the simplest solution since you need IFTTT aswell but it relys on Autoremote aswell. Step 1,2 and 4 are showing how to get homey to trigger a tasker task. You don't need Autoinput beside you would like to create a similar action with screen input on your phone/tablet.
Sign In or Register to comment.