# Use an variable value to get a other variable

**URL:** <https://discourse.nodered.org/t/use-an-variable-value-to-get-a-other-variable/48643>\
**Category:** General\
**Created:** [20 July 2021 09:36 UTC](https://discourse.nodered.org/t/use-an-variable-value-to-get-a-other-variable/48643 "2021-07-20T09:36:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rchood](https://avatars.discourse-cdn.com/v4/letter/r/51bf81/32.png) [@Rchood](https://discourse.nodered.org/u/Rchood)\
**Post date:** [20 July 2021 09:36 UTC](https://discourse.nodered.org/t/use-an-variable-value-to-get-a-other-variable/48643/1 "2021-07-20T09:36:18Z")

</div>

Hi,

I'm using an Aqara Cube to control my lights and every face of the cube controls a different light.  
So I would like to use the rotating function of the Cube to be able to dim the light (which is controlled by the selected face).  
So I have to flow variables set like this:  
brightness\_2 = 254  
face = 2

And now I would like to use the `face` variable to retrieve the value of the `brightness_2` variable, like:  
face = flow.get("face");  
get\_brightness = "brightness\_"+face;  
brightness = flow.get("get\_brightness");

While trying to debug, I see that `get_brightness` has the correct value on that `brightness` is undefined

Any idea what I can do to make this work?

Complete function:  
face = flow.get("face");  
get\_brightness = "brightness\_"+face;  
brightness = flow.get("get\_brightness");  
msg.payload = face;  
msg.get\_brightness = get\_brightness;  
msg.brightness = brightness;  
return [msg];

Debug result:  
event\_type: "zha\_event"  
topic: "zha\_event"  
payload: 2  
\_msgid: "f6ec7dd0.ff4f5"  
get\_brightness: "brightness\_2"  
brightness: undefined

With kind regards,  
Robin

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 July 2021 10:08 UTC](https://discourse.nodered.org/t/use-an-variable-value-to-get-a-other-variable/48643/2 "2021-07-20T10:08:48Z")

</div>

> [@Rchood](#):
>
> brightness = flow.get("get\_brightness");

`flow.get()` expects a string containing the flow variable name, so when you use `flow.get("get_brightness");` it looks for a variable called `get_brightness`. What you want is the string contained within `get_brightness` so all you need is  
`flow.get(get_brightness);`

However, I am sure you would be better keeping the brightness values in an array. Then you could do `flow.get(brightness[face])`

---

<div class="post-metadata">

**Author:** ![Rchood](https://avatars.discourse-cdn.com/v4/letter/r/51bf81/32.png) [@Rchood](https://discourse.nodered.org/u/Rchood)\
**Post date:** [20 July 2021 13:57 UTC](https://discourse.nodered.org/t/use-an-variable-value-to-get-a-other-variable/48643/3 "2021-07-20T13:57:58Z")

</div>

> [@Colin](#):
>
> brightness[face]

Thank you very much, got it working now 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 August 2021 13:58 UTC](https://discourse.nodered.org/t/use-an-variable-value-to-get-a-other-variable/48643/4 "2021-08-03T13:58:38Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
