# \[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:** 8

<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 30, 2024, 10:57pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/145 "2024-03-30T22:57:46Z")

</div>

Wow, hats off!

> [@Patrick\_Van\_Deursen](#):
>
> logic cards needs to be set to text, not variable!

I think it should read  
_…text, not numeric_

---

<div class="post-metadata">

**Author:** ![viix](https://avatars.discourse-cdn.com/v4/letter/v/4af34b/32.png) [@viix](https://community.homey.app/u/viix)\
**Post date:** [April 10, 2024, 4:50am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/146 "2024-04-10T04:50:45Z")

</div>

_edit_ I figured it out, I used Math.round(Date.now() / 1000)

How do i get the Unix or Epoch time to use as a tag? Previously I’ve used $timenow$ with a mathJS card but I’m trying to use the BLL card to a GET Request as it needs the current time in 10 digits.

---

<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 10, 2024, 8:48pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/147 "2024-04-10T20:48:54Z")

</div>

I found this working script, but I can’t get it to work as BLL function

```auto
function epoch (date) { 
return Date.parse(date) 
} 
const dateToday = new Date() 
const timestamp = epoch(dateToday) console.log(timestamp)

```

---

<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:** [April 16, 2024, 10:05am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/148 "2024-04-16T10:05:21Z")

</div>

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

Hopefully is the picture clearly to understand.  
Later I saw also a MMM option but that was giving the same error.

---

<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 16, 2024, 10:24am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/149 "2024-04-16T10:24:12Z")

</div>

The formatting differs  
First timestamp has this format:  
`yyyy-MM-ddTHH:mm:ss+01:00`  
The “KNMI” timestamp has this format:  
`yyyy-MM-dd HH:mm:ss`

I think you first should convert your “KNMI” timestamp to that format, then I don’t see why it should error;  
You could pre-define it in BLL format settings:

 ![Screenshot_20240416-122026_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/2/a298577a8336c8dda007946309537b82549af055.jpeg)

or use a flowcard

---

<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:** [April 16, 2024, 10:39am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/150 "2024-04-16T10:39:48Z")

</div>

That idea of different timestamps came also the my mind therefore I let you know.  
There is also a split for having only HH:mm:ss and I am afraid to get there problems.

Now I know where I have to look for I will trying those other things.

**Edit**

Found  
date(“ISOZ”) gives 2024-04-16T12:56:05.547+02:00

---

<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:** [April 16, 2024, 5:32pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/151 "2024-04-16T17:32:59Z")

</div>

That date(“ISOZ”) gives the right format for the day, for now.  
BTW ISO gives **without** the +hh:mm

The KNMI gives this format by JSON. Time: “16-04-2024 18:58:03”  
There is also this Timestamp: 1713286683

For the time the only option I see now is Cut & Past in date-text.  
Moving 2024 and 16 and added the T.

For the Timestamp you need a script for the conversion.

Lot of thinking to do. 😉

* * *

**Edit 1**

Previously I received a tip to get the time from a ‘date with time’.  
That was a .split(’ ')[1] command.

Now I have found to put a “T”+ in front of it and get part of the correct time format.  
“T”+“16-04-2024 17:08:04”.split(’ ')[1]

Where can I see more of these ideas to continue puzzling?  
Copy the day and place it in front of that T.  
Do the same with the month and year.

**Edit 2**

By putting split(’ ') in the search I came to .slice( , ).

![](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/a/8a7866c17ebbaece4a8abbd84b52794fad24960e.jpeg)

The input = 16-04-2024 21:38:03  
The output = 2024-04-16T21:38:03

Now the variables with only the time I will let go otherwise I have 2 x 3 needed.

**Edit 3**

My goal in post 144 is sadly not there.  
The parseInt to ‘now’ worked for both date.  
Unfortunately the difference between the two is not yet clear.  
So now or then it’s working but mostly not.  
The error is then the same as in post 144.

For now 😴

**Edit 4**

> [@Arie\_J\_Godschalk](#):
>
> `parseInt(time('M', new Date('2023-07-03T16:15:12+01:00') - now))`
> 
> The `now` can be replace with for instance `new Date('2023-07-03T15:15:12+00:00')`

**Finally I found why I was not getting a 0 out of that formule** when I replaced ‘now’ with in the exact same way with the other value.  
Then I try to put ( ) around every `parseInt(time('M', new Date('2023-07-03T16:15:12+01:00')`

That make it then this:  
**(parseInt(time(‘M’, new Date(’ Data update KNMI ISO’)) - (parseInt(time(‘M’, new Date(‘Data update Weerlive ISO’))))))**

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [April 29, 2024, 3:58am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/152 "2024-04-29T03:58:03Z")

</div>

you can do the conversion, by the same method I used, which is a lot simpler (unless I am missing something. by:

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/e/0ee29be049ce53d1ebd6ee58fb3bdc13d610092c.png)

Setting how you want the date format to look like. You can change the order and add text wherever you want (see I added the T here ass well)

---

<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:** [April 29, 2024, 6:37am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/153 "2024-04-29T06:37:43Z")

</div>

But if you get the date as “26-04-2024 16:48:04” from a Json File?

---

<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, 9:21am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/160 "2024-05-08T09:21:07Z")

</div>

I have some problems doing calculations with negative numbers, e.g. in the following test-flow I want to subtract the value of “Abweichung Raumtemperatur” from 1, whereby “Abweichung Raumtemperatur” is a negative number. It works fine when using the standard logic card to calculate a variable, but it fails with the shown error when trying to use the BLL card to calculate the values as a tag.

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/f/7f20a7238fc9f196e9024c6ba1267348da880113.png)

It seems it’s trying to evaluate 1–0.5 (watch the two minus signs). I could put “Abweichung Raumtemperatur” into round brackets, but I can’t do that for all variables/capabilities in all circumstances.

What I’m a doing wrong? I can’t imagine, that BLL can’t handle negative variables/capabilities.

---

<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 8, 2024, 9:44am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/161 "2024-05-08T09:44:44Z")

</div>

When I do 1- -0.5 then I get 1.5.

Think you have to put a space after 1-.

---

<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, 9:56am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/162 "2024-05-08T09:56:03Z")

