Table of Variables

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.

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
Maybe this will help you with lookup table
https://www.reddit.com/r/nodered/comments/9q7v3n/how_to_create_a_lookup_table/

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.

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.

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:

(
    $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:

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.

@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

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