I have a simple script to reset some variables.
Since shortly I get the message “Classic”, meaning I seem to use an old API library or something
When I copy and past the script to a script with a new name, but same content, it does not work anymore. I can’t figure out what’s wrong. Debugging results in that it suddenly cannot find await Homey.logic.getVariables anymore by its name, it returns “undefined”. In the original version the exact same code returns the correct values. So apparently I need to use convert my code, but no idea, read the tutorial, but could not find the solution.
Could be, but I usually like some coding examples. I often use the examplexys.js that are in my homey scripting evironment. But also these examples all have a orange flag, probably because of being classic. So a bunch of new examples in the scripting environement would also be helpful.
This tutorial does not help very much either. Tutorial: Migrating deprecated scripts - HomeyScript
Pasted this in a new script, and it does not work anymore, does not find the correct variable, 3 time the same id. which is not correct. In the old code the correct id’s are found.
The problem to me is that I have an old script that I use as an example for new scripts, but in the new script exactly the same code does not work. The old script is since shortly indicated as “classic” , with the suggestion to migrate it to something else. Also this is left to the programmer to find out for him/herself, because to me the manual offered is abacadabra, I need examples. It would be helpful if there was a kind of indication what pieces of code need attention, or even an upgrade service, should be possible in these days of AI.
Anyway, I tried some different code I found in a post, and that works, but I have a bunch of scripts with the “classic” indication so I would rather not spent a day per script migrating it to the new HomeyScript version. I will post a message to the Homey support team.
I know the frustation on finding updated examples etc… been there myself… this script example will do what you want i belive, there is a slight difference from your orginal code:
setparvalue("testvar","test");
setparvalue("testvar1","test");
setparvalue("testvar2","test");
//
async function setparvalue(varname, varvalue) {
const advancedvar = await Homey.logic.getVariables({ filter: { name: varname } });
// Find the variable object by its name
const variable = Object.values(advancedvar).find(v => v.name === varname);
if (!variable) {
throw new Error(`Variable ${varname} not found.`);
}
const parval = variable.value;
const parvalid = variable.id;
log(parval, parvalid);
await Homey.logic.updateVariable({ id: parvalid, variable: { value: varvalue } });
}
tested and working with changing the variables.
i claim no expertise in coding, this was done with GPT O1
and it seem log wil return undefined no matter… might be a Homey thing…
@TheKos I see more changes in your code. So I am curious to know if you have any idea what has changed? Is it the library or the script language version? Or are you merely following examples?