# MQTT - DS18B20 Sensors and Rules Question

**URL:** https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572
**Category:** General
**Created:** [4 July 2023 09:14 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572 "2023-07-04T09:14:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 09:14 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/1 "2023-07-04T09:14:35Z")

</div>

Hi  
I have an ESP12 board with a pair of DS18B20 temperature sensors on GPIO2 - the MQTT input node returns an object including names DS18B20-1 and DS18B20-2 which I cannot seem to extract to get values out.

I noted on the web someone published a rule, slightly modified here but you get the idea.

Rule1 on DS18B20-1#temperature do publish stat/mosfet/DS18B20a %value% endon on DS18B20-2#temperature do publish stat/mosfet/DS18B20b %value% endon  
Rule1 1

It works - I can extract DS18B20a and DS18B20b and get their temperature values but the MQTT input node insists on pulling in data every second (no idea why) so I end up having to use rate limiting (delay node).

Any ideas as to a better way? I only need to read the temperature once a minute at most.. standard TELE response rates would be fine.

---

<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: [4 July 2023 09:31 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/2 "2023-07-04T09:31:33Z")

</div>

> [@scargill](#):
>
> the MQTT input node insists on pulling in data every second

No it doesn't. The MQTT In node does not pull data, it gets pushed data from the mqtt broker. If the MQTT In node is giving you data every second then the publisher if publishing data at that rate, so you should fix it at that end. If you do not believe this is the case then install MQTT Explorer to check.

---

<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: [4 July 2023 09:51 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/3 "2023-07-04T09:51:13Z")

</div>

In addition, MQTT Explorer will let you see what else is being published by the device, which may be useful to you.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [4 July 2023 09:59 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/4 "2023-07-04T09:59:07Z")

</div>

It looks as if you might be using ESPeasy firmware on the ESP12.  
If so, you can specify how often to send readings by setting a value for 'Interval' in the 'Devices tab'...

 ![a_DS18b20_v2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abeb22cb259b5ebf41cbb999e10b82a8f2f56ba6.png)  
This method doesn't use any rules, just sends the reading(s) via MQTT controller every 60-sec.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [4 July 2023 10:10 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/5 "2023-07-04T10:10:05Z")

</div>

> [@dynamicdave](#):
>
> It sounds as if you might be using ESPeasy firmware on the ESP12.

Or perhaps it's Tasmota, which has very similar Rules syntax.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [4 July 2023 10:59 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/6 "2023-07-04T10:59:29Z")

</div>

On the OP's blog there is what appears to be some background to this question.

You seem to be using Rules (inappropriately) to retrieve sensor data because your sensor names contain a hyphen:

> Well, NO. You can’t extract “DS18B20-1” because it gets treated like an expression – and you can’t put quotes around that either.

Have you tried square bracket notation _and_ quotes? `msg.payload.StatusSNS["DS18820-1"].Temperature`

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 11:45 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/7 "2023-07-04T11:45:24Z")

</div>

Nope – I’m using a fully updated Tasmota.

Pete

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 11:46 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/8 "2023-07-04T11:46:19Z")

</div>

No. Trying that right now...

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 12:13 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/9 "2023-07-04T12:13:17Z")

</div>

RIGHT - and for anyone falling into the same trap.... in the case of my "mosfet" device the MQTT in needs to be:

stat/mosfet/STATUS10  
returning a PARSED JSON OBJECT

The FUNCTION to read the first sensor is:

msg.payload=msg.payload.StatusSNS["DS18B20-1"].Temperature  
return msg;

Thank you jbudd. Perfect.

To get that response I'm injecting topic:  
cmnd/mosfet/STATUS  
and payload 10

every 30 seconds  
I could have waited for TELE I guess but this'll do for now.

---

<div class="post-metadata">

### Author: ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)
#### Post date: [4 July 2023 12:19 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/10 "2023-07-04T12:19:31Z")

</div>

@scargill [SetOption64](https://tasmota.github.io/docs/Commands/#setoption64) can be used to switch from default.legacy `_` instead of `-` in JSON keys  
The default to use `-` is an unfortunate choice but it was decided not to break what was existing and offer the ability to change it by choice.

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 13:49 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/11 "2023-07-04T13:49:03Z")

</div>

Thanks - the brackets-quotes solution works a treat. I am however using a cmnd to get a stat reading back - and though it works prefectly and I need to do it that way, I'm wondering what I was doing wrong with my TELE MQTT input as after a few minutes I wasn't seeing anything... I thought tele/mosfet/sensor would do it - but nothing.

---

<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: [4 July 2023 14:01 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/12 "2023-07-04T14:01:53Z")

</div>

What topics is MQTT Explorer showing?

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 14:02 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/13 "2023-07-04T14:02:32Z")

</div>

Didnt try - didnt need to - see solutions above...

---

<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: [4 July 2023 14:14 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/14 "2023-07-04T14:14:19Z")

</div>

You said you wanted to know why you were not seeing the TELE messages. Explorer should show you the topic.

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 14:49 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/15 "2023-07-04T14:49:24Z")

</div>

Oh I seee - yes I'll look ta... though in the end I need more control than the tele message will give. Got to turn the pump on if it's not cold, wait a bit to find out if the hot pipe is warmer than the cold pipe, then keep the pump on if it is.... until it isn't 🙂

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [4 July 2023 15:48 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/16 "2023-07-04T15:48:55Z")

</div>

Also see TelePeriod

> TelePeriod See current value and force publish STATE and SENSOR message  
> `0` = disable telemetry messages  
> `1` = reset telemetry period to firmware default (`TELE_PERIOD`)  
> `10..3600` = set telemetry period in seconds _(default = `300`)_

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [4 July 2023 22:21 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/17 "2023-07-04T22:21:07Z")

</div>

Ok, I'm lost - I have MQTT Explorer running in Windows - and I juat had it send tele/mosfet/TelePeriod with a value of 30

The program is subscribed to tele/mosfet

yet looking at what's happening I can see my command was accepted but no tele events are recorded.. It is now 00:42 on 5th,

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cd0e19716b51cdef152b40967127cebb24f8ca90.png)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [4 July 2023 22:51 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/18 "2023-07-04T22:51:28Z")

</div>

> [@scargill](#):
>
> I just had it send tele/mosfet/TelePeriod with a value of 30

TelePeriod is a _command_.  
EIther enter it directly in the web console or via MQTT: topic **cmnd/\<blah/blah\>/TelePeriod** and payload **30**

Note commands are not case sensitive. **teleperiod** works too.

Edit: (Not relevant, scrubbed)

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [5 July 2023 00:20 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/19 "2023-07-05T00:20:36Z")

</div>

Yes I just realised it was a command cmnd and ignore the time comment - the time setting was miles out.....

---

<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: [3 September 2023 00:21 UTC](https://discourse.nodered.org/t/mqtt-ds18b20-sensors-and-rules-question/79572/20 "2023-09-03T00:21:26Z")

</div>

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