Custom SmartThing + Arduino

Derek Colley
5 min readJan 30, 2022


Build a Smartthing with Wemos D1 Mini + DHT22 temperature/humidity

Wemos D1 Mini + DHT22

I use Samsung SmartThings (ST) hub for our home automation and it serves my needs just fine. However, my home office at the end of the garden is too far for devices to be controlled from the ST hub.

So, I needed a way to add devices and connect them over http (instead of zigbee or zwave). I also feel simple devices for temperature measurement seem overly expensive for what they do.

So I decided to build my own…

Designs I rejected

  • Zigbee/ZWave Repeater — I don’t have power in the middle of the garden
  • MQTT bridge — requires MQTT server and nodejs or similar endpoint
  • Cloud API (any cloud provider) — relies on internet connection, additional cost for data

System Architecture

I prefer to have my data on a local device, so I settled on the following:

  • Wemos D1 Mini with DHT22 sensor, running ST_Anything firmware
  • Wifi connection to office Access Point
  • Local API connection to ST hub in the house

We need the ST cloud api to create the following:

  • Device Handler (get these from the ST_Anything repo, link below)
  • Device

Once these are created, all other actions happen on the ST hub and mobile app.

Top tip: make sure you’re connected to the cloud IDE for your country/region

SmartThings Cloud IDE

I found the ST UK IDE did not allow connection to GitHub, so I created the Device Handlers manually. Simply copy the code from here and create the DT’s you need. I created the following:

  • parent-st-anything-ethernet
  • child-temperature-sensor
  • child-humidity-sensor
Device Handlers in ST IDE

Wemos D1 Mini Wiring for DHT22

3vcc <= positive
GND <= negative
D2 <= signal

Arduino IDE

Copy this sketch from the ST_Anything repo

Edit as follows (this file has comments removed, please see github for original comments)

#include <SmartThingsESP8266WiFi.h>#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library#define PIN_TEMPERATUREHUMIDITY_1 D2  //SmartThings Capabilities "Temperature Measurement" and "Relative Humidity Measurement"String str_ssid     = "changeme";                                //  <---You must edit this line!String str_password = "changeme";                                //  <---You must edit this line!IPAddress ip(192, 168, 1, 123);       // Device IP Address       //  <---You must edit this line!IPAddress gateway(192, 168, 1, 254);  // Router gateway          //  <---You must edit this line!IPAddress subnet(255, 255, 255, 0);   // LAN subnet mask         //  <---You must edit this line!IPAddress dnsserver(192, 168, 1, 254);// DNS server              //  <---You must edit this line!const unsigned int serverPort = 8090; // port to run the http server on// Smartthings / Hubitat Hub TCP/IP AddressIPAddress hubIp(192, 168, 1, 10);     // smartthings/hubitat hub ip //  <---You must edit this line!// SmartThings / Hubitat Hub TCP/IP Address: UNCOMMENT line that corresponds to your hub, COMMENT the otherconst unsigned int hubPort = 39500;   // smartthings hub port//const unsigned int hubPort = 39501;   // hubitat hub portvoid callback(const String &msg) {  //Uncomment if it weould be desirable to using this function  Serial.print(F("ST_Anything_Multiples Callback: Sniffed data = "));  Serial.println(msg);}void setup() {  // this did not work, just use baud=115200 in the serial monitor  // Serial.begin(9600);  //Polling Sensors  static st::PS_TemperatureHumidity   sensor5(F("temphumid1"), 60, 40, PIN_TEMPERATUREHUMIDITY_1, st::PS_TemperatureHumidity::DHT22,"temperature1","humidity1");  st::Everything::debug=true;  st::Executor::debug=true;  st::Device::debug=true;  st::PollingSensor::debug=true;  st::InterruptSensor::debug=true;  //Initialize the optional local callback routine (safe to comment out if not desired)  st::Everything::callOnMsgSend = callback;  st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);  st::Everything::init();  st::Everything::addSensor(&sensor5);  st::Everything::initDevices();}void loop() {  st::Everything::run();}

Tip: D1 mini requires “D2” in the code above. If you try this on another board, you might need “2” as the pin number for D2 pin.

Flash the code to the board and confirm via serial monitor…

Record the MAC address

You will need the MAC address in the ST Cloud IDE later.

Serial monitor shows temp and humidity

ST Cloud IDE

Create a device in the ST Cloud IDE (remember to login to your region).

Add your MAC address in the network device Id

Type: Parent_ST_Anything_Ethernet. This parent will create children for the temperature1 and humidity1 sensors.

After initialisation, I renamed the children to suit my needs
Yes, the server room temp is a bit high…

Done! Now you can monitor and use the device as normal.

I hope that helps you. Remember to comment and clap if you found this useful.

Things you’ll need

  • Samsung SmartThings Starter Kit — the starter kit
  • Wemos D1 Mini (or similar) —this is my go-to board for any project, it has loads of memory and built-in wifi
  • DHT22 — the DHT22 provides readings with 1 decimal precision. The DHT11 will work and provides precision to 0 decimals
  • Breadboard or soldering iron — depends on your project

Disclaimer — the links above include an affiliate code for Amazon