Gade(b)llaa

A blog where I talk about the stuff I make, do and more

Wednesday, March 9, 2016

[HOWTO] Automatically adjust adaptive brightness based on time/dawn/dusk (root required, sadly)

No comments
A quick intro: I use CF.lumen to adjust my screen temperature during the evening and night and I love it. It's highly customizable and the one thing I really like is that it actually filters the colors instead of just overlaying a color. That means that black remains black (because there is no color to filter) instead of a getting an orange/reddish tint. And CF.lumen offers a ton of options to let you tweak its behaviour.

One of those options is that, besides the actual color temperature and amount of red, blue and green, it lets you configure the display brightness for when it's day, evening and night. But that's exactly where I ran into a bit of trouble because I use Android's Adaptive Display feature (the one that lets you set the display brightness but still gives the system some room to maneuver based on the amount of light the device detects in your surroundings). The problem is that apps can only set the system brightness when Adaptive Brightness is disabled. Which is stupid.

Luckily, Tasker comes to the rescue.

I'm not going into a lot of detail about what Tasker is and what it does and-so-on but lets keep it at this: Tasker lets you configure certain rules (called 'profiles') and do things (called 'tasks') based on those rules. And there are a LOT of plugins available for it, extending its not-so-limited standard feature set even more.

I found out that Android actually does provide for a "settings key" to change the brightness when the Adaptive Brightness feature is enabled[1]: "screen_auto_brightness_adj". And you can use that key by running a shell command with Tasker.

Now, you could of course just set a time and run the command based on that but - in most parts of the world - the sun doesn't come up and goes down at the same time of the day. Here's where the Tasker plugin Twilight comes to the rescue. It lets you create rules based on your location's dawn and dusk times!

So just a quick rundown (I'll update this section later but it's getting late right now so this'll have to do for now):

  1. Open Tasker and create a new profile > State
  2. Search for twilight, tap it and then the 'pen' icon
  3. Choose your from/until and confirm
  4. Create a new task, give it a useful name ("Brightness Night" or something)
  5. Add a command, search for "run shell"
  6. Paste "settings put system screen_auto_brightness_adj [value]" where [value] is between -1 and 1.
  7. Don't forget to check the 'run as root' option or it won't work.
  8. Confirm everything and in the Profile section of Tasker longpress the task you just created and choose "Add exit task"
  9. Create a new task, name it "Brightness Day" and repeat step 6 and 7 but now with the brightness value you want to use during daylight.
  10. Done! Keep pressing 'back' until Tasker exits (this is important, it seems Tasker doesn't actually save things until you do this!)
[1] Some manufacturers - among them Samsung of course - decided to change and/or remove this key. It might still exist but you probably need to google for it..