Sonoff SNZB02 Data interpretation

Dear community,

I want to read the information from SNZB02 temperature sensor and display all the components on different debug blocks to be able later to display them on gauges.
How can I do to split the temperature, humidity, battery and voltage if the structure of the message is this?

topic: "zigbee2mqtt/Temp"
payload: "{"battery":100,"humidity":52.31,"linkquality":174,"temperature":27.46,"voltage":3200}"

If you are using an mqtt-in node to get the data, set the 'output' option

Screen Shot 2022-08-02 at 12.23.21 PM

Otherwise pass the data thru a json node.

Hi Zenofmud,

Thanks for your reply!
Could you please provide more details about? I'm a beginner in Node-Red.
I want to do similar like in this movie but the structure of the message is different from the one that I receive. Node-Red : DHT11 on RaspberryPi - YouTube

This is a great introduction to working with messages:

https://nodered.org/docs/user-guide/messages

Did you set the output in the mqtt node to Parsed JSON?

Export your flow and attach it to a reply so we can see what you are doing.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

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.

[
    {
        "id": "93fbd86d11d1dc72",
        "type": "tab",
        "label": "Smart Home",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "236c235d1f996813",
        "type": "mqtt in",
        "z": "93fbd86d11d1dc72",
        "name": "",
        "topic": "zigbee2mqtt/Temp",
        "qos": "2",
        "datatype": "json",
        "broker": "a9414e3e953aa69a",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 330,
        "y": 140,
        "wires": [
            [
                "e9b8663077d95cd7"
            ]
        ]
    },
    {
        "id": "e9b8663077d95cd7",
        "type": "function",
        "z": "93fbd86d11d1dc72",
        "name": "",
        "func": "var t =  Math.floor(msg.payload.temperature);\n\nvar msg1 = {payload:t};\n\n\nreturn msg1;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 140,
        "wires": [
            [
                "8c7636543b5986f8"
            ]
        ]
    },
    {
        "id": "8c7636543b5986f8",
        "type": "debug",
        "z": "93fbd86d11d1dc72",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 790,
        "y": 140,
        "wires": []
    },
    {
        "id": "a9414e3e953aa69a",
        "type": "mqtt-broker",
        "name": "",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

Here is an example, you can round the values using Angular decimal pipeline in the gauge value format field.
You will require Node-red Dashboard installed.

[{"id":"236c235d1f996813","type":"mqtt in","z":"93fbd86d11d1dc72","name":"","topic":"zigbee2mqtt/Temp","qos":"2","datatype":"json","broker":"a9414e3e953aa69a","nl":false,"rap":true,"rh":0,"x":330,"y":140,"wires":[["8dd78029.351048","8c7636543b5986f8"]]},{"id":"8dd78029.351048","type":"ui_gauge","z":"93fbd86d11d1dc72","name":"","group":"2d4fe667.28f8ba","order":9,"width":0,"height":0,"gtype":"gage","title":"Temp","label":"","format":"{{msg.payload.temperature | number : 0}} °C","min":0,"max":"140","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":680,"y":160,"wires":[]},{"id":"8c7636543b5986f8","type":"debug","z":"93fbd86d11d1dc72","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":280,"wires":[]},{"id":"a695eeeb.5622a","type":"inject","z":"93fbd86d11d1dc72","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"battery\":100,\"humidity\":52.31,\"linkquality\":174,\"temperature\":27.46,\"voltage\":3200}","payloadType":"json","x":340,"y":240,"wires":[["8dd78029.351048","8c7636543b5986f8"]]},{"id":"a9414e3e953aa69a","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

You can do similar for all your other readings you wish to display in a gauge.

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