[APP][Pro] Better Logic Library - For Users

So we should generally write a - b instead of a-b and similar in all formulas to avoid issues?

Homey has quite a steep learning curve. The scarce documentation doesn’t help either, and on top of that you usually need apps written by the community that follow different, inconsistent design concepts.

In short: you are not the problem.

But Homey still has a good concept. It gives you a reasonably stable basis to build on. I have tried various smart home systems and Homey is IMO the best, even if it has some weaknesses.

Indeed!
(Altho i never realized it before, lol)

In a Math.js-expressie card I found this.
Expressie waarde (Tekst) > 00 and Expressie waarde (Tekst) < 06 is waar.
For a part of my need a can work with it.

Now I was thinking of the possibility to use “or” in the same way like
Expressie waarde (Tekst) = 04 or
Expressie waarde (Tekst) = 10 or
Expressie waarde (Tekst) = 16 or
Expressie waarde (Tekst) = 22 is waar

But no.
SyntaxError: Invalid left hand side of assignment operator = (char 5)

The value of the tag Expressie waarde (Tekst) is 22.

Do I have to do it in a other way or is it not working at all.

In JS, you need 2 or 3 equal signs: ==.
And in stead of the or, use ||

:+1:
Thanks but only changing the = in to == signs was needed.

1 Like

I just remembered the app Temporary variables which also can do some limited calculations. I checked now and it has no problems with negative numbers, i.e. the following example calculates just fine:

image

Ignore the zeros, I added them so that the “1-” is displayed in front of the variable and it’s clear that there are no spaces. Maybe @spkesDE has some ideas how to solve that?

I don’t know the issue. Maybe a tl;dr would be nice.

But FYI: all my code is open source.

2 Likes

See this simple flow:

I set a variable to a negative number and then calculate 1 minus that variable.

  • Logic flow card works fine and sets a second variable to 6
  • Temporary variables works fine and calculates 6
  • BLL fails with an error
  • But if one adds a space between the minus sign and the variable, BLL works just fine

@DirkH summarised it pretty well:

So the question is pretty much if you @spkesDE have any idea what can be done to improve the handling of variables within BLL as your app doesn’t have that problem.

Wasn’t there recently a finding that there should be better always a blank before and after the minus? Am not sure whether you did that. Difficult to see.

Arie would have to check this in his code with debugging. I bet there is a check in place that I don’t have.

Is it possible to make a BLL-expression like an Excel cell formula like:
IF calculated-value > 2 THEN calculated-value ELSE 0

It is called ternary operator.
variable = (condition) ? expression1 : expression2
In the BLL field you delete the “variable =“ part and you can use something like
(5 > 1) ? 61: 90;

2 Likes

Thanks for this solution. :+1:

8 x 2 cards could be left out of a flow.
The card itself replaced another BLL card.

They were needed to reduce hours above 23 by 24.

(HH > 23) ? HH-24: HH;

1 Like

If you have to do date and time calculations, you might use EPOCH format, the time in milliseconds since 1-1-1970. Then the functions Date.now() and Date(<EPOCHnumber>) come in handy in any field that supports expressions or BLL expressions for BLL variables and fields in AVD’s.
The first one returns the epoch number of the current date & time, whilst the second reverse the operations. Pitty that one cannot use text formatting in the reverse operation, at least I did not find it yet.

What do you mean with this?
You mean convert milliseconds into a Date and then format it a certain way? If so, you can do that:

date('shorttime', now + (90*60000) )

FYI: Same as :
date('shorttime', Date.now() + (90*60000) )

FYI: in BLL expressions, Date.now() is available as now. Just to make it more readable and have for each execution a fix value of now.

I was trying some like Date(1718960326112, “dd-mm-yy HH:mm:ss”).
I will try your suggestions. Thanks

PS: I think there is a difference when you write “date” or “Date”, probably because they are different function from different libraries/packages. In this case BLL library and JavaScript.

Yes, the Date is the default Javascript object, while the date is the BLL Custom date-formating function.
See the BLL settingscreen for more info about the date (and other) method(s).

To be clear, to convert a millisecond to a Javascript Date object, you use the
Date(1718960326112)

However, formating it into a certain text-format, you use the BLL date method:
date('dd-MM-yy HH:mm:ss')
Using the date with only the format definition, will make the function use Date.now() as input.

However, the optional second parameter/argument to the date method can be any of the input:

  • A valid Date object, like Date(1718960326112) or Date.now()
    date('dd-MM-yy HH:mm:ss', Date(1718960326112))
  • A number, as in milliseconds
    date('dd-MM-yy HH:mm:ss', 1718960326112)
  • A text containing a ISO date, like 2022-11-10T19:17:01.439Z
    date('dd-MM-yy HH:mm:ss', '2022-11-10T19:17:01.439Z')
  • A text containing a default date makeup (Thus only English format right now)
3 Likes

Thanks, I was really mixing up those two functions.

Would it be possible to format text in different colors? And show it in the status field of an AVD?