[APP][Pro] Better Logic Library - Just some better logic, variable and library management

Hi,

I’m starting with my Homey Pro 2023 … added lights, dimmers, shutters, etc … and created some simple flows and some advanced flows.

Now struggling with time calculation for a new flow that should steer my shutters based on the sunset time and a fix time (20u00): Time to go down = ((Sunsettime - 20:00)/2) + 20:00

Example1 when Sunset at 22u00: ((22:00-20:00)/2) + 20:00 = 21:00

Example2 when Sunset at 18u00: ((18:00-20:00)/2) + 20:00 = 19:00

I’ve tried to find a solution with the Better Logic Library app … but, unfortunately, my knowledge isn’t (yet) to a level to solve my challenge.

Can anyone put me on the right track with BLL ?

Goal is to use this in an advanced flow together with other input/conditions/…

Thanks !

For date/time calculation you might consider “epoche time”, the number of miliseconds past since 00:00:00 01-01-1970. BLL has several conversions for such calculations.
See [APP][Pro] Better Logic Library - For Users - #185 by Arie_J_Godschalk

I’d like to do some basic variable calculations, mixing or not the intrinsic Homey library and the BLL library
With :

  • VarX_HomeyLogic = a Homey variable
  • VarX_BLL = a variable created with BLL
  • VarY = Another variable, either BLL or Homey

Trying to do things like :

  1. VarX_HomeyLogic=VarX_HomeyLogic+0.21+VarY
  2. VarX_HomeyLogic=VarX_BLL+0.21+VarY
  3. VarX_BLL=VarX_HomeyLogic+0.21+VarY
  4. VarX_HomeyLogic=VarX_HomeyLogic+0,21+VarY

A) Which “Set variable …” box should I use and what should I write in it.
B) The {} and have a particular role apart from doing the same thing as parentheses.
C) could you have some examples to show (or link to basics How Too !)

Then how can I :
D) update VarX_BLL with the content of VarX_HomeyLogic ?
E) update VarX_HomeyLogic with the content of VarX_BLL ?

Maybe it seems easy for number of you but I just didn’t get the trick!

Thanks a lot

In Homey logic calculations you’ll need to put it between {{ }} as shown in the flow card info
Not needed in BLL logic calculations

(You’ll have to trust me I used the right variables in my examples)

  1. VarX_HomeyLogic=VarX_HomeyLogic+0.21+VarY

_
2. VarX_HomeyLogic=VarX_BLL+0.21+VarY
Same principle as 1.)

_
3. VarX_BLL=VarX_HomeyLogic+0.21+VarY

_
4. VarX_HomeyLogic=VarX_HomeyLogic+0,21+VarY
This is equal to 1.)
but, commas are used for functions. Always use decimal points in flowcards and calculations.

_

You can pick any variable or tag.

_

1 Like

Why can’t I create variables automaticly from the thencard?
I have tried to save the flow and restart the application and nothing changes…


Am I doing something wrong?

Because “create new number” means you have to create the BLL variable once in the BLL app.

Actually, with most flowcards, the variable will be created as soon as you save the flow.
(Only not with bll expression, since the type could be number, text or yes/no)

Not sure why i wouldnt work tbh.

When finished entering the name, did you select it? Otherwise it won’t be added

“Create new number” it says.

Yes, I selected it :joy:
If you have the same version as me, could you test if it works for you?

Homey Pro (Early 2023)
Better Logic Library - v3.4.13

I just had to make sure, not everyone ‘gets’ it :wink:

So, I’ve just tested with both standard and advanced flows: works fine.
but:
advanced flow: I get the same error, when TEST running the flow.
So don’t operate the card in any TEST mode I’d suggest!

Homey 2019 v12.1.0
BLL v3.4.13

hi @Arie_J_Godschalk every so many days, this app stops working on my 2019 Homey Pro. It’s quite annoying b/c other (important) flows are depending on this app functioning properly. I have to reboot this app to have it working again for a few days until it stops working again…

Here is the error log code: 72779ce2-788d-49fd-9d1b-fdc47fb09210.
Can you see (hopefully!) what’s going wrong?

Lately the Date and Time app gives problems with sun rise/set time settings.
When you have eg -10 minutes then you can’t edit that canvas. The flow is still working
Because by saving it you get argument error and all your negative values turning red.
For now I use the “sun positions” app (Google translate)

Now I found out the you can use BLL for calculate time.
Someone had to add some day for checking out.


The first flow I copy off that but with the 10 minutes subtracting.
The variable “tijd nieuw” is 10 minutes earlier the time NOW

The last one is when I get to the smallest version after all the trying :wink:
To understand the errors I needed my Notepad ++
When they where gone I get always time NOW.

Instead of “Date.now()” I like to use a sun rise or set tag to calculate and put that it to a variable.

hi @Arie_J_Godschalk did you see this message ?

I’m trying to send myself a notification with current time plus the remaining time of a timer. (So the timer ends at hh:mm)

But when I try to store the current time with the second card at 13:03 the result is 12:03.

To correct this i can add (60x60x1000)milliseconds as shown in the first card?
Is this the best way to go?

Homey unfortunately works with UTC time, which was introduced in june, 2022.

Not sure if I understand your case right, but you can use this card below, which has the option to add your timezone and therefore it shows your local time instead:

1 Like

@Arie_J_Godschalk

reminder :innocent:

1 Like

If you leave it empty, your local timezone will automaticly be used.

1 Like

But that’s the “big” Homey issue: sometimes the local time gets showed / used, sometimes the UTC time.
Generic (and non-tech) users often can’t tell.

My thoughts here were: better safe than sorry :wink:

I’d like to have a calculated variable to be capped at either 0 or 1 depending if the result is less or more than that - if in between it should return the calculated value. I’d like to avoid using multiple ‘Variable greater than 1’ or ‘Variable less than 0’ cards, is there any BLL expression / math.js function I could put into my existing card?

1 Like

This should do it:

min(max([calculated_value],0),1)

3 Likes