Available math functions

Awesome, it works, thanks a lot @Peter_Kawa ! :pray:

1 Like

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?

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

1 Like

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

please give example how you use this in a flow

thnx

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?

Best regards,

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!

.

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.

1 Like

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

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

1 Like

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

Hi Hans,
(Mind the topic language :wink: )

Edit: found it @HanZ !

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:

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?

1 Like

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

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 :sweat_smile: :crazy_face: :sweat_smile:

1 Like

Oh wow, thank you @Peter_Kawa

@HanZ maybe uoy can do something like

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

So that would become something like:

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

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

{{ max(value, 0) }} 

I havent tried it by the way.

1 Like

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

1 Like

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)