Anyway to Convert HEX Color to HSB Color?

289 views
Skip to first unread message

Scott Almond

unread,
Jan 7, 2016, 6:55:51 AM1/7/16
to Tasker
Hi All

     As the title suggests I'm wanting to convert a HEX color (e.g. #FF112233) to HSB color (e.g. 210,67,20). I'm using Kolorette to extract the colors from currently playing music artwork and wish to pass on the HEX color to my Philips hue lights via the Tasker plugin Autohue. Problem is, Philips hue deals with HSB colors (Hue, Saturation, Brightness).

If this isn't something that can be done easily, any chance this could be added into the variable convert function in Tasker Pent?

Thanks in advance for any responses.

Regards
Scott Almond

John Doe

unread,
Jan 7, 2016, 12:57:01 PM1/7/16
to Tasker
You can use java code to do that, just one line of code:

Color.RGBToHSV(int red, int green, int blue, float[] hsv)

Refs:
http://developer.android.com/reference/android/graphics/Color.html

Scott Almond

unread,
Jan 8, 2016, 6:58:33 AM1/8/16
to Tasker
Brilliant, Thanks John. I'm not familiar with Java but will certainly get to work on learning the basics to make use of this.

Thanks again
Scott Almond.

Scott Almond

unread,
Jan 8, 2016, 10:07:13 AM1/8/16
to Tasker
Well I've been fiddling for a few hours and am struggling to get the java function to run. it gives the below log.
whilst i've tried learning the basics, Tasker doesn't display Java in the same form that you would learn and type java code so it's no easy task trying to work out how one would fill in the tasker "java function" task
Any idea where i've gone wrong or could explain how I would go about filling in the java function task in Tasker.

(I've hard coded the color purple for now, but I will be replacing those parameters with variables once I can confirm the task runs correctly.)

A1: Java Function [ Return: Class Or Object:Color Function:RGBToHSV {} (int, int, int, float[]) Param:250 Param:0 Param:250 Param:hsv Param: Param: Param: ]


Log

14.53.10/E Java Function:  ->

14.53.10/JU analyse: target: Color expected: null

14.53.10/JU target: analyse done: Color: class: android.graphics.Color  obj: null partWithoutMods: null static: true const false casted: false

14.53.10/JU analyse: returnval: java.lang.Void expected: null

14.53.10/JU returnval: analyse done: java.lang.Void: class: java.lang.Void  obj: null partWithoutMods: null static: true const false casted: false

14.53.10/JU initClass: class: java.lang.Void  obj: null partWithoutMods: java.lang.Void static: true const false casted: false

14.53.10/JU initClass: retnovar: init with array handling -> class java.lang.Void

14.53.10/JU initClass: class: android.graphics.Color  obj: null partWithoutMods: android.graphics.Color static: true const false casted: false

14.53.10/JU initClass: target: init with array handling -> class android.graphics.Color

14.53.10/JU analyse: param0: 250 expected: int

14.53.10/JU param0: analyse done: 250: class: int  obj: 250 partWithoutMods: null static: false const true casted: false

14.53.10/E param 0 class: int

14.53.10/JU analyse: param1: 0 expected: int

14.53.10/JU param1: analyse done: 0: class: int  obj: 0 partWithoutMods: null static: false const true casted: false

14.53.10/E param 1 class: int

14.53.10/JU analyse: param2: 250 expected: int

14.53.10/JU param2: analyse done: 250: class: int  obj: 250 partWithoutMods: null static: false const true casted: false

14.53.10/E param 2 class: int

14.53.10/JU analyse: param3: hsv expected: class [F

14.53.10/JU param3: analyse done: hsv: class: ???  obj: null partWithoutMods: null static: false const false casted: false

14.53.10/E param 3 class: class [F

14.53.10/E targetClass: class android.graphics.Color

14.53.10/E object: null

14.53.10/E method: public static void android.graphics.Color.RGBToHSV(int,int,int,float[])

14.53.10/E arg0 class java.lang.Integer value 250

14.53.10/E arg1 class java.lang.Integer value 0

14.53.10/E arg2 class java.lang.Integer value 250

14.53.10/E arg3 class null value null

14.53.10/E Java Function: java.lang.reflect.InvocationTargetException

14.53.10/ Caused by: java.lang.NullPointerException

14.53.10/ android.graphics.Color.RGBToHSV(Color.java:320)

14.53.10/ java.lang.reflect.Method.invokeNative(Native Method)

14.53.10/ java.lang.reflect.Method.invoke(Method.java:515)

14.53.10/ net.dinglisch.android.taskerm.ExecuteService.c(Unknown Source)

14.53.10/ net.dinglisch.android.taskerm.ExecuteService.a(Unknown Source)

14.53.10/ net.dinglisch.android.taskerm.ExecuteService.a(Unknown Source)


Any help would be much appreciated. Apologies for my stupidity when it comes to java as its something i've never touch upon before.


Regards

Scott

Message has been deleted

Scott Almond

unread,
Jan 8, 2016, 10:30:11 AM1/8/16
to Tasker
That's my mistake. I thought the 4th parameter was where I specify the name of my float array. So I need another java function first to build the float array?

On Friday, 8 January 2016 15:14:06 UTC, John Doe wrote:
The problem is the hsv parameter. What is hsv in your task? You need to create a float array.
Message has been deleted

Scott Almond

unread,
Jan 8, 2016, 10:43:00 AM1/8/16
to Tasker
I found the below link has a similar task going on which according to the poster works. I tried copying it and get the same problem. Does the task on the below link look like it should work? how have they m,anaged to set a float array in Tasker.

are you telling me, this cannot be done then?

On Friday, 8 January 2016 15:34:00 UTC, John Doe wrote:
Yep, you need to use float array but I just checked and I didn't find an easy way to create it actually because Tasker support array of objects and not array primitives, and you cannot use Float[] where it's required float[].

Scott Almond

unread,
Jan 8, 2016, 10:43:30 AM1/8/16
to Tasker

John Doe

unread,
Jan 8, 2016, 10:54:32 AM1/8/16
to Tasker
Oop sorry my fault, Tasker is a bit tricky when you use Java :) I create a simple task and it works. When you create the array you need to 3 as parameter to create an array of length 3. Then you can get each value assigning to local variables.

Link: https://drive.google.com/file/d/0B54blAHdXRJ6N3UwSzNuamstRzA/view?usp=sharing

Scott Almond

unread,
Jan 8, 2016, 11:17:43 AM1/8/16
to Tasker
Nice one, that task runs perfectly, I will be able to adapt that no problem...... and I've learnt a bit of java.

Thanks for all your help, it's much appreciated.

Regards
Scott

joer...@gmail.com

unread,
May 4, 2016, 10:04:46 AM5/4/16
to Tasker
The link is dead.. can you repost the link or post the relevant changes here??? Thank you!!

Scott Almond

unread,
May 5, 2016, 8:37:22 AM5/5/16
to Tasker

joer...@gmail.com

unread,
May 5, 2016, 11:22:20 AM5/5/16
to Tasker
Wow.. awesome thanks!!!! Does this output 1-100 or 1-255? I noticed my lights seem to only accept 1-100 via URL, but will happily take 1-255 via JSON. Just curious, haven't tested this yet.

Scott Almond

unread,
May 6, 2016, 6:04:42 AM5/6/16
to Tasker
1-255.
Reply all
Reply to author
Forward
0 new messages