Advice please on best way to attack this

Hi Craig,

The approach that came to my mind is a mix of what you want to do and what Colin just suggested.

Instead of using a bunch of nested switch cases you could instead create an object that works as a table lookup. As Colin said it is good to engineer a solution that makes easier to implement any eventual change without messing up something else. It is much better to change an object than rebuilding a complex code with nested switch cases (and all those tricky breaks statements).

I understand that your RBE node will provide you with two numbers whenever there is a state change. If you combine these two numbers into a single string it could be used as a key to fetch the table lookup object. In the object, you can have a property that says what the change is about (eg. property status) and a property that is a function (therefore a method) that may be used to take actions to respond to the change.

Example of an object could be:

let def = {
    
    "176192": {
        "status": "pump turned on",
        "action": function () { node.warn("176192"); }
    },
    "176208": {
        "status": "pump turned on and boiler turned on and solar off",
        "action": function () { node.warn("176208"); }
    },
    "176240": {
        "status": "pump turned on and boiler turned on",
        "action": function () { node.warn("176240"); }
    },
    "240176": {
        "status":
            "pump turned off and boiler turned off",
        "action": function () { node.warn("240176"); }
    },
    "208192": {
        "status": "boiler turned on",
        "action": function () { node.warn("208192"); }
    }
};

Follows a flow that put it all together. The action I coded in the functions is only a display but you can do whatever you need, like build an MQTTT reply for instance.

[{"id":"e60c1848.624e28","type":"tab","label":"Flow 15","disabled":false,"info":""},{"id":"e4eefb9b.fe1b78","type":"inject","z":"e60c1848.624e28","name":"","topic":"","payload":"240176","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":240,"wires":[["9cc5fb51.b4d948","4643eec9.d5e6f"]]},{"id":"5eb39148.2562f","type":"function","z":"e60c1848.624e28","name":"Create Object","func":"let def = {\n    \n    \"176192\": {\n        \"status\": \"pump turned on\",\n        \"action\": function () { node.warn(\"176192\"); }\n    },\n    \"176208\": {\n        \"status\": \"pump turned on and boiler turned on and solar off\",\n        \"action\": function () { node.warn(\"176208\"); }\n    },\n    \"176240\": {\n        \"status\": \"pump turned on and boiler turned on\",\n        \"action\": function () { node.warn(\"176240\"); }\n    },\n    \"240176\": {\n        \"status\":\n            \"pump turned off and boiler turned off\",\n        \"action\": function () { node.warn(\"240176\"); }\n    },\n    \"208192\": {\n        \"status\": \"boiler turned on\",\n        \"action\": function () { node.warn(\"208192\"); }\n    }\n};\n\nflow.set(\"def\", def);\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":80,"wires":[[]]},{"id":"9cc5fb51.b4d948","type":"function","z":"e60c1848.624e28","name":"Display status change","func":"let d = flow.get(\"def\");\nnode.warn(d[msg.payload].status);\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":240,"wires":[[]]},{"id":"4643eec9.d5e6f","type":"function","z":"e60c1848.624e28","name":"Execute action","func":"let d = flow.get(\"def\");\nd[msg.payload].action();\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":300,"wires":[[]]},{"id":"598bc7b9.926518","type":"inject","z":"e60c1848.624e28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":150,"y":80,"wires":[["5eb39148.2562f"]]}]