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

**URL:** <https://community.homey.app/t/app-pro-better-logic-library-for-users/71876>\
**Category:** Apps\
**Tags:** app, tools, homey-pro, logic, bll\
**Created:** [November 7, 2022, 10:13pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876 "2022-11-07T22:13:40Z")\
**Posts on this page:** 20\
**Page:** 9

<div class="post-metadata">

**Author:** ![CaptainVoni](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/captainvoni/32/3549_2.png) [@CaptainVoni](https://community.homey.app/u/CaptainVoni)\
**Post date:** [May 8, 2024, 3:51pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/171 "2024-05-08T15:51:22Z")

</div>

> [@DirkH](#):
>
> probably I am too old

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.

---

<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:** [May 8, 2024, 4:51pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/172 "2024-05-08T16:51:37Z")

</div>

> [@DirkH](#):
>
> So we should generally write _ **a - b** _ instead of _ **a-b** _ and similar in all formulas to avoid issues?

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

---

<div class="post-metadata">

**Author:** ![Theo\_de\_Koning](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/theo_de_koning/32/136062_2.png) [@Theo\_de\_Koning](https://community.homey.app/u/Theo_de_Koning)\
**Post date:** [May 12, 2024, 8:59pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/173 "2024-05-12T20:59:38Z")

</div>

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.

---

<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:** [May 13, 2024, 6:23am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/174 "2024-05-13T06:23:11Z")

</div>

> [@Theo\_de\_Koning](#):
>
> 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 `||`

---

<div class="post-metadata">

**Author:** ![Theo\_de\_Koning](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/theo_de_koning/32/136062_2.png) [@Theo\_de\_Koning](https://community.homey.app/u/Theo_de_Koning)\
**Post date:** [May 13, 2024, 6:58am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/175 "2024-05-13T06:58:17Z")

</div>

👍  
Thanks but _only_ changing the = in to == signs was needed.

---

<div class="post-metadata">

**Author:** ![CaptainVoni](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/captainvoni/32/3549_2.png) [@CaptainVoni](https://community.homey.app/u/CaptainVoni)\
**Post date:** [May 19, 2024, 7:44am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/176 "2024-05-19T07:44:08Z")

</div>

> [@Arie\_J\_Godschalk](#):
>
> Unfortunately, this is not possible, because a tag/token is parsed by Homey as plain text. BLL cannot know that its a token, tag or variable.

I just remembered the app [Temporary variables](https://homey.app/en-at/app/com.spkes.temporaryVariables/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](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/8/78df43ca70c4e609b9797b8e1a8733709f04f172.png)

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?

---

<div class="post-metadata">

**Author:** ![spkesDE](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/spkesde/32/54352_2.png) [@spkesDE](https://community.homey.app/u/spkesDE)\
**Post date:** [May 19, 2024, 3:43pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/177 "2024-05-19T15:43:01Z")

</div>

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

But FYI: all my code is open source.

> <https://github.com/spkesDE/com.spkes.temporaryVariables/blob/master/Evaluator.ts>

---

<div class="post-metadata">

**Author:** ![CaptainVoni](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/captainvoni/32/3549_2.png) [@CaptainVoni](https://community.homey.app/u/CaptainVoni)\
**Post date:** [May 20, 2024, 6:41am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/178 "2024-05-20T06:41:46Z")

</div>

See this simple flow:

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

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:

> [@DirkH](#):
>
> That is especially dangerous, if a formula works fine for months. until the first negative value occurs, and either stops or has unexpected side effects, when after a-b suddenly a is lowered by the value of b.

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.

---

<div class="post-metadata">

**Author:** ![SingKT](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/singkt/32/173226_2.png) [@SingKT](https://community.homey.app/u/SingKT)\
**Post date:** [May 20, 2024, 9:32am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/179 "2024-05-20T09:32:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spkesDE](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/spkesde/32/54352_2.png) [@spkesDE](https://community.homey.app/u/spkesDE)\
**Post date:** [May 21, 2024, 8:17am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/180 "2024-05-21T08:17:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [June 19, 2024, 11:49am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/181 "2024-06-19T11:49:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [June 19, 2024, 10:55pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/182 "2024-06-19T22:55:06Z")

</div>

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;`

---

<div class="post-metadata">

**Author:** ![Theo\_de\_Koning](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/theo_de_koning/32/136062_2.png) [@Theo\_de\_Koning](https://community.homey.app/u/Theo_de_Koning)\
**Post date:** [June 20, 2024, 6:16pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/183 "2024-06-20T18:16:13Z")

</div>

Thanks for this solution. 👍

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;

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [June 21, 2024, 9:09am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/184 "2024-06-21T09:09:55Z")

</div>

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.

 ![IMG_3342](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/b/0b102ba74bb1785323e25ca21b888e56a74ca094.jpeg)

---

<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:** [June 21, 2024, 9:32am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/185 "2024-06-21T09:32:53Z")

</div>

> [@Rmb](#):
>
> 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`.

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [June 21, 2024, 9:47am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/186 "2024-06-21T09:47:32Z")

</div>

> [@Arie\_J\_Godschalk](#):
>
> What do you mean with this?

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.

---

<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:** [June 21, 2024, 10:13am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/187 "2024-06-21T10:13:44Z")

</div>

> [@Rmb](#):
>
> 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)

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [June 21, 2024, 11:23am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/188 "2024-06-21T11:23:14Z")

</div>

Thanks, I was really mixing up those two functions.

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [June 24, 2024, 10:48am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/189 "2024-06-24T10:48:01Z")

</div>

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

---

<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:** [June 25, 2024, 11:10am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/190 "2024-06-25T11:10:08Z")

</div>

> [@Rmb](#):
>
> And show it in the status field of an AVD?

Yes, you can pick any textfield as status indicator.

But no, unfortunately i cannot control colors of text.

[Previous page](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876.md?page=8)

[Next page](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876.md?page=10)
