# Sonoff SNZB02 Data interpretation

**URL:** <https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [2 August 2022 16:17 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940 "2022-08-02T16:17:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandru89](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alexandru89](https://discourse.nodered.org/u/Alexandru89)\
**Post date:** [2 August 2022 16:17 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/1 "2022-08-02T16:17:05Z")

</div>

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}"

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 August 2022 16:24 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/2 "2022-08-02T16:24:22Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b1ec153749e3cccf6f5fdc4b62291a8ec65221c6.png)

Otherwise pass the data thru a `json` node.

---

<div class="post-metadata">

**Author:** ![Alexandru89](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alexandru89](https://discourse.nodered.org/u/Alexandru89)\
**Post date:** [2 August 2022 18:21 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/3 "2022-08-02T18:21:14Z")

</div>

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](https://www.youtube.com/watch?v=AprmCrSZXEw&t=587s)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [2 August 2022 18:46 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/4 "2022-08-02T18:46:01Z")

</div>

This is a great introduction to working with messages:

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 August 2022 19:10 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/5 "2022-08-02T19:10:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 August 2022 19:11 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/6 "2022-08-02T19:11:52Z")

</div>

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 `````)

````auto
``` 
   code goes here 
```

````

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

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). 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.

---

<div class="post-metadata">

**Author:** ![Alexandru89](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alexandru89](https://discourse.nodered.org/u/Alexandru89)\
**Post date:** [2 August 2022 19:23 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/7 "2022-08-02T19:23:57Z")

</div>

```auto
[
    {
        "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": ""
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 August 2022 19:50 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/8 "2022-08-02T19:50:29Z")

</div>

Here is an example, you can round the values using [Angular decimal pipeline](https://angular.io/api/common/DecimalPipe#usage-notes) in the gauge value format field.  
You will require Node-red Dashboard installed.

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 October 2022 19:51 UTC](https://discourse.nodered.org/t/sonoff-snzb02-data-interpretation/65940/9 "2022-10-01T19:51:08Z")

</div>

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