ESP8266, DS18B20, to emoncms

I have read with interest some of the emontx4 post regarding temperature measurement, as I had always wondered how the system coped with the close timing of the ( not so now ) cheap and cheerful DS18B20 and still capturing A/D updates from the CT’s. (Yes I did read the error was relatively low with 6 CT’s,… but not recommended for greater than 6 CT’s ).
With this in mind I have checked around to see what offerings are available for simple ESP8266 units with DS18B20 logging to emoncms. I have found several options,… the best ( IMHO ) I found was some code written back in 2017 by Stuart Pitaway.

I have attempted to upload this to nodemcu,… but compile fails as the code for JSON has changed from V5 to V6,… as it would appear things are enumerated/formatted slightly differently,. I had started to change to code,. to make it V6 compliant,… but it then occurred as this original code was written back in 2017, is the output still compliant with the latest version of emoncms,… not to mention my JSON knowledge experience is very limited,… so making changes is a new adventure.
So I was wondering has anything materialised from within the ‘Welsh hills’, as I believe I read the ‘team’ was going to develop a template ESP8266 module to ‘off-load’ temperature sampling…
Or has any other like minded soul have some code they have developed…
I await with baited breath…
KR and tx to all at the openenergy community.

The present thinking is to use the emonBase - a.k.a. Raspberry Pi - to handle temperatures. Don’t count me as a RPi expert, but I’d have expected even the lowest-powered WiFi RPi would work nicely, and there’d be commonality between this and the (new) emonPi, making support that much easier and better.

Raspberry Pico seems to be a similiar price to a nodemcu board,… although I to have not dabbled with a Pi-pico,… I guess there must be a IDE interface and libraries and all that stuff out there,… support via arduino IDE and or VS…
Arduino seems to have it on its list,…

Yes So I’m game to use a Pi pico with WiFi…

I think if you search the forum, you’ll find a few examples. I have 6 DS18B20s attached to a sonoff TH unit running code that is a cut down version of MartinR’s diverter sketch which had DS18B20 support.

It’s late, so I’m not going to try to find it now but I’ll try to find the sketch tomorrow and post it here.


From the ‘Learn’ page about MartinR’s PLL diverter:

8: The Sketch Explained in Detail.
The version described was published at Solar PV power diversion with emonTx, emonGLCD and temperature measurement | Archived Forum and can be downloaded from

Mark hi,

My starting point was the code from MartinR but really it was only the timing loops for reading the sensors and sending the data. From memory, his code uses interrupts to manage this so that it doesn’t trip up the main code to read the CTs and control the triac for the diverter. On an ESP8266 without the diverter, you can use the Ticker library to effectively set up the triggers to read the DS18B20s and to do the send of the data to emoncms and MQTT.

I can send you my code (pretty messy) to do this but it’s very specific to managing my backup boiler and heat bank.

Thinking abut things this morning though, why don’t you use Tasmota or ESPHome. There are several threads on here about getting Tasmota to send data to emoncms for example → Tasmota integration with EmonCMS Input REST API.

It might be easier to go down this route with MQTT and node-red than to create your own code.

But, as I said, I can send you my code if that’s your preferred route. I’d also stick with an ESP8266 rather than a pico, mainly because there’s lots of information and experience with using the ESP devices to read DS18B20s.


Personally, I use a WEMOS D1 Mini connected to 6 DS18B20 and use Tasmota. It just works. There was a post this week about using the scripting to send the values in an emoncms format directly, but I use Node-RED to translate it to something emoncms understands.

Absolutely rock solid and very easy to do.

As a bonus, HomeAssistant picks up the data as well.

Hi, posting from the opposite corner of Europe where solar water heaters on the roof are very common. I’m monitoring ambient, solar panel in / out and tank temperatures. Agree with borpin above, basic ESP32 running Tasmota, multiple ds18b20s sending MQTT and node-red sending the data on to a local Emoncms instance. Monitor runs from a small PV panel and a car battery, ESP32 analogue input monitors the battery voltage. Only problem is the hot water gets too hot - can be 65C through the summer months.

Well,… some definite food for thought as they say,… The Home assistant route seems to be and interesting option,… I played with HA, last year on an old i3 laptop with a ‘bust’ screen,… but have now created a HA install on a Pi 4, and the nodemcu’s I was using with some motion detection, I can immediately re-purpose as my required Temperature sensors… All I have to do now is get my head around the in’s and out’s of YAML again,… and tie in the integrations… But it does look neat…
thanks to all for their comments

Are there any articles relating to the Node Red setup?,… Have got myself a HA - Raspberry Pi running,… and displaying temperatures from a remote node, just need some pointers on the Node Red stuff, formatting etc.
Many Tx

Are you saying you have the sensors setup and HA is receiving the data? If so, use the HA emoncms component to send the data to your emoncms instance. It is the simplest way.

