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

You probably already know, but you can do this function also with a Logic card.

Yes, I do if you have a single condition. But I have 4 of these with an OR in between together with a few other conditions. I think you can have 3 groups of OR conditions. The forth one calls for another solution. Is it possible to have a logic card doing this?
Zon=a flow tag
“Zon” == “Köket” or “Zon” == “Hallen” or “Zon” == “Lekrummet” or “Zon” == “Toaletten”
image

I’m trying to figure out if I can use BLL in advanced flows to calculate what time I should start a task, where I know how many minutes it takes to complete the task and when it should be ready.

Say I want a to start a task $tasktime minutes before 18:00. Somehow can’t get my head over how to do this.

The result should be something I can use to compare to for a trigger.
For example every five minutes I can run a logic test see if it is now within $tasktime minutes before 18:00 and start the task.

In Homeyscript it would be

const endDate = new Date();
endDate.toLocaleTimeString();

endDate.setHours(18, 00);

var startDate = new Date(endDate);

var durationInMinutes = 20;

startDate.setMinutes(endDate.getMinutes() - durationInMinutes);
startDate.toLocaleTimeString();

console.log(startDate);

I made a time calculate flow using this app.
It might get you going:

You can import this flow right away using the Device Capabilities app from Arie
Screenshot from 2023-01-13 17-10-41

https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981/73?u=peter_kawa

That’s just a Device Capabilities app’s virtual button. Ignore it’s name, I use it for example flows and forgot to rename it.
Edit: adjusted in screenshots and TEF

although again it’s a very nice flow from @Peter_Kawa , perhaps here is a somewhat simpler solution.
Only issue is, it works with UTC (since Homey base time is always set to UTC/GMT).

image

new Date().setHours(18,0,0,0) - Date.now() < 5*60*1000;

This Condition Expression card will return true when the time is less then 5 minutes before 18u00utc.

1 Like

Oh, that is a nice one. And easy.

I can always use local offset variable for setHours to cover timezone and DST.
Can I actually get those with BLL expression? I.e. as a local time offset?

Well, you can kind off, but not in the easy ‘formatting’ way: because i didn’t find a all-around solutions independend of locale and timezone.

date('DATETIME', null, 'en')

You will get a tag, you can use the last number if it’s like this.

But if you get this, you will probably get the same result as me:



So, the complete solution would be:
new Date().setHours(18-Number.parseInt(_.last(date('DATETIME', null, 'en'))),0,0,0) - Date.now() < 15*60*1000;
(this is true when less then 15 minutes from your local 18u.

image

2 Likes

Thanks for the heads up, Arie!
But from an average Homey user’s point of view, I could in no way ever come up with the code for ‘if BLL expression is true’ with
new Date().setHours(18,0,0,0) - Date.now() < 5*60*1000;
You have to be quite into javascript imho :wink:
But when I look at the code, it looks quite logical and simple to use :+1:

2 Likes

This is guru level :crazy_face:
I only missed the minutes part of the targeted time, a first wild guess seems to work for 'is true when less than 15 minutes before 18.30h:
new Date().setHours(18-Number.parseInt(_.last(date('DATETIME', null, 'en'))),30,0,0) - Date.now() < 15*60*1000;

2 Likes

Exactly what I was looking for. As a proof of concept this is what I got done with it:

2 Likes

Hi guys,

I am getting a value (“10.01”) as a string from MQTT. How can I convert the format to a number

Use a BLL expression as tag Flowcard with:

Number.parseFloat("[[tag]]")

That should be it. The Number tag will contain it’s value.

1 Like

Hi, I read that BLL supports arrays.
I am interested to see an example.

I want to store the rainfall for each day of the past week and then sum up the rainfall for the past X days to see if I should re-enable the garden watering.

I would also like to track some other value daily for the past month.

Hey @Rrrr ,

Wel, yeah, not specificly, but generally, BLL supports Arrays.
because i don’t exactly know how users will want to use this, i haven’t implemented special array functions or anything, but you can do that yourself quite easily.

For instance, here a small array functionality.

  • Create a BLL function called pushAsString and place this in it’s body:
function(arr, value) {
  arr.push(value);
  return JSON.stringify(arr);
}
  • Add a flowcard Set variable to text: Set ArrayTest to []
  • Add a flowcard Set variable to bll expression: Set ArrayTest to pushAsString([[ArrayTest-token]], 1);
  • Add a flowcard Set variable to bll expression: Set ArrayTest to pushAsString([[ArrayTest-token]], 2);
  • Add a flowcard Execute BLL expression as Tag: _sum([[ArrayTest-token]])

This wil result in a token with 3.

Flow:

TEF:

[tef:FLOWS:"H4sIAAAAAAACA+2UTY+bMBCG/0rkU1fCkcE2xvS03eveuqdGERqbIUEiBIFJE6X57x3IdtVIkVartrde+JiZd2beB+EzCyw/sxbDsuYlHpYOQ8C+2W9qPyXCqcNheoD2xPIVVcIOWc4e+x5OLzgEdllfItZS6MusXDxP0sVz7XroT+xCSZiFNZVIgVnltOLe0kXZ0nOHWnKJsbHOSClAs2u3qfdinkKBeRXtwFaOJKbyFVeQGm59mXENxscSpMpKOdUdWS4iRtumdNtTq+1+h6ccui6/bzOad3unKh8wFEPo63ZTHKCvwTVISqLHwId637LZ6Jm9JfM7sKIZKIWunei9xMH3dTd3yNlTjxBw0eL3xWsF8TtAM06a1XrGqTKRlR6AjMeCK5Vk3GqBvNI2iWWZJNZVNxzi7K+CwCP6MWDhmgKPXY/DcHX/YRS/fN2h0uNuf6BIBc2AEWtgCE9baDdYUlUiEsmF5Il+iVWubS7NMk6zb9PYMZDR0I9IoH7bLmfdOGwfh6/zgE+r1Tsmf7ztuV5Hi/jh80y+sj7OMAHuTKq5MpXkTtqKC6UqLXUJiXE35KX4T/6PyCev5H0ijU0N8Co29O+7FLiFUtCHEJlAUaZK4g15lf578kWAzV36N/aL5TDuPub7gTxf6Fz9CWI6jV+dBQAA":/tef]
3 Likes

Hi,

Is there any way to retrieve the Last set" value for a variable in Better Logic? Background: I store temperature data in Better Logic variables. I’m trying to calculate the average/min/max for the temps as long as they are not invalid/too old etc. Instead of storing a temperature (as now) in A) a temp variable and B) a corresponding date variable it would be fantastic if I could access the “Last Set” attribute when determining if the temp is valid or stale.

Many thanks!

Not yet i think, but that can be created.
Can you create a ticket for it?

If I understand your question correct:
Via a little d-tour it’s available in an Advanced virtual device, when you use a textfield, and let Better Logic reflect the ‘Last Set’ property of a var:

Then the tag (when the Create Tag box = ticked) with the timestamp is available in flows.

1 Like

Thank you. I like your example. To use an array I would need to replace values in the array ( in my example the array position reflects the day (x=1-7) and the value is the rainfall of day x) or make a calculation of a subset in the array (eg. Total rainfall in the last x days). Is there a way to reference array positions and get the value of those?

Yeah, place [0] after the token, which would make it technicly:
[5,6,2,5][0].

This would give you a 5.

1 Like