Trouble inserting dashboard slider value into JSON payload

Hey All,
I've got a dashboard slider that sends 0-255 to an esp8266 using JSON. I can do this from an inject mode with the following payload, it works as intended.

{"modeBrightness" : 50}  // renders 50

Next I want to send the brightness from a slider on the dashboard. I'm trying to add it to JSON with a change node with the following code.

{"modeBrightness" : "{{topic}}"}  // renders {{topic}}  

{"modeBrightness" : "{{payload}}"}  // renders {{payload}}

How can I get the slider values into my JSON payload?
Thx
Rich

[
    {
        "id": "6e4a0e1c3f08a293",
        "type": "debug",
        "z": "cf08cb9713ba9cda",
        "name": "debug 341",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 410,
        "y": 220,
        "wires": []
    },
    {
        "id": "49ed4223b39cd05d",
        "type": "change",
        "z": "cf08cb9713ba9cda",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"modeBrightness\" : \"{{topic}}\"}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 240,
        "y": 80,
        "wires": [
            [
                "6e4a0e1c3f08a293",
                "902ba5af9d02cea1"
            ]
        ]
    },
    {
        "id": "f77c465a8c64faee",
        "type": "ui_slider",
        "z": "cf08cb9713ba9cda",
        "name": "",
        "label": "brightness",
        "tooltip": "",
        "group": "65963440961b63cc",
        "order": 6,
        "width": 0,
        "height": 0,
        "passthru": true,
        "outs": "end",
        "topic": "topic",
        "topicType": "msg",
        "min": "0",
        "max": "255",
        "step": 1,
        "className": "",
        "x": 70,
        "y": 80,
        "wires": [
            [
                "49ed4223b39cd05d"
            ]
        ]
    },
    {
        "id": "65963440961b63cc",
        "type": "ui_group",
        "name": "HANGING LAMP",
        "tab": "f3a8a67ff0904e39",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": true,
        "className": ""
    },
    {
        "id": "f3a8a67ff0904e39",
        "type": "ui_tab",
        "name": "HOME",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

In the change node select JSONata J: not json, you can use

{"modeBrightness" :  $$.payload} 

Or use a template node, set to output js object, and you what you had minus the quotes.

{"modeBrightness" : {{payload}}} 

Or you can do it like this

image

You can't set msg.payload.modeBrightness directly as it is currently a number, so you can't add a property to it. msg.temp does not exist so the change node allows you to create it as an object, then move it into the payload.

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