# Available math functions

**URL:** <https://community.homey.app/t/available-math-functions/16622>\
**Category:** Questions & Help\
**Created:** [August 9, 2019, 9:48am UTC](https://community.homey.app/t/available-math-functions/16622 "2019-08-09T09:48:17Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Diposan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/diposan/32/46698_2.png) [@Diposan](https://community.homey.app/u/Diposan)\
**Post date:** [August 27, 2022, 9:24am UTC](https://community.homey.app/t/available-math-functions/16622/21 "2022-08-27T09:24:06Z")

</div>

Awesome, it works, thanks a lot @Peter_Kawa ! 🙏

---

<div class="post-metadata">

**Author:** ![Juppehup](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/juppehup/32/16748_2.png) [@Juppehup](https://community.homey.app/u/Juppehup)\
**Post date:** [January 26, 2023, 6:10am UTC](https://community.homey.app/t/available-math-functions/16622/22 "2023-01-26T06:10:47Z")

</div>

I am trying to get a logarithmic formula to work but it is giving me “Error executing expression: Undefined symbol math”.  
I am using “math.log(10000)” as a test for now, pretty simple, but not working.  
What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 26, 2023, 6:41am UTC](https://community.homey.app/t/available-math-functions/16622/23 "2023-01-26T06:41:21Z")

</div>

> [@Juppehup](#):
>
> What am I doing wrong?

Since every function mentioned in this thread doesn’t use the `math.` prefix, I would suggest trying `log(10000)`

---

<div class="post-metadata">

**Author:** ![Juppehup](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/juppehup/32/16748_2.png) [@Juppehup](https://community.homey.app/u/Juppehup)\
**Post date:** [January 26, 2023, 7:01am UTC](https://community.homey.app/t/available-math-functions/16622/24 "2023-01-26T07:01:14Z")

</div>

Aaah…it can be so simple sometimes…stupid me…😌  
Thanks!

---

<div class="post-metadata">

**Author:** ![HanZ](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hanz/32/18371_2.png) [@HanZ](https://community.homey.app/u/HanZ)\
**Post date:** [March 20, 2023, 10:07am UTC](https://community.homey.app/t/available-math-functions/16622/25 "2023-03-20T10:07:44Z")

</div>

please give example how you use this in a flow

thnx

---

<div class="post-metadata">

**Author:** ![Tjar](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tjar/32/61177_2.png) [@Tjar](https://community.homey.app/u/Tjar)\
**Post date:** [July 3, 2023, 9:26am UTC](https://community.homey.app/t/available-math-functions/16622/26 "2023-07-03T09:26:20Z")

</div>

Hi Dear readers,

I’m also struggling with my first math in advanced flow.  
I have a flow trigger “on temperature change” and need to transform that value to linear fan control:  
(temperature - setpoint) \* 5 = level  
And send that out though MQTT message.

The trigger and send out through MQTT works but how can I do the math?  
The logic block does not accept any input like {{ (temp- 20) \* 5 }}

Also: do I need the 'temp" as flow variable or is it possible to inherit the temperature value ‘#temperature’ from the previous block for the calculation?

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/4/649476cf62d7a06fd4421e0e7edc8e3a5c21149b.png)

Best regards,

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [July 3, 2023, 1:39pm UTC](https://community.homey.app/t/available-math-functions/16622/27 "2023-07-03T13:39:15Z")

</div>

Hi Tjar,

In several cards you can enter the math without needing an ‘in-between’ logic calc card.

It seems to work with the MQTT Client card!

 ![Screenshot from 2023-07-03 15-37-28](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/6/a657a96228c5e1e4e224a4bf812c631b67de6610.png)

.

> [@Tjar](#):
>
> do I need the 'temp" as flow variable or is it possible to inherit the temperature value ‘#temperature’ from the previous block for the calculation?

It’s the latter (if it’s available from the card though).

**First connect the two cards (!)**

and then you can select the ‘inherited’ tag which is on top on the dropdown, under “_This flow_”  
When you hover the tag, you can also notice the trigger card’s tag icon gets blue colored, and the card gets a blue shadow.  
This comes in handy when you have several trigger cards to choose the tag from f.i.

 ![Screenshot from 2023-07-03 15-40-46](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/1/c14f3573b841c8b3654f66137987f02b525abdfc.png)

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [July 3, 2023, 10:46pm UTC](https://community.homey.app/t/available-math-functions/16622/28 "2023-07-03T22:46:52Z")

</div>

> [@Peter\_Kawa](#):
>
> In several cards you can enter the math without needing an ‘in-between’ logic calc card.

I believe you can use the curly brackets in any textargument.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [July 3, 2023, 11:04pm UTC](https://community.homey.app/t/available-math-functions/16622/29 "2023-07-03T23:04:08Z")

</div>

Yeah, but while I didn’t test all of them, ‘several’ would be a safer statement for me to write here 😅  
And Homey always seems to have (unexpected) exceptions somewhere 🤪

---

<div class="post-metadata">

**Author:** ![HanZ](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hanz/32/18371_2.png) [@HanZ](https://community.homey.app/u/HanZ)\
**Post date:** [July 4, 2023, 10:44am UTC](https://community.homey.app/t/available-math-functions/16622/30 "2023-07-04T10:44:50Z")

</div>

Hi,

ik probeer formule te vinden die een getal (#vermogen bv.) vergelijkt of het positief of negatief is, bij positief het getal weergeven indien negatief 0 weergeven.

Dit om een variabele te maken die alleen een waarde geeft als de zonnepanelen leveren en 0 weergeeft als het verbruik hoger is als de opbrengst van de zonnepanelen.  
kan op de site van math.js. org niet mijn gewenste formule deduderen.

hoor graag

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [July 4, 2023, 3:07pm UTC](https://community.homey.app/t/available-math-functions/16622/31 "2023-07-04T15:07:11Z")

</div>

Hi Hans,  
(Mind the topic language 😉 )

Edit: found it @HanZ !

 ![Screenshot from 2023-07-04 17-39-27](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/7/579056f559502c5cc2061f99dbaf45553450e816.png)

Whoopss… I got the question wrong at first, but I want to show this function anyways:  
This is a math way to change negative numbers to positive numbers:

 ![Screenshot from 2023-07-04 17-04-24](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/e/ae2e70d9eeb4b711a0d91dae91e704e26934b962.png)

---

<div class="post-metadata">

**Author:** ![HanZ](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hanz/32/18371_2.png) [@HanZ](https://community.homey.app/u/HanZ)\
**Post date:** [July 4, 2023, 3:38pm UTC](https://community.homey.app/t/available-math-functions/16622/32 "2023-07-04T15:38:47Z")

</div>

Sorry my mistake, thanks Peter,

changing a negative outcome to a positive outcome = multiply by -1 (IMHO)  
I need to create a variable with a positive outcome or, if the outcome is negative; zero (0)  
any suggestions on this?

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [July 4, 2023, 3:43pm UTC](https://community.homey.app/t/available-math-functions/16622/33 "2023-07-04T15:43:20Z")

</div>

{{max(0, [YourVar])}} returns a zero when [YourVar] is a negative number, see screenshot in my edited reply above.

> [@HanZ](#):
>
> changing a negative outcome to a positive outcome = multiply by -1 (IMHO)

You’re right. I tried this  
{{[MyNumVar] \* -1}}  
but that didn’t work.  
This works:  
{{round([MyNumVar] \* -1)}}  
But when the value is positive, it also gets changed… to negative in this case…

Advantage of using ‘abs’: With math ‘abs’ there is less characters to enter 😅 🤪 😅

---

<div class="post-metadata">

**Author:** ![Tjar](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tjar/32/61177_2.png) [@Tjar](https://community.homey.app/u/Tjar)\
**Post date:** [July 7, 2023, 7:01am UTC](https://community.homey.app/t/available-math-functions/16622/34 "2023-07-07T07:01:30Z")

</div>

Oh wow, thank you @Peter_Kawa

@HanZ maybe uoy can do something like

```auto
{{ (value >= reference) true_value : false_value }} 

```

So that would become something like:

```auto
{{ (value >= 0) value : 0 }} 

```

But you could also just return the highest value of two arguments using max()

```auto
{{ max(value, 0) }} 

```

I havent tried it by the way.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [July 7, 2023, 8:34pm UTC](https://community.homey.app/t/available-math-functions/16622/35 "2023-07-07T20:34:32Z")

</div>

In BetterLogicLibrary you can use way more advanced calculations. Just FYI.

---

<div class="post-metadata">

**Author:** ![HanZ](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hanz/32/18371_2.png) [@HanZ](https://community.homey.app/u/HanZ)\
**Post date:** [July 21, 2023, 1:22pm UTC](https://community.homey.app/t/available-math-functions/16622/36 "2023-07-21T13:22:00Z")

</div>

Just over the moon I understand (a bit of) the variable things Arie.  
A topic with a lot of examples and explanations could help (I hoop)

---

<div class="post-metadata">

**Author:** ![Patrick\_Spadrille](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_spadrille/32/120160_2.png) [@Patrick\_Spadrille](https://community.homey.app/u/Patrick_Spadrille)\
**Post date:** [March 11, 2025, 7:19am UTC](https://community.homey.app/t/available-math-functions/16622/37 "2025-03-11T07:19:35Z")

</div>

I try to do some math inside the card to set a variable to a number. In the number field, i entered {{10+20}} but when i press ENTER, it just delete what i have put in the field. What am i doing wrong?

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [March 11, 2025, 7:23pm UTC](https://community.homey.app/t/available-math-functions/16622/38 "2025-03-11T19:23:00Z")

</div>

Use the “Calculate…” card, not the “Set…” card.

---

<div class="post-metadata">

**Author:** ![DeBossDK](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/debossdk/32/105832_2.png) [@DeBossDK](https://community.homey.app/u/DeBossDK)\
**Post date:** [April 24, 2025, 8:25am UTC](https://community.homey.app/t/available-math-functions/16622/39 "2025-04-24T08:25:48Z")

</div>

Hi all..  
A problem I thought would be simple - But nooooo.

I’m doing logic drills to inteligently calculate a variable, that I’d use for adjusting a pool-heatpump for tomorrow energy prices.

The issue is, that “tomorrow vaulues” are not available until around noon today - so the logic can’t calculate from 00.00-\>13.00, and the result becomes NaN (or simply empty/NULL when I look at the variable) until prices are available.

This does not give an error, but it destroys the following calculations.

I can’t fint a math function to wrap the calculations, to ensure a number is present.  
Somethin like a IsNumber() check or similar..

Any ideas?

Thanks in advance 🙂  
Dennis

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [April 24, 2025, 2:00pm UTC](https://community.homey.app/t/available-math-functions/16622/40 "2025-04-24T14:00:12Z")

</div>

Many Math.js functions will work.

[Previous page](https://community.homey.app/t/available-math-functions/16622.md?page=1)

[Next page](https://community.homey.app/t/available-math-functions/16622.md?page=3)
