Available math functions

Add a ‘crazy’ number to the calculation, check no and subtract afterwards.

I did with temperature :

VAR + 1000
If VAR greater than 1000 its a number (if its 1000 or less its not)
VAR - 1000
If VAR eq 24

Edit:
Does NOT work if VAR is a character like ‘T’..

1 Like

Awesome!! - That worked perfectly.. Now I get an error if NaN.. :slight_smile:
Thanks!

Yes, I was going to add that: check for error if NaN, but you allready found out…

1 Like

know any ways to replace text?

I thought using the standard JavaScript replace method would work, but I cannot get it to work in a flow card.

E.g. {{ “TEXT TAG“.replace("Original", "New") }} where TEXT TAG is a tag or variable containing the text “Original Text”.

However Homey gives an error (invalid or unexpected token). Maybe someone else knows how to use the replace method.

Yeah, i tried the exact same thing.

Nice puzzle @John_William_Brekke

@SunBeech Unfortunately we cannot use the ‘calculate a value’ card for a string variable. But with Better Logic we can, with the 'Set [variable] to BLL [Calculation], like this:

Working flow example:

1 Like

So with the better logic app replace will work?

Hi @Peter_Kawa, interesting. That was also my thought. I tried the BLL ‘execute BLL expression as’ card before posting and got the same error. As I normally use that card for operations on strings, I assumed the method is not supported on Homey.

As such, I don’t understand why the said BLL card does not work with the replace method, while the ‘set variable’ card does. Did your suggested flow work?

This card I used, can take string variables, that’s the trick.
Mathjs functions for strings just don’t work with cards which only take numeric variables

Of course :grimacing:, I also included the timeline notifications it produced :wink:

1 Like

Maybe I should first look at your screenshots before commenting :blush: :sweat_smile:.

Is there an easy way to determine whether a flow card works with string functions? Or is it just a matter of trail and error?

1 Like

:zany_face:

Yea, I 'trial and errored" until I discovered this particular BLL card, which can be used for string/text calculations on any variable type.

Afaik all other cards take only numeric variables to calculate on, and using .replace on strings/text just gets rejected for non-numeric data.

Does this make sense?

But, wait! Yesterday I couldn’t get it to work, but now I tried this in an ordinary notification card and it works !
This should work with Homey variables as well

{{ "[bll_stringvar]".replace("[name]","[other_name]") }}

Strange!

I got confused because the ‘execute as tag’ BLL card I normally use for string calculations, like the following example (which extracts the first name from the full Homey user name):

did not work with the replace method. The following example with the replace method does not work:

Anyway, trial and error it is :grinning:!

1 Like

Thanks, i tried what i wanted it to do and it worked!

1 Like

It does or doesn’t?
Because it should work :sweat_smile:

It works if I create the flow on my computer via the web app. If I create exactly the same flow via the web app on my iPad, it does not work.

Looking closer, I now see that on iPad the default double quotes are different (angled) compared to those on my laptop (straight).

Note to self: select the correct double quotes :blush:.

2 Likes

Yeah hold down the ”“ button to get “” i always hold it to get the straight ones because for some reason my default is «»

1 Like

I still hope there comes an option for flowcard defenitionw (within the app for devs) to mark a flowcard-argument field as coding. So if you include a string token, it wraps it in double qoutes. Or a yes/no token as true and false, instead of yes/no (hp2019) or emoticons (hp2023).

Yes that would make sense and easier for the end user.

I am a HP2023 user and also having trouble understanding how to use booleans in math.js functions, since Homey seems to convert them to symbols (as you indicate), while my mind thinks in true/false options :sweat_smile:.