"Quick Settings" Toggle Tiles by Tasker on Android

Preview

Notice the Bulb icon being “clicked” turns on all lights in my bedroom, and changes the colour of the tile!

TL;DR

If you want to get going as quickly as possible, download this GIST on your phone and import it!

Download Link:
https://gist.githubusercontent.com/fanuch/2bd3348b7e982b4aad09cb2943e1cace/raw/bb3056e9ca5564cecaa7713b958252f0eb552e94/home_assistant_quick_settings_tile.xml

Source Code:

Simply click and hold the “TASKS” tab at the top, click “Import” and navigate to the place where you downloaded the GIST.

Click through and change the parts that say CHANGE_ME based on your own settings!

Why

I would like to continue on the good work by @broesie on his post Android: Control Home Automation with Tasker from Quick Toggles to explain how to make toggleable commands through Tasker!

The difference between this example and that of the previous example:

  • Requires one task per toggle, instead of two
  • Can read return data from Tasker for the true status
  • Repeatable use of variables
  • Use of Javascript to cut many, multiple commands to one!

Let's Begin

Create the Task

Click the + icon to add a new task, and call it something meaningful. Note this name will be the word that appears under the tile!

Creating the Variables

For the sake of code re-usability, I would recommend making the following variables: 1. `url` (should be called `domain`) 2. `address` 3. `body`

Create the variable by clicking the + button down the bottom right, and searching for Variable Set

The %body variable is what you would send to HA. You can work out what you need to send by going to the Services icon in the Developer tools, or looking through the forum for examples.

This is the example for the %body variable.

For the %url variable, this should be your dynamic DNS address, or however you access HA. For example https://xxxxxxxxx.duckdns.org:8123 (note, no trailing forward slash at the end! /)

For the %address you will need to work out what that is, but if you wish to toggle a light, it will be the same as mine:

/api/services/light/toggle?api_password=xxxx

note that if you have a password for web access, you place it at the end at the address, as the variable api_password as is above, replacing the xxxx.

Create the Javascript Request

After the variables are set, click the `+` and search for `JavaScriptlet` and add that.

Add the following in the Code section:

var xhttp = new XMLHttpRequest();
xhttp.open = ( "POST", url+address, false );
xhttp.send(body);
var result = JSON.parse(xhttp.responseText)[0].state;

The [0].state at the end will look at the first array returned, and the value of state.

If you have any issues, add flash(xhttp.responseText); after the 3rd or 4th line to see if you are actually getting a response from HA!

If Statement

![11|690x388](upload://b668SYpig8KvSVIfM14FjfBGFFX.png)

For the if statements:

  1. Add an if command
    a. and in the first field type %result and for the comparison, do on.
  2. Add the Setup Quick Settings action after that
    a. For the name, it should be the same as the current task you have made, and are in!
  3. add an else
    a. Tick the +
    b. check %result against off
    c. important step toggle the Status to Inactive! This will turn the icon to a lighter shade

Choose the Icon

  1. Click the “grid icon” at the bottom of the screen
  2. Click on Holo
  3. Choose any icon

Create the Quick Settings Tile

  1. Go to your quick tiles, and drag one of the Tasker tiles into your drawer as seen in the video.
  2. After exiting the edit, you should see your unset Tasker quick setting.
  3. Click and hold on the tile to edit it
  4. In the sceen that comes up, click the “magnifying glass” icon and click on your new task

Done!

12 Likes

Hi thanks for sharing.

I wanted to know what version of Android does this work with? because I had tried a similar setup with android 6.0.1 and it didn’t work.

Which part didn’t work?

Are you using autonotification? Because autonotification doesn’t work with android 6.0.

Can’t get it to work:

Nothing happens.
Not sure about this part:

For the if statements:

Add an if command
a. and in the first field type %result and for the comparison, do on.
Add the Setup Quick Settings action after that
a. For the name, it should be the same as the current task you have made, and are in!
add an else
a. Tick the +
b. check %result against off
c. important step toggle the Status to Inactive! This will turn the icon to a lighter shade

Can you post some more detailed info?

You have to delete the / after toggle I think

Not using Autonotification!

Good find @Bob_NL. That wasn’t in my source, but made it into the guide. Did you get yours to work?

I’ll remove the typo.

Edit: I’ve exported the Task to allow people to simply download it, import it into Tasker, and change a the word CHANGE_ME to their specific settings.

I cant get the Quick settings tile to work

Have you got the Quick Setting setup? Is it just when you click it nothing happens?

I haven’t got that set up how do I set it up? I am using a Samsung android 6.0.1

Download Tasker, and follow the guide above.

Ok so I set up everything as mentioned above however my icon does not change colour

Where is the important step that you mentioned I.e. where can I change “status” to “inactive”?

Also when I run the task it stops at the java scriplet I.e. step 4 and it doesn’t go beyond that to the if statement.

Any ideas?

It stops at the javascriptlet because it is erroring out. If you untick the “Auto Exit” button in the javascriptlet it will give you a better idea of what the error might be.

Right so my error is the following:

10.48.40/E add wait type JSI1 time 45
10.48.40/E add wait type JSI1 done
10.48.40/ActionSpecs non-proxy
10.48.40/E add wait task
10.48.40/E Error: null

right so I even used your xml task file and changed the bits to match my HA and I get the same error as above.

I suspect its something to do with your javascript request? because I am using SSL and in your javascript it contains “http” shouldn’t it be “https” ?

thanks.

@Bob_NL did you get this working ?

@fanuch did you look into it buddy?

I am using HTTPS in both the example, and in the XML. Have a look at the address variable. I can’t make sense of those errors - are you using a proxy on your phone or something?