Sonoff Basic + onewire ds1820b

I’m using Hass.io in a VM as I out grew a Pi. But since moving I’ve missed the onewire capabilities which I used for temperature monitoring of my heating system. I’ve since begun to re-use my Pi for an alarm interface and didn’t see it viable to dedicate an additional £30 of kit just to read some temperatures.

I had a few sonoff basic R2 devices kicking about. After some reading I managed to turn one into an interface between the onewire sensors and MQTT - thought I’d do a short write-up here.

Hardware & Requirements
Sonoff basic R2 (modified with Tasmota and a pin header, configured to connect to your MQTT broker)
4.7k resistor
X* ds1820b (only tested 2 at this time)
MQTT Broker running in HA

All in parts cost me £10.

Steps
Tasmota

  1. Configure Module: as ‘Generic (18)’
    1.1) Configure GPIO3: DS18x20 (4)
  2. Configure Logging: Telemetry Period - default is 5 minutes - I set mine to 10s to test. Then to 60s for live
  3. Reboot

Hardware

  1. Wire sensor gnd (Black) to gnd pin, 3.3v (Red) to 3.3v pin and data (Yellow) to Rx pin
  2. Connect 4.7k resistor between Red and Yellow cables

Testing

  1. Power on sonoff and use Console to check logs

HA

  1. Add sensor:
Sensor:
  - platform: mqtt
      name: "[SENSOR NAME]"
      state_topic: "tele/[MQTT_TOPIC]/SENSOR"
      unit_of_measurement: '°C'
      value_template: "{{ value_json['DS18B20']['Temperature'] }}"

If you have multiple sensors value_template is:

      value_template: "{{ value_json['DS18B20-1']['Temperature'] }}"

Next sensor is “DS18B20-2”, etc…

My config means loss of the relay and led on the sonoff, but I’m sure with some tweaking and further testing those could be brought back - they’re not needed for my purposes so I didn’t try.

Interested to know if anyone else has done similar / other approaches.

This is also easily achieved using esphome.io.