Working with object name variables

I have a pop up whereby I can choose one of many Sonoff (MQTT Tasmota) switches and via notification see that switches operating info such as RSSI, network, gui_name, hw_name, etc...

So if I choose "1" in my pop up, the switch info that is displayed via a notification node is for context.flow.sw1_wifi . If I choose "2" the switch is context.flow.sw2_wifi .

But so far I have to write a function node such as:

if (msg.payload === 1) 
RSSI     = context.flow.sw1_wifi.RSSI;
network  =;
if(msg.payload === 2)
RSSI     = context.flow.sw2_wifi.RSSI;
network  =;

Is there any way to make it work along these lines?

if (msg.payload === 1) object = context.flow.sw1_wifi;
if (msg.payload === 2) object = context.flow.sw2_wifi;
RSSI     = object + . RSSI;
network  = object + . network;


If i understand correctly, something like,
RSSI = context.flow["sw"+msg.payload.toString()+"_wifi"].RSSI;

Neat. Let me try that.

I missed that you will need to set msg.payload.toString() as msg.payload is a number.

Got it.
Interestingly it works whether msg.payload is a string or a number from the popup.
Thanks again E1cid

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