Rename the payload coming from MQTT-IN node?

Good Morning,

as Topic says, how can i rename a msg.payload to eg. msg.payload2 coming from a MQTT OUT Node ?

From a Inject Node its no Problem here can i directly rename it in the Node but in MQTT Node not.

change node...
image

Hi,

i have tried the Change Node before but gettin this Info from Debug Node:

msg.payload2 : undefined
undefined

The MQTT Message is analyzed JSON like:

{"Time":1667726362,"Switch1":"OFF","ENERGY":{"TotalStartTime":"2022-10-29T18:30:48","Total":0,"Yesterday":0.018,"Today":0.344,"Period":6,"Power":0.01,"ApparentPower":375,"ReactivePower":0,"Factor":1,"Voltage":235,"Current":0}}

Did you mean to say a MQTT-OUT node or should it have been a MQTT-IN node (like the one below)??

tasmota_energy

If you set the option in your MQTT-In node to 'a parsed JSON object' you can filter out the data you need.
For example to get the voltage value you can do this in a function node or change node...

msg.payload = msg.payload.ENERGY.Voltage;

return msg;

parse_JSON

Are you sure you specified Move in the Change node and not Set?

If you still can't get it to work then add a debug node showing what is coming out of the MQTT node and what is coming out of the function node. Give the debug nodes names and set them to Output complete message.

@dynamicdave

Yes sorry i meant MQTT-IN and yes its a parsed JSON Object

Ok
Debug from MQTT IN:

{"Time":1667813960,"Switch1":"OFF","ENERGY":{"TotalStartTime":"2022-10-29T18:30:48","Total":6.49,"Yesterday":1.818,"Today":0.068,"Period":1,"Power":37,"ApparentPower":73,"ReactivePower":63,"Factor":0.51,"Voltage":233,"Current":0.315}}

Debug from the Change Node (I set it to --> msg.payload2 to see the Data from changed payload2):

tele/tasmota_772430/SENSOR : msg.payload2 : undefined
undefined

Debug with Output complete Message at the Change Node:

{"topic":"tele/tasmota_772430/SENSOR","qos":0,"retain":false,"_msgid":"2a928136e68581cd"}

Show us how you have configured the Change node.



Here is the complete Flow of these 3 Nodes:

[
    {
        "id": "7b9af3bf34a743f2",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e4b0ff793fb1f945",
        "type": "inject",
        "z": "7b9af3bf34a743f2",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"Time\":1667726362,\"Switch1\":\"OFF\",\"ENERGY\":{\"TotalStartTime\":\"2022-10-29T18:30:48\",\"Total\":0,\"Yesterday\":0.018,\"Today\":0.344,\"Period\":6,\"Power\":0.01,\"ApparentPower\":375,\"ReactivePower\":0,\"Factor\":1,\"Voltage\":235,\"Current\":0}}",
        "payloadType": "json",
        "x": 450,
        "y": 180,
        "wires": [
            [
                "94071c8fcaf238e4"
            ]
        ]
    },
    {
        "id": "94071c8fcaf238e4",
        "type": "change",
        "z": "7b9af3bf34a743f2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload2",
                "tot": "msg",
                "dc": true
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 670,
        "y": 180,
        "wires": [
            [
                "7caf94504c0e21b3"
            ]
        ]
    },
    {
        "id": "7caf94504c0e21b3",
        "type": "debug",
        "z": "7b9af3bf34a743f2",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload2",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 960,
        "y": 180,
        "wires": []
    }
]

The change node can sometimes be a little confusing, when you "set" a property, think of it like:
create new property: msg.payload2 and get the value from msg.payload

so you have to switch them around.

As I said in my earlier post

1 Like

Thats the Solution, thanks Colin.

I must have read it again.

Move Mode did the work :grinning:

1 Like

Hope you don't mind.
I've edited the title of your post to help people who might search for this topic/issue in the future.

Yes, that's great, thanks everyone

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