# Table of Variables

**URL:** <https://discourse.nodered.org/t/table-of-variables/42323>\
**Category:** General\
**Created:** [9 March 2021 11:07 UTC](https://discourse.nodered.org/t/table-of-variables/42323 "2021-03-09T11:07:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PHewson](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@PHewson](https://discourse.nodered.org/u/PHewson)\
**Post date:** [9 March 2021 11:07 UTC](https://discourse.nodered.org/t/table-of-variables/42323/1 "2021-03-09T11:07:03Z")

</div>

Hi,  
For transparency, I am not a programmer in C, C#, json etc, but by using multiple guides I got there!  
I work with Crestron Simpl windows and my Simpl+ (C deriviant) is limited.

I have done a search but NodeRed is new to me.

A client asked me if I could look at a way of using Google Home to control his lighting system.  
Crestron controls it using a RS485 protocol.

I have it working using a lot of functions....  
I was thinking if it is possible to have a table of 'Room Hint' and assign a value, to cut down on the amount of functions I need.

IE The Kitchen in this project is Area 10  
The command string I send for a room is always relevant to that area.  
"@SS01: **A10** :F03"cr/lf ;selects scene1 in Area10

So if I was able to have a table like

Room Hint Area  
Kitchen A10  
Utility A11  
Lounge A5

True SS01 ; Area On  
False SS00 ; Area Off

How could I Create or store that table and then write the function to build the command.  
IE  
Google home switch function. Topic = Room Name, True (On)  
Debug message for reference.  
payload: true

topic: "Kitchen"

So the general output command would be  
@'payload':'Topic':F03 but after processing it becomes "@SS01:A10:F03" cr/lf - which turns the light on, etc.

If someone could point me in the right direction to some links, it is not that I have much to do in the UK during LockDown3!

Hope my question makes sense!

Regards  
Paul.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 March 2021 11:18 UTC](https://discourse.nodered.org/t/table-of-variables/42323/2 "2021-03-09T11:18:27Z")

</div>

Not sure if i understand fully, but it sounds like you need to create a llok up table.

This can be done by creating a JSON with keys as device names and values as the information corresponding to the device. This can be stored in context storage as a global or in a database/textfile also.  
Context would be easier and fairly simple.  
[https://nodered.org/docs/user-guide/context](https://nodered.org/docs/user-guide/context)  
Maybe this will help you with lookup table  
[https://www.reddit.com/r/nodered/comments/9q7v3n/how\_to\_create\_a\_lookup\_table/](https://www.reddit.com/r/nodered/comments/9q7v3n/how_to_create_a_lookup_table/)

> [@How to access a lookup table from \`\`\`Function\`\`\` Node](https://discourse.nodered.org/t/how-to-access-a-lookup-table-from-function-node/4063):
>
> I am wondering where to begin if I want to access a lookup table on my computer (example .csv) that would have two columns and I could match up a know variable passing through a function node on the payload and assign a new variable to the payload after a match is made. For example my table has a column "ip address" and a column "location". I would fill out the table with the ip address and associated location, and as my function node runs, it will be able to output the location based on the i…

---

<div class="post-metadata">

**Author:** ![PHewson](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@PHewson](https://discourse.nodered.org/u/PHewson)\
**Post date:** [10 March 2021 15:38 UTC](https://discourse.nodered.org/t/table-of-variables/42323/3 "2021-03-10T15:38:18Z")

</div>

Thank you so much for the links.

I have been trying to understand the code.  
Found out I can copy the long lines of text and import it into node red!  
I have read and watched the links numerous times.....

Because I am not in or anywhere near your realms of knowledge i am honestly struggling.

If I need to 'Buy a Coffee' for someone to get me started I have no issues in doing that.  
I know exactly what I am trying to achieve, but do not have the expertise to implement it in Node Red!

I think I will need 2 or 3 lookup tables or files would be easier, one for 'Room' or 'Topic', one for Payload 'True' or 'False' or a value.

I will persevere more when I get back from a customer visit.

Regards,  
Paul.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 March 2021 16:03 UTC](https://discourse.nodered.org/t/table-of-variables/42323/4 "2021-03-10T16:03:01Z")

</div>

I could help more but i would need examples of your device names and information to link to each.  
If you export your flow maybe i could see what you need and produce an example for you. Examples of the input data and how the output should look. would help to. I see you have added some examples but they are not to clear.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [10 March 2021 16:48 UTC](https://discourse.nodered.org/t/table-of-variables/42323/5 "2021-03-10T16:48:22Z")

</div>

The simplest "lookup table" I can think of would just be a `change` node, using a JSONata expression to lookup the code and area, returning the command string -- something like this:

```auto
(
    $code := payload ? "SS01" : "SS00";
    $area := {
        "Kitchen": "A10",
        "Utility": "A11",
        "Lounge": "A5"
    } ~> $lookup(topic);
    
    "@" & $code & ":" & $area & ":F03\r\n"
)

```

The JSONata expression language is fairly advanced, but this seems more readable to me than a block of Javascript code... Here is how it looks in the node-red editor:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3cfc77dcab8b3d70357ff0f9d20795a0cba5d3b4.png)

It has the advantage of having a built-in tester -- just put your msg data in the lower-left pane and the output appears in the lower-right pane, in real time, as you modify the expression above.

---

<div class="post-metadata">

**Author:** ![PHewson](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@PHewson](https://discourse.nodered.org/u/PHewson)\
**Post date:** [10 March 2021 20:15 UTC](https://discourse.nodered.org/t/table-of-variables/42323/6 "2021-03-10T20:15:33Z")

</div>

@shrickus Yes that is easier to understand, thank you.

Do I need to install something in my Palette to use JSONata Exp Editor?

I added a change node and could not see that editor.  
Very new!

Thanks again.

Paul

---

<div class="post-metadata">

**Author:** ![PHewson](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@PHewson](https://discourse.nodered.org/u/PHewson)\
**Post date:** [10 March 2021 20:59 UTC](https://discourse.nodered.org/t/table-of-variables/42323/7 "2021-03-10T20:59:01Z")

</div>

After lots of clicking and swearing I found it and eventually got it to work.

Thanks again.

Just need NORA to stay connected!

Regards,

Paul

---

<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:** [24 March 2021 20:59 UTC](https://discourse.nodered.org/t/table-of-variables/42323/8 "2021-03-24T20:59:05Z")

</div>

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