Yes,… I will see what emoncms add-on has to offer in HA… Thanks for the feedback

So… not really answering your question directly (and I think you will probably have to become friends with JSON :-), but:-
I would look at using the SHT40 rather than the DS18B20 and having only 1 sensor per ESP8266. I mean to say to consider a different architecture. THe 1-wire device is quite nice if you want to have one MCU and a string of temperature sensors attached, but if multiple independent units is a better fit for your scenario then an I2C device is easier to work with IMO. THe SHT40 also reads humidity and there is an arduino library from the manufacturer.

I have several of these in operation, including two outside on battery power (one in the greenhouse). If you use the ESP8266 “deep sleep” and only wake up every 5 or 15 minutes then one 18650 LiPo cell will last a sensibly long time. I send the readings (formatted as JSON!) to my emonpi MQTT broker. I think that is also a helpful approach in general, and very much in the “IoT” model of thinking, where you keep the things at the edges light-weight. The Rpi in the EmonPi is quite able to cope with more MQTT traffic and MQTT is a natural integration point for other services. If you want the temp/humidity data to appear in EmonCMS, you just need to name the MQTT topic appropriately (see: Using MQTT in Open Energy Monitor to Capture External Device Data – Adam @ Hilltop Cottage). Alternatively, you can just use any [other] MQTT topic name and monitor the messages using something like MQTT-Explorer. This won’t upset your OEM/EmonCMS!

Whichever direction you go, I suspect you’ll need to spend time learning stuff. I think becoming familiar with MQTT and JSON will open doors!

Cheers, and good luck!

Assuming that reading humidity is required. I don’t need it for reading the water temps in my tank. It also makes the setup significantly more expensive. Hooking 8 sensors to a single WEMOS D1 Mini and then using Tasmota to read them is simple, robust, and cheap :slight_smile: .

Hi Brian, I am reading temperatures in HA, and I believe exporting them via

  api_key: !secret emoncms_RWapi_key
  url: https://692.468.9.356/emoncms     -- Address edited
  inputnode: 95
    - sensor.tasone_ds18b20_1_temperature
    - sensor.tasone_ds18b20_2_temperature

I have tried creating a device, for input node 95, with the hope it would appear as a feed or input, but as yet to no avail, and my search for HA history to emoncms only shows the HA side of things,… and as far as I can tell not the emonpicms side setup,… are you able to enlighten me as to the emonpicms setup. ( assuming the HA is setup correctly ).
Many tx

Interesting Adam,… Are you able to share the code that you use in your ESP8266…
Many Tx

The data should just appear on the Inputs Page under ‘95’ Node. Have you checked both HA and emoncms logs?

URL might not need the ‘emoncms’ part.

TBH I don’t use it, I use the Node-RED addon and fire it via MQTT :slight_smile:

Ah yes,… logs,… it would seem I’m not actually sending data yet as it fails to write, the ‘emoncms’ inm the url does seem to be unnecessary,… I have tried ‘http:…’ and ‘https:…’ neither work
error logs as follows:-

2023-06-20 12:11:40.714 ERROR (SyncWorker_8) [homeassistant.components.emoncms_history] Error saving data {sensor.tasone_ds18b20_1_temperature:24.1,sensor.tasone_ds18b20_2_temperature:23.1} to (http status code = 401)
2023-06-20 12:11:50.721 ERROR (SyncWorker_2) [homeassistant.components.emoncms_history] Error saving data {sensor.tasone_ds18b20_1_temperature:24.1,sensor.tasone_ds18b20_2_temperature:23.1} to (http status code = 401)
2023-06-20 12:12:00.719 ERROR (SyncWorker_2) [homeassistant.components.emoncms_history] Error saving data {sensor.tasone_ds18b20_1_temperature:24.1,sensor.tasone_ds18b20_2_temperature:23.1} to (http status code = 401)
2023-06-20 12:12:10.715 ERROR (SyncWorker_3) [homeassistant.components.emoncms_history] Error saving data {sensor.tasone_ds18b20_1_temperature:24.1,sensor.tasone_ds18b20_2_temperature:23.1} to (http status code = 401)

my configuration .yaml is as follows, and my RW-key is as cut and pasted from my emonpi ‘My Account’ screen… and not the read only key…

# Example configuration.yaml entry
  api_key: emoncms_RWapi_key
  scan_interval: 10
  inputnode: 95
    - sensor.tasone_ds18b20_1_temperature
    - sensor.tasone_ds18b20_2_temperature

Don’t you need to do !secret emoncms_RWapi_key?
p.s. mine works okay with just http.
p.p.s. I don’t use !secret with mine - just the API key

Yes,… your quite correct,… missing the obvious…
a !secrets 39854kdjhgfkjdhkjhgkdjhgkjh3c
was all it needed and feed as noted previously just appears as an input with the respective node_ID as given in HA.
Thanks guys…

1 Like