NodeRed prepare data in separate node

Hi all,

I’m trying to create a ‘clean’ process for configuring my lights.
To do this, i’m using NodeRed and would like to prepare all the ‘data’ (brightness, color, transition, etc) in a separate node and then send it to several ‘call service’ nodes to be able to easily apply the same dataset to several lights in a flexible way.

What I’ve tried is to use a ‘template’ node to compose the data and send it to ‘msg.payload.data’, but I didn’t yet succeed. Anyone who can help me to get this working?

A copy of the setup can be found below:

[
    {
        "id": "3c763b1c.fec884",
        "type": "template",
        "z": "5c6092e6.285e1c",
        "name": "",
        "field": "payload.Data",
        "fieldType": "msg",
        "format": "json",
        "syntax": "plain",
        "template": "{    \"transition\": 1,    \"color_name\": \"magenta\",    \"brightness_pct\": 100}",
        "output": "json",
        "x": 920,
        "y": 240,
        "wires": [
            [
                "1379c144.4f8bbf"
            ]
        ]
    },
    {
        "id": "8ebe21dd.c2b22",
        "type": "inject",
        "z": "5c6092e6.285e1c",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 700,
        "y": 240,
        "wires": [
            [
                "3c763b1c.fec884"
            ]
        ]
    },
    {
        "id": "1379c144.4f8bbf",
        "type": "api-call-service",
        "z": "5c6092e6.285e1c",
        "name": "",
        "server": "505f997a.bd0f78",
        "version": 1,
        "debugenabled": true,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.hue04_light",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "payload",
        "output_location_type": "msg",
        "mustacheAltTags": false,
        "x": 1150,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "505f997a.bd0f78",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "addon": true
    }
]

Try this:

[{"id":"5bf7b985.00a0c8","type":"template","z":"c45103e8.03da3","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n    \"data\":\n    {\n        \"transition\": 1,\n        \"color_name\": \"magenta\",\n        \"brightness_pct\": 100\n    }\n}","output":"json","x":450,"y":190,"wires":[["dfdf0f00.19cc2"]]},{"id":"fbd432c8.e9baa","type":"inject","z":"c45103e8.03da3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":190,"wires":[["5bf7b985.00a0c8"]]},{"id":"dfdf0f00.19cc2","type":"api-call-service","z":"c45103e8.03da3","name":"","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.hue04_light","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":680,"y":190,"wires":[[]]}]

Hi,
Thanks! This worked like a charm.

I’m now able to link a set of data to different light entities easily in Node-Red, really convenient way of working.
As an example i’ve added a screenshot which should be quite self-explanatory, if there’s anyone with any suggestions or tips to it i’m open for that.
Thanks in advance!