[Sonoff Basic] Seen in the wild: Temperature sensor connected to GPIO 14

Hi2UAll!

On a work location I noticed a Sonoff Basic was used as a WiFi connected temperature sensor.

Seems to me it is connected to GPIO14. I opened the case to see how it is done, check the picture.

I do have a working Sonoff Basic connected with ESPHome and I want to try this also. Does anyone tried this?
And how do I get this working on ESPHome?

EDIT: I guess the used temperature sensor is something like a DS18B20 WTP
EDIT: Some additional info (maybe): ESP32 Dallas temperature sensor config

That is the standard way of using a sensor with a sonoff basic. But what exactly is your question? Do it the same as any other esp project.

Thank you for responding @nickrout .
I searched the Internet and the only thing I found was connecting an (extra) button to the GPIO14, so I couldn’t find any documentation which more kind of signals it can used for.

I´m just starting to explore ESP32/ESPHome and almost no experience with Arduino (just copy paste code), so I’m kind of noob at this kind of stuff…

Just curious if I’m heading into the right direction…
This is the code I’m using so far (ESPHome).

# https://esphome.io/devices/sonoff_basic.html
esphome:
  name: iot-sonoff
  platform: esp8266
  board: esp8285

# Enable logging (Default: DEBUG)
# https://esphome.io/components/logger.html?highlight=logger
logger:

# Enable Home Assistant API
# https://esphome.io/components/api.html?highlight=api%20server
api:
  password: "<MY_PASSWORD>"
  encryption:
    key: "<MY_ENCRYPTION_KEY>"
    
ota:
  password: "<MY_OTA_PASSWORD>"


wifi:
  domain: .<MY_DOMAIN>
  networks:
    ssid: <MY_SSID>
    password: <MY_SSID_PASSWORD>
    hidden: <TRUE_OR_FALSE>
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "<MY_FALLBACK_SSID>"
    password: "<MY_FALLBACK_SSID_PASSWORD>"

captive_portal:

# Webserver
# https://esphome.io/components/web_server.html?highlight=webserver
web_server:
  port: <MY_WEBSERVER_CUSTOM_PORT>
  auth:
    username: <MY_WEBSERVER_USERNAME>
    password: "<MY_WEBSERVER_PASSWORD>"
  css_include: "/config/esphome/esphome-docs/webserver-v1.min.css"
  css_url: ""
  js_include: "/config/esphome/esphome-docs/webserver-v1.min.js"
  js_url: ""
  include_internal: false

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
      inverted: true
    name: "Sonoff Basic Button"
    on_press:
      - switch.toggle: relay

# Dallas Temperature Sensor
# https://esphome.io/components/sensor/dallas.html?highlight=one%20wire
#dallas:
#  - pin: GPIO14

#sensor:
#  - platform: dallas
#    address: 0xA40000031F055028
#    name: "Sonoff Basic Temperature"

switch:
  - platform: gpio
    name: "Sonoff Basic Relay"
    pin: GPIO12
    id: relay

status_led:
  pin:
    number: GPIO13
    inverted: yes
    

The temperature Sensor is remarked, I have to solder first. So am I on the right track?

GPIO14 is a generic pin that can be used for most GPIO digital purposes (but not ADC). See ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials and bookmark it.

I also point you to Generic Sonoff — ESPHome

Your config looks OK at a glance, but you use a lot of extraneous shit that is not needed (what is al lthat stuff under the webserver setup?) Start simple, and go from there.

2 Likes

Thanks @nickrout . I have to do some reading, I guess. :wink:

BTW, the config I posted is a working config on my Sonoff Basic.

FYI the Webserver Stuff is used to have an embedded webserver just for crucial access when ESPhome/Home Assistant is not working, for some reason. the css and js files are downloaded and stored locally.

I found this datasheet of an esp8285, I don’t know for sure if it’s the chip used, but I have take a closer look.

EDIT: I still can’t figure out if a DS18B20 WTP temperature sensor will work on GPIO14. The sensor is an OneWire device.
Any idea?

will work. works for me. here is the code

dallas:
  pin: GPIO14
  update_interval: 20s
  

sensor:
 - platform: dallas
   name: "Pump1_temp"
   id: pump1_temp
   address: "0x333C01F095835628"
   accuracy_decimals: 1
   force_update: true

address: “0x333C01F095835628” Each sensor is different. You will find the address itself in the web server

1 Like

@lordzid I just soldered everything and I booted the Sonoff Basic with only the ‘dallas’-config and the address is presented! The next step I added the ‘sensor’ config and everything is working!!!
Soooo Cool! :clap:

Just some questions left:
1 - The LED is not functioning when I toggle to ON, any idea how to solve this?
2 - Will the log (debug) fill the Sonoff’s memory (and eventually) crash it?
3 - In my Home Assistant ESPHome I noticed the Sonoff sate is going to offline, and directly going online again. Is this normal for this device?

Thank you @nickrout and @lordzid for getting me there! It’s highly appreciated! :+1:

1 - It is possible to do this. These are the elementary functions that you have to do by yourself.
2 - No, it won’t, you can sleep well and not be afraid
3 - Malfunctions during operation are possible. It depends on everything.

P.S. Sonoff Basic is a very versatile device for small tasks. For example, I made a thermostat with a temperature sensor (I wrote part of the code to you above), made control of the LED strip (Adjust brightness, turn on sunset or sunrise)

Thanks for your remarks.

It seems something went wrong, temperature is showing 85 degrees, even after disconnect → connect main power:

[D][dallas.sensor:136]: 'Sonoff Basic Temperature': Got Temperature=85.0°Ce
[D][sensor:113]: 'Sonoff Basic Temperature': Sending state 85.00000 °C with 1 decimals of accuracye

:cry:

EDIT: The sensor is reporting the right values again. Seems my soldering skills were bit of decaying. Or my eyes. Or both… :wink:
Just testing a long run to see what is happening…

FYI, it’s working for a day without problems! Nice!

@lordzid @nickrout
I have problems with the onboard led I cannot figure out how to link it to the relais output. This is my config:

switch:
  - platform: gpio
    name: "Sonoff Basic Relay"
    pin: GPIO12
    id: relay

# https://esphome.io/components/light/status_led.html    
light:
  - platform: status_led
    name: "Sonoff Basic Onboard LED"
    id: onboardled
    pin:
      number: GPIO13
      inverted: yes

I tried several things but nothing worked, like (added to the switch component):

# https://esphome.io/components/switch/index.html?highlight=on_turn_on#switch-on-turn-on-off-trigger
    on_turn_on:
      then:
       - light.turn_on: onboardled
    on_turn_off:
      then:
        - light.turn_off: onboardled

When compiled and uploaded the Sonoff Basic board goes bezerk… :cry:

How can accomplish that the onboard LED will represent the relais state?

Any help would be appreciated… :+1:

No logs, no issue.

1 Like
  • platform: monochromatic