How to read and Set the logic variables with HomeyScript?

If you want to look up a variable by name instead of id, you can use lodash like:

const vars = await Homey.logic.getVariables(); 
const myVar = _.find(vars, (o) => o.name === "Variable name");

log(`Changed switch is ${myVar.value}`)

await Homey.logic.updateVariable({id: myVar.id, variable: {value: "foo"}}) 
2 Likes