Use an variable value to get a other variable


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,

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

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

Thank you very much, got it working now :slight_smile:

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