I would like to have my battery icon and battery % turn red when the battery % gets to 30% or below. I think it’s in Opacity somewhere, but I am not sure how to write the formula.
In color use
{bl} <= 30 and ‘ff0000’ or ‘ffffff’
Change the hex codes for what you need.
This example turns the image red at 30% and it’s the original color at 31% and up
Lovley little Snipet . Thank youj . I assume we can not do Maths with the RGB HEX . Make Psychadelic colours morphing at speed .
![]()
We can play with the hex, question is, whether it is compatible with the WFF.
AI researched for me this LUA script for the fluent color change from green at 100% trough yellow at 50% to red at 0%.
{bl} > 50 and string.format("%.2xff00", (100-{bl})*5.1) or string.format("ff%.2x00", {bl}*5.1)
In studio preview it works well, but I cant test it on watch. AI makes bold claim.
"I want to be sure this will work on updated watches too, but I do not have such one
Yes, this Lua formula will continue to work perfectly on updated watches because the WatchMaker development team has specifically updated their platform engine to translate these types of custom expressions into Google’s modern, compliant system. [1]
While Google mandates the newer Watch Face Format (WFF) for modern operating systems like Wear OS 5 and Wear OS 6, you do not need to rewrite your code. [1, 2, 3, 4, 5]
How WatchMaker Handles it on Updated Watches
- Automatic Translation: When you push your watch face from your browser to a newer watch (like a Samsung Galaxy Watch 7/8 or Pixel Watch 3/4), the mobile companion app automatically translates your custom layers into the new XML-compliant format. [1, 2]
- Optimized Rendering: Your color shifting formula is converted under the hood into native arithmetic tokens so the watch can render the gradient natively. This ensures you get the smooth color transition you designed without draining the battery or getting blocked by the operating system. [1, 2]
- Testing Your Design: Since you do not own an updated smartwatch to check the results physically, you can rely fully on the WatchMaker Studio browser preview. The live preview engine accurately mirrors how the math compiles, ensuring that if the colors transition smoothly from green to red on your monitor screen, they will do the exact same on a modern watch."
Peter - I am really quite impressed. I will give your formula a try. Thanks.
If it does not break down somewhere in the process, maybe to better see if it really works try this on some other colored element (I expect it to stumble on the 6 nested conditions but in preview its fun):
({drss}%60) < 10 and string.format("ff%.2x00", ({drss}%60)*25.5) or ({drss}%60) < 20 and string.format("%.2xff00", (20-({drss}%60))*25.5) or ({drss}%60) < 30 and string.format("00ff%.2x", (({drss}%60)-20)*25.5) or ({drss}%60) < 40 and string.format("00%.2xff", (40-({drss}%60))*25.5) or ({drss}%60) < 50 and string.format("%.2x00ff", (({drss}%60)-40)*25.5) or string.format("ff00%.2x", (60-({drss}%60))*25.5)
Oh well - your formula looks great on the monitor - changes exactly as it should. On my Pixel Watch 4 I get nothing - it’s just blank. Eeeek!!
that is what I was afraid of
Yikes . Peter . Thanks so much . I look forward to giving that a run on GW7 tomorrow .
Peter and Russell and anyone else who likes conditional color changes. Give this a try. It seems to work nicely on the Pixel 4 Watch.
({bl}>=0 and {bl}<=30) and ‘ff0000’ or ({bl}>30 and {bl}<=50 and ‘DEFF00’) or ‘00ff00’
Now, of course, we have all seen where Lua works great on the monitor and drops dead on a WearOS watch. I’ll let ya’ll know what happens when my watch gets to less than 50% battery charge.
You know LUA translation in background failing is drag but I actually expected it to happen.
It is not the end of world, I still have my old trusty 3 layer setup I used to work with on Facer. Not as elegant but seems to work on this platform too. Would you try it on watch? I shared it as component for inserting in studio
Hi, Peter - your Facer description sounds like what I’ve done on Watch Face Studio. I’ll try your component tomorrow, but I really want to see what this one I “invented” does on the watch. It’s not the morphing style, but if it works, it will be nice.
Sadly I can not get that Formula to work on the Studio . I will check it on my watch . No change on my watch . Just shows white .
I tried that Psychadelic formula , with my thanks Peter . I replaced " with ’ but still could not get it to work .
Hi, Peter and Russell,
Well, it took some serious fiddling around, but I now have 4 conditional colors (red, orange, yellow-green, and green) - works on both Studio and Pixel 4 Watch. Yeah, I had several attempts that just showed white - I discovered I was doing lots of unnecessary stuff with parentheses (brain still speaks WFS). Try this version:
{bl}>=0 and {bl}<=30 and ‘ff0000’ or {bl}>30 and {bl}<=45 and ‘B8AB1E’ or {bl}>45 and {bl}<=70 and ‘DEFF00’ or ‘00ff00’
Now, this just changes color as the battery percent changes - not psychedelic - although that is really cool.
I have no Idea why that does not work for me . This one works .
{bl} > 50 and string.format(‘%.2xff00’, (100-{bl})*5.1) or string.format(‘ff%.2x00’, {bl}*5.1)
You have unnecessary compares in your statement. You dont have to check for a value between, just a value less than. This statement is is what I use (different color scheme, of course):
({bl} == 100) and “000080” or ({bl} > 95) and “0000ff” or ({bl} > 90) and “0080ff” or ({bl} > 85) and “00b0ff” or ({bl} > 80) and “00ffff” or ({bl} > 70) and “00ff80” or ({bl} > 60) and “00ff00” or ({bl} > 50) and “c0ff00” or ({bl} > 40) and “ffff00” or ({bl} > 35) and “ffc000” or ({bl} > 25) and “ff8000” or ({bl} > 10) and “ff0000” or “800000”
I think elsewhere was stated that too many compares can confuse WFF. But the above works for my Samsung Classic 8 watch.
Also note there is a bug in Watchmaker in that the equivalent {pbl} is not working in the color field property of a layer (reported elsewhere on this forum).
Hi, David - I tried your formula (no worries re the color choices; I know how to change those). Sorry, no luck - everything just stays white. Sorry - the Pixel Watch is a unique animal.
Where are you placing that formula (i.e. what type of layer and what field in that layer)? I could then try the same thing on my Samsung watch. As I mentioned, I have problems with {pbl} in the “Color Selection” property of a shape object due to a bug in WM. Another thing to try: reduce the formula to just two values, and see if you can get that to work:
{bl} > 0 and “0000ff” or “ff0000”
the result should be dark blue, not red. If that works, then you can expand from there. Does the formula work in Studio (85% should resolve as light blue in the original formula)?
I published a test watch for my earlier report to WM that you could also try. “aavh Basic”. I think it was made a premium type watch by default by WM, however.
David - I’ve been putting it in the 1st level and the Color field for battery ({bl}. I know the two-value variation will work. I’ve been doing it with red and green.
I have Premium, so I’ll look for your watch. The one I’m working with is MAT002. Yes, I know - too many comparisons, but it does work, so I’ll not fix what isn’t broken. I made it a component too.