Custom SmartThing + Arduino

Wemos D1 Mini + DHT22

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
  • Device Handler (get these from the ST_Anything repo, link below)
  • Device

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

#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();}
Record the MAC address
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
After initialisation, I renamed the children to suit my needs
Yes, the server room temp is a bit high…

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



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store