Better logic with homeyscript

I’m not so into better logic yet since built in logic works great for me so far. Homeys own API works nice for crud operations in logic variables.

hey @Ludwig_Hallgren i would use homey logic also, I just need to be able to set variables from inside homescript not via a flow.
is this somehow possible?

for me as a reminder: https://forum.athom.com/discussion/4541/ok-homey-whats-the-current-day-number
to test again

@adem_p yes that is very easily done. Look at the thread I linked at the last 4-5 comments.

For what I know it is not possible to change values of tags/variables of other apps.
That could/would give inconsistent results as not all apps are prepared for that.
Since the last update it is possible for set the Homey’s global variables.
Beside that HomeyScript has its own variables.

let sys = await Homey.system.getInfo();
var theTime = new Date(sys.date);
var theHour = theTime.getHours();
if (theHour > 12) { theHour = theHour - 12};
let BLApp = await Homey.apps.getApp({id:"net.i-dev.betterlogic" });
BLApp.apiPut('Klok12h/' + theHour);

I tried that also, but had some issues with homeyscript.
a) some of the scripts disappear/deleted. after adding a new test script.
b) parameter wrong message disappeared after restarting homey.

but nevermind thank you @JPe4619 and @Dijker for your example and clearance

hi, thanx for your idea/example.

i am very close to finish. but the last step does not work. i read a better logic variable, do slicing an want to write it back, but the variable does not change.

do you have an idea, here is my code:

// my script

let BLApp = await Homey.apps.getApp({id:‘net.i-dev.betterlogic’ });

//set Better Logic Variable

//BLApp.apiPut(“VariableName/value”);

//get Better Logic variable

let tmp = await BLApp.apiGet(‘CameraLink’);

var link = tmp.value;

var laenge = link.length;

var res = link.slice(0,laenge-17);

//var link = await BLApp.apiGet(‘CameraLink’);

//console.log(res) ;

//var res = link.slice(0,link.Length()-1);

//console.log(res) ;

//set Better Logic Variable

//BLApp.apiPut(“CameraLink/”+res);

BLApp.apiPut(CameraLink/${res});

//Hi, ${user.name}!

//BLApp.apiPut(‘CameraLink/NEU’);

//console.log(tmp) ;

//console.log(link.name) ;

//console.log(link.type) ;

//console.log(link.value) ;

//console.log(CameraLink/${res})

return(true);

I’ve had some struggling also setting / reading better logic variables. Athom did some syntax changes. Read this topic for solutions:

You should use the first of this two lines

Sorry I dont have BetterLogic on my Homey, so can not test it, if it is not working, please indicate, what is working and what is not.

Please be aware of the “quote” signs, they sometimes are misformed .

hi jpe4619

thanks for your reply. the var res gets the correct string without the last 16 character (&export=download), homeyscript prints it running console.log(res) ;

but still the betterlogic variable does not get updated by
BLApp.apiPut(“CameraLink/”+res);

here is my flow to test, i get the same link with the &export=download twice.
when i dont use the variable res, e. g
BLApp.apiPut(“CameraLink/varvalueexmaple”);
then the BL var is updated.

Found another peace of code, maybe you can follow this example?

let BLApp = await Homey.apps.getApp({id:“net.i-dev.betterlogic” });
let result = await BLApp.apiPut("/" + BLVarName + “/” + Math.round(dayOfYear) );
return true;

FWIW, you can format pieces of code using the </> button (or using ` or ``` in the text). Makes it much easier to read.

1 Like

thanks for your idea and your awesome support.

unfortunately the script still does not change the better logic variable. maybe i missed something in my code below?

Have installed BL and tested with both lines:

BLApp.apiPut(“CameraLink/”+res);
let result=BLApp.apiPut(“CameraLink/”+res);

Both are working well in next flow"

image

1 Like

hi again,

could you please post your complete code? your last screenshot shows the same variable value twice, does this mean it works?

i tested your 2 lines for putting the new value to BL variable, but still no success.

with my code i would expect that the link will be reduced each script run by 16 characters. but it does not work because setting the new values does not change the variable in Better Logic.

Never give up:D

Yes, it works perfectly, as mentioned above, tested with both lines (one at a time)
> // my script
> let BLApp = await Homey.apps.getApp({id:"net.i-dev.betterlogic" });
> let tmp = await BLApp.apiGet("CameraLink");
> var link = tmp.value;
> var laenge = link.length;
> var res = link.slice(0,laenge-17);
> //BLApp.apiPut("CameraLink/"+res);
> let result=BLApp.apiPut("CameraLink/"+res);
> return(true);

Your BL-variable can be changed from IFTTT side and from your HomeyScript, are you sure these two don’t interfere? Maybe you should use two different variables.

Thats the right spirit :+1:

Thanks Robert, as (almost) always you are right,
but now an offtopic question to the man who knows it all:
do you have an explanation for the “misforming” of the quote marks (" ") when they are entered in this forum? and if so, is there a way to avoid this?

The forum editor converts normal quotes to “smart” quotes. It doesn’t look like you can avoid this (unless "you're using the preformatted text option"). Very annoying :rage:

1 Like

thanks again, I am getting closer and closer.

the following script with code line 4 active works correct, but when i disable codeline 4 and use the flow THEN Card with SET BL Variable CameraLink = tag1 (this is a lokal tag and it holds the link from IFTTT) the script does not perform the slicing.

very strange

And what happens when you use my Flow? https://homey.app/f/xOhD6b
Or what happens when you use two variables?
Maybe there are (formatting) characters in the string that are not displayed?