[OBSOLETE] SmartThings ESP32 Multi Device (Switch, Button & Contact Sensor) With OLED or LCD for a Garage & Gate Switch


This project consists of code for an ESP32 to interface with SmartThings using the SmartThings MQTT Bridge. While any ESP32 can be used, ones with built-in displays like Heltec Wifi Kit 32, Wemos ESP32 LoLin and even the Heltec Wifi Kit 8 (ESP8266) should be considered instead. The project includes Samsung SmartThings Device Type handlers for a stateful (on/off) switch, a stateless/momentary button and a contact sensor. The project also supports a variety of temperature & humidity sensors which can be seen on all 3 device types. Two of each capabilities (switch/button/contact) can be ran on each ESP32 device.

GitHub link: GitHub - JZ-SmartThings/SmartThings-ESP32-Multi-Device

ESP32 Instructions
The *.ino file is an Arduino IDE code sample which is also compatible with MS Code Platform IO so the ino file can be renamed to cpp if desired. Verify the few options at the top of the script before flashing your device. The default settings are for a Heltec Wifi Kit 32 with a 128x64 OLED display.

SmartThings MQTT Bridge
The bridge should be configured properly well before using this code. I had to make some changes to the MQTT SmartApp in order for the Contact state, Temperature & Humidity to be written back to SmartThings. Please see the following version of the SmartApp in my fork in order to properly use Contact Sensor, Temperature Measurement & Relative Humidity capabilities. If this change is not made then none of three capabilities will sync back to SmartThings.

Direct link to the SmartApp code.

Differences between original and my pull of the SmartThings MQTT Bridge.

Displays like the OLED 128x64, 128x32 and the 2004 LCD (20 character 4 line) are all supported w/o code changes.

Temperature & Humidity
Temperature & Humidity sensors like the BME280, DHT22, DHT21, DHT11 and the built-in ESP32 temperature sensor (only on older chips, deprecated in later chips) are all supported w/o code change.

Contact Sensor
The contact sensor is read-only in SmartThings. I used a switch capability to sync with the contact state. So if desiring to use the contact sensor, please enable SWITCH sync for your device in the MQTT SmartApp otherwise it will not work.

1 Like

Updated the code and the MQTT SmartApp to make the functionality as straight forward as possible. Please make sure to use the MQTT SmartApp from my GitHub fork or some of the state changes will not make it back to SmartThings.

NEW VERSION * v1.0.20190907 - Changed MQTT SmartApp in order to sync Contact state. No longer using on/off sync workaround. Small enhancements and fixes.

Since one of my needs is an Ethernet switch in my gate (wifi not strong enough), I added support for an Arduino UNO with the W5100 Ethernet shield. Memory is VERY limited on the UNO and this is really a proof of concept to make sure the code is flexible enough to deal with wired devices. I settled on using the Ethernet library because UIPEthernet was simply to big for UNO’s memory limitations. I may opt for ENC28J60 shield but not sure.

NEW VERSION * v1.0.20190921 - Added support for a wired UNO with the W5100 Ethernet shield.

Hi JZst,

Very nice project you have there, I am really interested because I am doing a project to connect a BioGas sensor with SmartThings App (The New One).

But to be honest I am still really confused how to send the data from ESP32 using MQTT to the App. So do I need another hardware in between or I just connect to the WiFi with internet and send the data to SmartThings Cloud then program the App to fetch the data, is it right? Please enlighten me

Thank you very much in advance!

Basically this configuration requires MQTT so either you can set your own up locally using Mosquitto or similar (or a Raspberry Pi, or a VM box) or you can use a cloud service. To be honest, I have not tried the cloud service MQTT with this project. Maybe something I’ll look into when I have a chance… I guess the only thing that would theoretically need to be added to the code is MQTT username & password.

Bottom line is that the device will post either Temperature or Humidity to the MQTT server. Obviously you can re-use that with a bit of code tweaking for other purposes.