Sonoff TH Origin 16A Switch (THR316) with DS18B20

Hi!

I’ve just set up Sonoff TH Origin 16A Switch (THR316) through esphome, works like a charm except the Dallas DS18B20 sensor (new RJ9 jack)

image
https://itead.cc/product/sonoff-th/ref/3/
image
https://itead.cc/product/sonoff-ds18b20/?attribute_pa_jack-type=rj9-4p4c

Everything is working (button/relay/leds) except the dallas sensor. It should be GPIO25 according to blakadders table https://templates.blakadder.com/sonoff_THR316.html

Logs:

Yaml (relevant part):

esphome:
  name: sonoff-th-r3-16

esp32:
  board: nodemcu-32s

# Enable logging
logger:
  level: VERBOSE

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:

dallas:
  - pin: GPIO25

Would appreciate any ideas, as I’m out of them atm. The guys over here https://github.com/arendst/Tasmota/issues/15856 managed to get it working with Tasmota (it’s a huge thread discussing other models and not just TH16R3)

I’m seeing exactly the same behaviour with a Sonoff THR320 (TH Origin 20A) and ESPHome 2022.10.2.

dallas:
  - pin: GPIO25
    update_interval: 10s

I’ve switched over to Tasmota for the time being to get the dallas sensor working but I think I’ve pontentionally found a solution for esphome:

Seems GPIO27 need to be pulled high to get the sensor working.

Appreciate a heads up if you get it working :slight_smile:

This config finally worked for me but not without some unexplainable behaviour of working then not working.

Not sure if it helped or just coincidence but ‘Clean Build Files’ seemed to make a difference.

switch:
  - platform: gpio
    pin: 27
    id: dallas_power
    restore_mode: ALWAYS_ON

dallas:
  - pin: 25

This is a above my pay grade… assume this is the bigger problem: Possible fix for slow pin mode on Arduino >= 2.0.3 by jenscski · Pull Request #3998 · esphome/esphome · GitHub

Seems to work ok for Tasmota but not working correctly for ESPHome.

And obviously only ESP32 and does seem once you have defined the sensor address it seems to remain stable.

Interesting, hopefully resolved soon

Hi, which Tasmota binary did you use? the standard or the sensors?
Thanks!

I am having a similar issue with the Sonoff THR316 Origin and the WTS01 sensor. They are both sold as a bundle from Sonoff, and the sensor attaches to the sonoff via a 4-pin RJ9 connection.
Over the past few days I tried many solutions I could find online and I am unable to get the sensor to work with ESPhome and to report any temperature values.

ESPhome (version 2024.9.1) always gives me the error: [gpio.one_wire:078]: Found no devices!

I did manage to get the sensor working on Tasmota, selecting the GPIO25 as a SSerBr Tx and typing the SSerialMode 3 in the console. As advised in this thread: arendst/Tasmota#19373 (comment)

I basically took the default recommended config from Sonoff THR316 | devices.esphome.io and adjusted it for ESPhome 2024.9.1. Since that did not work, I added some debugging code when trying to troubleshoot, however this did not get me far. I am hoping some wiser people can help me out here.

Here is my ESPhome config for reference, where the sensor is not working:

# Sonoff THR316 Smart Temperature and Humidity Monitoring Switch
# Assumes that a DS18B20 temperature sensor is connected
substitutions:
  friendly_name: "2-Boiler"
  name: 2-boiler

esphome:
  name: $name
  on_boot:
    - priority: 90
      then:
      # supply the external sensor with 3v power by pulling this GPIO high
      - switch.turn_on: sensor_power
      # Make sure the relay is in a known state at startup
      - switch.turn_off: relay
      # Default to running the climate control in Home mode
#      - climate.control:
#          id: climate_control
#          preset: "Home"

esp32:
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name} Fallback Hotspot"
    password: "1234567890"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  - platform: esphome

#optional
web_server:
  port: 80

time:
  - platform: homeassistant
    id: homeassistant_time

sensor:
  - platform: wifi_signal
    name: $friendly_name Wifi RSSI
    update_interval: 60s

  - platform: uptime
    id: uptime_sensor
    internal: True
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

  - platform: template
    name: $friendly_name ESP32 Internal Temp
    device_class: temperature
    unit_of_measurement: °C
    id: esp32_temp
    lambda: return temperatureRead();

  # External DS18B20 Digital Temperature Sensor
#  - platform: dallas_temp
#    name: $friendly_name Temperature
#    id: temp
#    update_interval: 10s

switch:
  - platform: gpio
    name: $friendly_name
    pin: GPIO21
    id: relay
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
      - delay: 500ms
      - light.turn_on: switch_led
    on_turn_off:
      - delay: 500ms
      - light.turn_off: switch_led
  - platform: restart
    name: $friendly_name Restart

  # This is needed to power the external sensor.
  # It receives 3v3 from this pin, which is pulled up on boot.
  - platform: gpio
    pin: 27
    id: sensor_power
    restore_mode: ALWAYS_ON

text_sensor:
  - platform: template
    name: $friendly_name Uptime
    id: uptime_human
    icon: mdi:clock-start
  - platform: wifi_info
    ip_address:
      name: $friendly_name IP
    ssid:
      name: $friendly_name SSID
    bssid:
      name: $friendly_name BSSID


light:
  - platform: status_led
    id: switch_led
    internal: True
    pin:
      number: GPIO16
      inverted: True
  - platform: status_led
    id: wifi_status_led
    internal: True
    pin:
      number: GPIO15
      inverted: True
  - platform: status_led
    id: auto_led
    internal: True
    pin:
      number: GPIO13
      inverted: True

interval:
  - interval: 30s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - light.turn_on: wifi_status_led
        else:
          - light.turn_off: wifi_status_led

# DS18B20 Digital Temperature Sensor Hub
one_wire:
  - platform: gpio
    pin: 25
    id: dallas

button:
  - platform: template
    name: Test 1-wire bus
    on_press:
     - lambda: |-
        id(dallas).search();
        id(dallas).dump_config();

Any advice on how to resolve this, please?