Brightness widget

This example explains how to create a simple Brightness 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 the option to show the new setting in the widget label.

I use 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.
If you are, remember setting Brightness levels manually or with this widget might conflict with your Auto Brightness setting.

Here we go.

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

  • Start Tasker
  • Click Tasks
  • Click New
  • 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 icon button (question mark) in the bottom right corner of your screen.

After selecting the icon you should be back in the new, empty Task screen you created, which we're going to fill. 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 1st Action
  • Select Variable
  • Select Variable Add
  • Fill in the name %SCHERM, set the value to 51, set wrap around to 306
  • Select the If checkbox, add the condition %SCHERM, select Is Set
  • Click Done

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 2nd Action
  • Select Variable
  • Select Variable Set
  • Fill in the name %SCHERM, set the value to 0
  • Select the If checkbox, add the condition %SCHERM, select Isn't Set
  • Click Done

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 3rd Action
  • Select Display
  • Select Display Brightness
  • Type %SCHERM in the level field
  • Click Done

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 4th Action
  • Select Variable
  • Select Variable Set
  • Fill in the name %SCHERM, set the value to: %SCHERM / 255 * 100
  • Select the Do Maths checkbox
  • Click Done

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 5th 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 Done

<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 6th Action
  • Select Variable
  • Select Variable Set
  • Fill in the name %SCHERM, set the value to: %SCHERM / 100 * 255
  • Select the Do Maths checkbox
  • Click Done

</optional>

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

  • Click Done
  • Click Apply.

We have left Tasker by now and will add the 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

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 Make Widget

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