Kustom Beginner’s Guide – Part 3 – Functions, Formulas and Kodes

Kustom Formulas Banner

The next step in my Kustom Beginner's guide is to learn about Functions, Formulas and Kodes. This brings a lot of customization action to Kustom.

Kustom Beginner’s Guide – Part 3 – Functions, Formulas and Kodes

After giving an overview about KLWP basics and creating a first simple Wall it is time to talk about functions, which we kind of already used to create the clock in the Part 2 Preset ("$df(hh)$"). After going through this guide you should be able to use functions and create own magic formulas or kodes like +Carla Jocobs does.

Basic Functions

For displaying text or information in text form Kustom uses simple functions which can be seen in the formula editor. A text preview is always given and mistakes in basic stuff are flagged.

Kustom Text EditorKustom Text Hour 

Frank Monza's own Kustom website gives proper information about all the basic functions. Since he uses multiple pages for all of them I transferred his collection to a single page for easier search.

Kustom Functions

Syntax

As you can see Kustom Functions can have different syntaxes but basics are always the same.

Beneath you see 2 examples of how to use functions inside of functions.

Kustom Function inside FunctionKustom 2 Inside Functions  

Formulas

Formulas are mostly connected functions like $ai(sunset) - ai(sunrise)$ (Note the $ as the borders of a formula)

You can use all math operators like "+", "/" and so on.

The operators will work differently depending on the way you use them, so, let's give some example:

  • $2*(2+3)$ will give 6, this is simple math
  • $df(s)*2$ will return the number of seconds in current minute and multiply it per 2
  • $"foo" + "bar"$ will merge "foo" string and "bar" string resulting in "foobar" text, this is useful when you want to join text sentences and numbers
  • $ai(sunset) - ai(sunrise)$ will subtract 2 dates and return the number of seconds between them, in general a date will be converted in seconds by operators so you can then use it in the formulas 

If you need more advanced functions like "floor", "ceil" and "sqrt" please look into the mu() function. (via kustom.uservoice)

I think the mosted used formulas are if conditions where you can use comparisons like:

  • "=" (equals)
  • ">" (greater)
  • ">=" (greater or equal)
  • "<" (less)
  • "<=" (less or equal)
  • boolean operators "&" (AND) or "|" (OR) and parenthesis

Examples are in the codes part of this guide.

Formulas with the Advanced Editor

Text bits aren't the only place for formulas or functions. As you can see in the screenshots below by selecting the item and pressing on the calculator on the top right you presented with the option to use formulas in multiple places (I won't list every place, because it's pointless. just search around).

Kustom advanced editingKustom Advanced Editing 2 

Always when you see the calculator icon you are good to go.

Kustom Advanced 4Kustom Advanced 3 

Kustom even gives to rules what the formula needs to return.

Kustrom Advanced 5Kustom advanced 6 

Kodes

The really interesting stuff with Kustom functions and formulas is called Kodes in the customization community. A lot of functions are combined into one formula and create something nice.

Every single Kode here is collected or created by +Carla Jacobs and not my work! All credits go to her!

[sam id="5" codes="true"]

FormulaDescriptionRestrictions
$if(df(H)>=14&df(H)<=16, 100 ,0)$display bitmap for a certain time using opacity
$if(df(h) > 12 & df(h) < 19, #FFFFFF , #00FFFF )$display text for a certain time using opacityonly in the paint- color - formula field
$if(ai(isday)=1,ff123abc,aa321cba$change color between day and night (1 is day, 0 is night)
$ce(ffffffff,alpha,100-df(h)*2.4)$changes color gradually as day goes on (ce uses values 0:100,
cm uses 0:255)
$if((df(ss)%2)=0, FFF000, FF000000)$flashing color
$if(df(e,si(alarmd))-1=df(e)|(df(e,si(alarmd))=1&df(e)=7),#FFFF0000,#00000000)$Give color to certain alarm
file://sdcard/foo /$df(MM)$.jpgChange images based on month (for own use).
Create a folder (foo). Put your twelve jpg images in there, name them 1 to 12.
$if(df(s)<10, df(h:mm), if(df(s)<20, df(MMMM d y), if(df(s)<30,df(h:mm))))$Nested ñif then elseî
$if(df(s) < 10 & df(s) > 5, "its between 5 and 10", "its not")$Time between
$ai(isday)=1, tf(0h0m0s, S), 0$display seconds since midnight
$if(ai(isday)=1, tf(ai(sunrise), S), 0)$display seconds since sunrise
$if(bi(charging),bi(source))$display Battery while charging
$if(df(ss) = 1, 300,+10, if(df(ss)= 2, 310,+10))$make shapes movingonly in padding section
/sdcard/yourpath/$if(nc(wsig)>=0&nc(wsig)<3,badwifi,if(nc(wsig)>=3&nc(wsig)<6,okaywifi,if(nc(wsig)>=6,goodwifi)))$.pngchange image depending on signal qualityImage path

Conclusion

Now at the end of the Kustom Functions, Formulas and Kodes guide you should know how to use functions in text field or within formulas in the advanced editor. 

The next part of the Kustom Beginner's guide will be about further advanced designs.

8 Comments

  1. How about some descriptions with those kodes, so we know what the result is. Thanks and good work!

  2. Is there anyway yo create variables that will be used throughout my code? For example, i may want to create: color1 = #FF00FF00 and reference this in my formula like this:

    $if (bi (level)>=90,color1,color2) $

  3. YOUR TUTORIAL IS AMAZING, I HAD SO MUCH TROUBLE FINDING A CODE THAT’LL MAKE A BITMAP REACT TO THE CURRENT TIME. THANK YOU SO MUCH!

  4. Hi, I am new at this and can’t figure how to make Track Title along with Artist appear only when music is playing. I used $if(mi(state) = PLAYING, “$$mi(title)$ – $mi(artist)$$, mi(state) != PLAYING, “Paused”) $.

    I will be very grateful if you could help me out with this.

  5. #Saeb, create a text and change its color mode to calculator and type: $if(mi(state)=playing, #FFFFFFFF, #FF000000)$

  6. I am trying to move my Zooper widgets to kgwt. How can i make a rectangle rotate with respect to the battery status. In Zooper it looks like this:
    [ar]7[/ar]
    [as]$(360/100*#BLEVN#)$[/as]
    [r] $(360/100*#BLEVN#)$[/r]
    In kgwt i tried to use an Overlap Group with one rectangle. On “Rotation” I did select manual an tried to insert something like
    $360/100*bi(level)$
    But there is no rotation
    Thanks in advance for any help

  7. is there a way I can create a widget to monitor the battery level of the bluetooth headset connected on the device? Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *