# Homey scripts vind de aangemaakte variabele niet

**URL:** <https://community.homey.app/t/homey-scripts-vind-de-aangemaakte-variabele-niet/135555>\
**Category:** Vragen & hulp\
**Tags:** homey-pro\
**Created:** [April 27, 2025, 7:18pm UTC](https://community.homey.app/t/homey-scripts-vind-de-aangemaakte-variabele-niet/135555 "2025-04-27T19:18:02Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [April 27, 2025, 7:48pm UTC](https://community.homey.app/t/homey-scripts-vind-de-aangemaakte-variabele-niet/135555/2 "2025-04-27T19:48:10Z")

</div>

Hoi Alle,

De ID dient echt de ID, en niet de naam van de variabele te zijn.

> [@Setting Logic Variable by HomeyScript](https://community.homey.app/t/setting-logic-variable-by-homeyscript/14819/43):
>
> Here I have created two functions which you can add to your scripts.

```auto
//Name of Logic Variable
var name = "TVProgramma";

//Read Logic Var
var value = await ReadLogicVar(name);
console.log("The parameter '"+name+"' has a value '"+value+"'");

//Write Logic Var
var new_value = "NOS Journaal";
await WriteLogicVar(name,new_value);

async function ReadLogicVar(name){
  let Logic = await Homey.logic.getVariables();
  let idArr = Object.entries(Logic);
  let filtered = idArr.filter(([key,value]) => value.name==name);
  let [[,{id:varID}]] = filtered;

  var varArr = await Homey.logic.getVariable({id:varID});

  return varArr.value;
}

async function WriteLogicVar(name,value){
  let Logic = await Homey.logic.getVariables();
  let idArr = Object.entries(Logic);
  let filtered = idArr.filter(([key,value]) => value.name==name);
  let [[,{id:varID}]] = filtered;
  
  var varArr = await Homey.logic.getVariable({id:varID});

  if (typeof(value) == varArr.type){
    await Homey.logic.updateVariable({id:varID,variable:{value:value}})
    //console.log("Value has been updated")
    return true;
  }
  else{
    console.log("New value has the wrong type! Expected type is '"+varArr.type+"', not '"+typeof(value)+"'. Value has NOT been updated!")
    return false;
  }
}

```

---

_[View the full topic](https://community.homey.app/t/homey-scripts-vind-de-aangemaakte-variabele-niet/135555)._