</div>

That’s another work-around, thanks.

---

<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, 9:57am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/163 "2024-05-08T09:57:40Z")

</div>

> [@Theo\_de\_Koning](#):
>
> Think you have to put a space after 1-.

Indeed, when you place 2 minus characters next to each other, you are telling JS to subtract 1 from the variable in front of it.  
But since the value 1 is not a variable, you recieve the error.

So the solution is indeed to place a space between the first minus character and the following (minus) value.

---

<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, 10:07am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/164 "2024-05-08T10:07:13Z")

</div>

I’m sorry, but that’s not a solution. I’m not placing two minus characters next to each other, I’m subtracting one value from another and both of those values may be negative. The logic card handles this correctly.

---

<div class="post-metadata">

**Author:** ![DirkH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkh/32/78952_2.png) [@DirkH](https://community.homey.app/u/DirkH)\
**Post date:** [May 8, 2024, 10:34am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/165 "2024-05-08T10:34:51Z")

</div>

Even if the work-around works, I would mark it as a design bug in the formula parser. It looks as if there is a simple macro substituting the variable by its value. But a variable is an entity and should not be combined with something else. 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 I would propose that the Better Logic Library sets blanks or brackets when dealing with variables instead of moving the responsibility to the user.  
Just my 2 cts to the topic. Currently I do not dare to use this App, although I installed it.  
I do not really understand the description in the readme text, how to use it effectively. I wanted to run some test to understand, what is written in readme.txt, and to find out what exactly is a BLL expression, etc.  
And now it seems to be dangerous. so probably I better do not touch it at the moment.

---

<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, 10:56am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/166 "2024-05-08T10:56:13Z")

</div>

Thank you for this elaborate explanation that identifies the real problem. I fully agree with you that this behaviour is unexpected, intransparent and therefore pretty dangerous. But a fix should be fairly easy as you already explained; IMO just adding spaces around variables should do the trick.

---

<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, 11:26am UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/167 "2024-05-08T11:26:03Z")

</div>

> [@DirkH](#):
>
> how to use it effectively

In my opinion BLL is pretty much a must-have if you are doing more complex flows. I’m only using a very small part of its capabilities, mostly calculating some tags, but compared to using the default logic cards, BLL is way more powerful and convenient. Not only can you do more complex calculations, you have more math functions at your disposal and - the absolute killer argument - you can get your results in tags and not only store it in some logic variable. This makes flows a lot clearer and compact, avoids race conditions and you need homey script a lot less.

Another feature that I rely on is the ability to get the timestamp of the last update of a BLL variable. I use that all the time to update various energy numbers, where I need to know when the power changed the last time in order to calculate the correct energy. Yes, I could do that also with logic variables or timers or with a separate PbtH device, but it’s far easier done with BLL.

---

<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, 1:58pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/168 "2024-05-08T13:58:59Z")

</div>

> [@DirkH](#):
>
> So I would propose that the Better Logic Library sets blanks or brackets when dealing with variables instead of moving the responsibility to the user.

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. This is a limitation of how Homey works, and Unfortunately there is not much i can do about that.

---

<div class="post-metadata">

**Author:** ![DirkH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkh/32/78952_2.png) [@DirkH](https://community.homey.app/u/DirkH)\
**Post date:** [May 8, 2024, 2:47pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/169 "2024-05-08T14:47:14Z")

</div>

> [@CaptainVoni](#):
>
> Not only can you do more complex calculations, you have more math functions at your disposal and - the absolute killer argument - you can get your results in tags and not only store it in some logic variable.

Thank you @CaptainVoni,  
probably I am too old and/or just not used to more modern programming languages than C or Visual Basic, not used to JavaScript, etc.

---

<div class="post-metadata">

**Author:** ![DirkH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkh/32/78952_2.png) [@DirkH](https://community.homey.app/u/DirkH)\
**Post date:** [May 8, 2024, 2:49pm UTC](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/170 "2024-05-08T14:49:11Z")

</div>

> [@Arie\_J\_Godschalk](#):
>
> Unfortunately, this is not possible,

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

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

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