# Sonoff TH with SI7021 humidity sensor

**URL:** <https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260>\
**Category:** General\
**Created:** [24 September 2020 06:42 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260 "2020-09-24T06:42:20Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jepe63](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jepe63](https://discourse.nodered.org/u/jepe63)\
**Post date:** [24 September 2020 06:42 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/1 "2020-09-24T06:42:20Z")

</div>

Hi all,  
I've got an sonoff TH (tasmota) switch with an SI7021 temperature and humidity sensor on it  
I would like to create a node that switches the sonoff on when reaching an max humitidy so it can start a fan, and of course the other way to shut it off.  
Any pointers or sombody has the same problem?  
Thx

---

<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:** [24 September 2020 08:31 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/2 "2020-09-24T08:31:16Z")

</div>

What part don't you know how to do?

1. Read the humidity
2. Compare it with a limit
3. Switch the fan off/on

**[Edit]** If point 2 is the issue see this recent thread asking a very similar question [Front montant du signal](https://discourse.nodered.org/t/front-montant-du-signal/33145)  
Read the full thread.

---

<div class="post-metadata">

**Author:** ![jepe63](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jepe63](https://discourse.nodered.org/u/jepe63)\
**Post date:** [24 September 2020 11:06 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/3 "2020-09-24T11:06:10Z")

</div>

yes, it's indeed 1 and 2 i can see the values but don't know ho to seperate the humidity and feed it to the switch to compare

This is the msg.payload  
{"Time":"2020-09-24T12:05:24","SI7021":{"Temperature":20.1,"Humidity":61.5,"DewPoint":12.5},"TempUnit":"C"}

---

<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:** [24 September 2020 11:15 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/4 "2020-09-24T11:15:14Z")

</div>

OK, I suggest start by reading the node red docs page Working With Messages which will show you how to do it I think. Also look through the other docs there. In fact it is probably worth taking and hour out and watching the node red essentials vidoes which are linked from the docs. You will save yourself time in the long run.

Do also read the thread. If you just use a simple comparison then the fan will almost certainly switch on and off repeatedly while near the threshold due to noise on the signal.

---

<div class="post-metadata">

**Author:** ![jepe63](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jepe63](https://discourse.nodered.org/u/jepe63)\
**Post date:** [16 October 2020 15:37 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/5 "2020-10-16T15:37:23Z")

</div>

Played a little with it , this is the result of my payload  
16-10-2020 17:33:19node: PAYLOAD  
msg.payload : string[161]  
string[161]  
{  
"Time": "2020-10-16T16:33:20",  
"SI7021": {  
"Temperature": 17.3,  
"Humidity": 62.8,  
"DewPoint": 10.1  
},  
"TempUnit": "C"  
}

Wich is completely different from the example

When i try to show me the value for the humidity in the payload msg.payload.humidity it gives me an undefined error .  
Am ik missing someting here ?

---

<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:** [16 October 2020 16:01 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/6 "2020-10-16T16:01:12Z")

</div>

That is because it is a string, run it through the json node to create the javascript object. Then msg.payload.humidity will be available

---

<div class="post-metadata">

**Author:** ![jepe63](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jepe63](https://discourse.nodered.org/u/jepe63)\
**Post date:** [16 October 2020 16:29 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/7 "2020-10-16T16:29:30Z")

</div>

thx, but it's the same...

[flows (7).json](https://discourse.nodered.org/uploads/short-url/sMnKQbc21XQRgcPPhi8mWbayJk6.json) (1.1 KB)

---

<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:** [16 October 2020 16:33 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/8 "2020-10-16T16:33:22Z")

</div>

export flow to clipboard and paste the flow between backticks example below. i do not download files.  
```  
paste text here  
```

---

<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:** [16 October 2020 16:53 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/11 "2020-10-16T16:53:50Z")

</div>

Please place between backticks as asked, it provides a copy link and makes helpers life easier. And delete the other post. Messy threads are hard to read

---

<div class="post-metadata">

**Author:** ![jepe63](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jepe63](https://discourse.nodered.org/u/jepe63)\
**Post date:** [16 October 2020 16:55 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/12 "2020-10-16T16:55:34Z")

</div>

sorry newbie here, i don't understand what you mean by this 😉

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 October 2020 16:56 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/13 "2020-10-16T16:56:09Z")

</div>

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<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:** [16 October 2020 16:58 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/14 "2020-10-16T16:58:35Z")

</div>

```  
{"somecode":"with formating",["is preseved"]}  
```  
becomes this

```auto
{"somecode":"with formating",["is preseved"]}

```

and is neat and tidy, i can also copy it by just one click.

---

<div class="post-metadata">

**Author:** ![jepe63](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jepe63](https://discourse.nodered.org/u/jepe63)\
**Post date:** [16 October 2020 17:01 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/15 "2020-10-16T17:01:03Z")

</div>

```auto
[{"id":"c898090f.b95ff8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4c08d1e5.de955","type":"debug","z":"c898090f.b95ff8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.humidity","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":260,"wires":[]},{"id":"77a11fe6.eb698","type":"Tasmota Sensor","z":"c898090f.b95ff8","broker":"11f388b0.3a1d17","device":"tasmota","name":"","outputs":1,"uidisabler":false,"fullTopic":"","cmndPrefix":"","statPrefix":"","telePrefix":"","rules":[],"x":200,"y":260,"wires":[["4b2e48e1.c40808"]]},{"id":"4b2e48e1.c40808","type":"json","z":"c898090f.b95ff8","name":"","property":"payload","action":"obj","pretty":true,"x":390,"y":260,"wires":[["4c08d1e5.de955"]]},{"id":"11f388b0.3a1d17","type":"mqtt-broker","z":"","name":"Domoticz master","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"anything","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<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:** [16 October 2020 17:07 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/16 "2020-10-16T17:07:07Z")

</div>

you forgot S17021 `msg.payload.SI7021.Humidity`

```auto
[{"id":"6b248168.5c73c","type":"inject","z":"ace010cf.0ce08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"Time\": \"2020-10-16T16:33:20\", \"SI7021\": { \"Temperature\": 17.3, \"Humidity\": 62.8, \"DewPoint\": 10.1 }, \"TempUnit\": \"C\" }","payloadType":"str","x":180,"y":300,"wires":[["70888398.2fe344"]]},{"id":"70888398.2fe344","type":"json","z":"ace010cf.0ce08","name":"","property":"payload","action":"","pretty":true,"x":390,"y":260,"wires":[["e43dc9a4.f059e8"]]},{"id":"e43dc9a4.f059e8","type":"debug","z":"ace010cf.0ce08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.SI7021.Humidity","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![jepe63](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jepe63](https://discourse.nodered.org/u/jepe63)\
**Post date:** [16 October 2020 17:12 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/17 "2020-10-16T17:12:46Z")

</div>

> [@E1cid](#):
>
> msg.payload.SI7021.Humidity

Thx, working now!!!

---

<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:** [15 December 2020 17:12 UTC](https://discourse.nodered.org/t/sonoff-th-with-si7021-humidity-sensor/33260/18 "2020-12-15T17:12:47Z")

</div>

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