Repository navigation
Math Expressions
Home · Getting started · Flow actions · BLL coding
Chronograph can calculate a duration when a Flow runs. Instead of entering only a number, enter an expression in a supported duration field. Chronograph uses a restricted subset of MathJS syntax; not every MathJS function or feature is available.
Use the duration field of these current action cards:
| Action | Supported types |
|---|---|
| Start or replace | Timer and transition |
| Start or resume | Timer and transition |
| Adjust | Stopwatch, timer and transition |
Stopwatch start has no duration field. Other fields, including transition start/end values and step count, are not MathJS expression fields.
The expression evaluates to a number in the unit selected on the card.
For example, 2 * 5 with minutes selected gives 10 minutes. A start-or-resume
card evaluates its parameters even when an existing instance is resumed; it
does not replace that instance's duration with the expression result.
| Expression | Result | Meaning |
|---|---|---|
2 + 3 |
5 | Addition |
10 - 4 |
6 | Subtraction |
3 * 4 |
12 | Multiplication |
15 / 3 |
5 | Division |
15 % 10 |
5 | Remainder |
2 ^ 3 |
8 | Power |
(2 + 3) * 4 |
20 | Parentheses group operations |
Spaces and uppercase or lowercase function names are allowed. Use a period
for decimal numbers in expressions, for example 1.5 * 2. A standalone
decimal number such as 1,5 is also accepted, but a comma
inside an expression separates function arguments; do not write 1,5 * 2
to mean one and a half times two.
| Function | Example | Result |
|---|---|---|
abs(x) |
abs(-10) |
10, the absolute value. |
ceil(x) |
ceil(1.2) |
2, rounded up. |
floor(x) |
floor(1.9) |
1, rounded down. |
round(x) |
round(2.5) |
3, rounded to the nearest integer. |
min(...) |
min(5, 10, 15) |
5, the smallest value. |
max(...) |
max(5, 10, 15) |
15, the largest value. |
random(min, max) |
random(10, 30) |
A random number greater than or equal to 10 and less than 30; it can be fractional. |
pick(...) |
pick(1, 3, 5, 9) |
One randomly selected value from the list. |
Chronograph's simplified pick syntax accepts a list of non-negative whole
numbers. For example, pick(1, 3, 5) works; decimal values, negative
values and nested expressions inside pick are not supported. Other
functions such as sqrt are not part of the supported subset.
- Add Start or replace timer, name it
Random light, and choose minutes. - Enter
random(10, 30)as the duration. - Use a separate Timer is finished Flow to turn off the light.
The timer starts for at least 10 minutes but less than 30 minutes. For whole
minutes, use floor(random(10, 31)) to choose an integer from 10 through 30.
Enter pick(5, 10, 15) and select minutes. The timer will use one of
those three durations each time the start action runs.
Insert a numeric Homey Flow token into the duration field, then add arithmetic
around it. For example, insert a token that supplies a duration in minutes
and multiply it by 2. If the token evaluates to 5, the expression
produces 10 and, with minutes selected, starts a 10-minute timer.
Make sure the token resolves to a number and that your calculation produces
a valid duration.
Use Adjust timer with -2 * 2 and choose minutes to subtract
4 minutes from elapsed time. This increases the remaining countdown by up to
4 minutes, limited by the elapsed time already accumulated. Positive
adjustments move elapsed time forward instead. See
Flow actions.
- Check parentheses, function names and commas. Use
.for decimal values inside expressions and select the intended unit separately. - Check that tokens resolve to numeric values and that the result is valid for the action. Timer starts require a positive duration; transition starts accept a non-negative duration. Avoid division by zero.
- Unsupported or malformed expressions may not produce a useful duration. In particular, do not rely on every invalid adjustment being rejected: test the calculation and its effect before using it in an important Flow.
- The widget start form requires a numeric duration; it is not the Flow-card expression field.
Support development - If Chronograph is useful to you, you can support its
continued development through GitHub Sponsors,
Patreon,
PayPal, or
bunq.
Thank you!