Problems to "read out" mqtt Payload from DHT11

Hi, i am new here and i can´t find my fault in a Function node. I want to read out the Temperature and Huminity from a Tasmota DHT11 Client. So i use the Function node to extract the Temperature and Huminity, but it will not work !
DHT11_Function
I Used also the msg.payload = msg.payload.Temperature; but it returns The Payload is undefined.


I Used a Testflow. The Injectnode sends a Teststring like the MQTT Client.
Is anythin wrong with my Function nodes. Thank you for Support a Newbee.

[
    {
        "id": "9968598e.b88798",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": ""
    },
    {
        "id": "9b8a73f.056939",
        "type": "inject",
        "z": "9968598e.b88798",
        "name": "Simulation DHT11",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"Time\":\"2021-04-06T18:20:04\",\"DHT11\":{\"Temperature\":38.0,\"Humidity\":25.0,\"DewPoint\":14.5},\"TempUnit\":\"C\"}",
        "payloadType": "str",
        "x": 270,
        "y": 80,
        "wires": [
            [
                "bb0529ee.da3168",
                "9c81b8e8.db70d8",
                "8f7ea74e.328278"
            ]
        ]
    },
    {
        "id": "bb0529ee.da3168",
        "type": "function",
        "z": "9968598e.b88798",
        "name": "Temperature Data",
        "func": "msg.payload = msg.Temperature;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 830,
        "y": 80,
        "wires": [
            [
                "aa4b43c9.b105a"
            ]
        ]
    },
    {
        "id": "8f7ea74e.328278",
        "type": "function",
        "z": "9968598e.b88798",
        "name": "Huminity Data",
        "func": "msg.payload = msg.Huminity;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 820,
        "y": 160,
        "wires": [
            [
                "42f17627.df3c88"
            ]
        ]
    },
    {
        "id": "fc6989c3.1f0b78",
        "type": "mqtt in",
        "z": "9968598e.b88798",
        "name": "Temp/Humin DHT11",
        "topic": "Gewaechshaus/DHT11_01/SENSOR",
        "qos": "0",
        "datatype": "auto",
        "broker": "798105ff.8a59ac",
        "x": 270,
        "y": 160,
        "wires": [
            [
                "8f7ea74e.328278",
                "9c81b8e8.db70d8",
                "bb0529ee.da3168"
            ]
        ]
    },
    {
        "id": "aa4b43c9.b105a",
        "type": "debug",
        "z": "9968598e.b88798",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1090,
        "y": 80,
        "wires": []
    },
    {
        "id": "42f17627.df3c88",
        "type": "debug",
        "z": "9968598e.b88798",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1090,
        "y": 160,
        "wires": []
    },
    {
        "id": "9c81b8e8.db70d8",
        "type": "debug",
        "z": "9968598e.b88798",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 270,
        "y": 120,
        "wires": []
    },
    {
        "id": "798105ff.8a59ac",
        "type": "mqtt-broker",
        "name": "MQTT Broker",
        "broker": "192.168.120.220",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

The data you show in the debug node is a string. If you change the config of the MQTT node to output a Parsed JSON Object then it will parse the JSON string and output a javascript object, which is what you want.

Hi Colin, thank you for Support and your Patience
But when i change the Output to Parsed JSON Object my Payload shows :
{"Time":"2021-04-06T18:20:04","DHT11":{"Temperature":38,"Humidity":25,"DewPoint":14.5},"TempUnit":"C"}
The Function Node with "msg.payload = msg.Temperature;" or "msg.payload = msg.payload.Temperature;"
repeat´s
Gewaechshaus/DHT11_01/SENSOR : msg.payload : undefined

Try using msg.payload.DHT11.temperature and
msg.payload.DHT11.humidity

Thank You so much Paul, You make an old man happy.
I´ll pray for you this evening. Google is also happy less search Traffic
Juergen

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

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