Brightness toggle widget

This example explains how to create a simple Brightness toggle widget, which you can you use to toggle between various brightness levels for your screen. The default setup creates 6 different levels of brightness and an extra option to show the new setting in the widget label.

Updated july 2014
I originally used this on my G1 (HTC Dream) with Android 1.6 and Tasker version 1.0.8, since I wasn't too happy about how Auto Brightness was working for me. Current description was updated for Android 4.4 and Tasker 4.3.4.
Remember: Setting Brightness levels manually or with this widget might conflict with your Auto Brightness setting. On my Nexus5 I could extend the widget to turn Auto Brightness off, not sure if other devices/versions allow this as well.

Before we start, BLC asked:
I don't have a text field here [at the 4th action, red.]; all I have is a value slider. Am I doing something wrong, or do I have a newer version of Tasker than when this was written?

Answer from Pent:
Try unchecking Menu / Prefs / UI / Beginner Mode, then you'll have a new icon next to the slider.

In recent versions of Tasker, disabling Beginner Mode has become a requirement to create the widget below. Thanks to BLC for pointing this out :)

Here we go.

First, we'll create a new named task, which will contain the widget functionality:

  • Start Tasker
  • Click Tasks
  • Click [+] to add a Task
  • Fill in a descriptive name for your widget task (I named mine "Set brightness")
  • Click OK
  • Select an icon for your widget by clicking on the image select button (3x3 square) in the bottom right corner of your screen, and selecting an image source from the list shown.

After selecting the icon you should be back in the new, empty Task edit screen you created, which we're going to fill. As a first step, we are going to let our task turning off Auto Brightness, if it is founf turned on.

  • Click on the [+] button to select the 1st Action
  • Select Display
  • Select Auto Brightness
  • Set to Off (might already be set this way)

Now we'll create a custom variable, in which current the brightness setting is stored. I use %SCHERM, which is dutch for screen, to avoid mixing up the custom variables I create myself and the system variables Tasker uses. You can create your own, but avoid using %SCREEN, which is a different Tasker variable already.

The actions ahead simply increase the value of %SCHERM if it's set already, or creates the variable %SCHERM if it isn't set yet. The order is important, to avoid setting the same value every time the widget is clicked.

  • Click on the [+] button to select the 2nd Action
  • Select Variables
  • Select Variable Add
  • Fill in the name %SCHERM, set the value to 51, set wrap around to 306
  • Click the If [+] button, and add the condition %SCHERM, select [Is Set]
  • Click on the < Tasker icon in the top left corner to go back from the Action Edit screen to the previous Task edit screen

The minimum and maximum brightness values are 0 and 255. Adding 51 each step creates these different brightness levels: 0, 51, 102, 153, 204, 255. When we go one step higher to 306, it will reset to 0 again.

<optional>
If you want less/more settings, you could set different values here. For instance an add value of 85 results in the levels 0, 85, 170, 255. Adjust the wrap around value accordingly, in the case of 85 set it to 255 + 85 = 340. Try to keep round numbers.
</optional>

If %SCHERM wasn't set yet, which is the case when the widget wasn't used before since the last device boot, the value wasn't adjusted by the previous action, and we'll have to set the initial value. This value is used the first time you click your widget. I like 0 here (brightness off), but any of the other values above will do.

  • Click on the [+] button to select the 3rd Action
  • Select Variables
  • Select Variable Set
  • Fill in the name %SCHERM, set the value to 0
  • Select the If [+] button, add the condition %SCHERM, select [Isn't Set]
  • Click on the < Tasker icon in the top left corner to go back from the Action Edit screen to the previous Task edit screen

Now we'll always have a %SCHERM value available, which we'll use to set the brightness level.

  • Click on the [+] button to select the 4th Action
  • Select Display
  • Select Display Brightness
  • On the Level row on top, click on the [2 arrows] button on the right side (don't have one? See above, beginner mode must be disabled in Tasker preferences)
  • Type %SCHERM in the level field
  • Click on the < Tasker icon in the top left corner to go back from the Action Edit screen to the previous Task edit screen

The task is now fully functional for setting brightness levels. Nice and simple, huh!

<optional>
Showing the latest brightness setting in percentages in the widget label.
After creating your widget (which we'll do as the last step), how about displaying the setting you've just applied in the label of the widget? While we're at it, shall we translate the 0-255 values to percentages? Thought so. 60% makes (slightly) more sense to me than showing 153 or even 153/255.

  • Click on the [+] button to select the 5th Action
  • Select Variables
  • Select Variable Set
  • Fill in the name %SCHERM, set the value to: %SCHERM / 255 * 100
  • Select the Do Maths checkbox
  • Click on the < Tasker icon in the top left corner to go back from the Action Edit screen to the previous Task edit screen

Now %SCHERM contains a percentage value of the setting that was applied earlier. Let's update the widget label with it:

  • Click on the [+] button to select the 6th Action
  • Select Tasker
  • Select Set Widget Label

Since we haven't created the widget yet, long clicking Name won't show the widget in the list yet. Which means, typing it manually:

  • In the name field, fill in the name of the widget (in my case: Set brightness)
  • In the label field, fill in %SCHERM% (with a trailing % as well)
  • Click on the < Tasker icon in the top left corner to go back from the Action Edit screen to the previous Task edit screen

<bonus exercise>
If you like your phone speaking to you, add a Say "Brightness set to %SCHERM%" action here. Say is found in the Action category Misc.
</bonus exercise>

To be able to use the %SCHERM variable again in case the widget is clicked again, we'll translate the value from a percentage back to the brightness setting:

  • Click on the [+] button to select the next Action
  • Select Variables
  • Select Variable Set
  • Fill in the name %SCHERM, set the value to: %SCHERM / 100 * 255
  • Select the Do Maths checkbox
  • Click on the < Tasker icon in the top left corner to go back from the Action Edit screen to the previous Task edit screen

</optional>

Ta Daaa, we're done! To let Tasker know we're done and want to save our new Task, on the Task Edit screen:

  • Click on the < Tasker icon in the top left corner to go back from the Task Edit screen to the Tasker home screen (tasks tab, if tabs are enabled)
  • Click on settings (3 dots in top right corner) en select [Exit] to leave Tasker
  • If prompted for conformation of saving your changes, do so by selecting Save First

Last step is adding our new widget to a home screen:

  • Go to the home screen where you want the widget
  • Long click on an empty place, wait for the popup list and select Widget
  • Select Task (long press it to add to the home screen)

There's that familiar task screen again. With a drop down list on top. If your new task "Set brightness" isn't selected yet:

  • Select the task you've created (in my case: Set brightness)
  • Click on the < Tasker icon in the top left corner to go back from the Task Widget screen to your home screen

That's all there is to it. You have just created a brightness toggle widget in your own style and learned one dutch word along the way.

Happy tasking! ~JJ

Back to Tasker Step throughs

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License