[HR] complication to change colors

Hello everyone. I’ve just started making my own watch faces and have a lot just going through the topics. I’ve made a few complications but now I’m stuck. I’m trying to create a heart rate bar that will change from it’s normal color to red once your heart rate goes above 100. Is anyone able to assist? Thank you all.

1 Like

Complications, or tags?
(There’s a difference, but that will not matter, here.)

What you’ll want to do, is use the [HR] tag, in the opacity field of your bar and make a formula that manipulates the opacity field, depending of the value of the HR.

  1. Make a normal bar at default 100 opacity that disappears when the [HR] value is 100 or more.

(([HR]>99)*-100)

Make a red bar on top of it at 0% opacity, that appears when the [HR] value is 100 or more.

(([HR]>99)*100)

Tag formulae are a powerful thing that can allow you to do neat tricks like this:

20230807_191107

20230807_191137

20230807_191254

2 Likes

Just in case @kswatch07 's formula looks confusing, it really works pretty simply:

(([HR]>99)*-100) may also be written [HR]>99?-100:0. They are both saying "If [HR] is > 99, subtract 100 from the default opacity (remember, the default is 100). Therefore, if heart rate is less than or equal to 99, the opacity is 100, or “on”. If heart rate is greater than 99, the opacity is 0, or “off”.

the trick with kswatch07’s formula is it multiplies a boolean value (0 or 1) with -100. [HR]>99 true becomes (1 * -100), or -100. [HR]>99 false becomes (0 * -100), or 0. It’s a cool technique that saves a few keystrokes.

The second bar does the opposite.

In my experience, if the red bar is an exact overlay of the normal bar, toggling and switching the two is redundant. The normal bar can be static, just toggle the red bar to be active when required and inactive when not. The normal bar won’t show through, unless the red bar’s opacity is less than 100 when active.
However, if you want the result to look like the example kswatch07 provided, then you will need to toggle elements on and off based on what you want the end result to be.

There’s a good codelab for using Tag Expressions that covers exactly what you’re doing, I recommend checking it out.

3 Likes

Thanks all. I really appreciate the feedback and I’m working on learning more through the codelab. Thank you for the link. That helped a great deal!! I think I got it now.

1 Like