[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

smartthings esp8266 servo.
I’m using a WeMos D1 CH340 WiFi Arduino UNO R3 Development Board ESP8266 ESP-12F.
Can help me with the code?

I do not have any servo motors to even try. I would recommend you take a look at the numerous ESP8266/Servo solutions that already exist for controlling blinds. These solutions should provide you with almost exactly what you need.

Here is one such example:

#include <Servo.h>

Servo servo;

void setup() {
  servo.attach(4);  //D4
  //servo.write(0);
  //delay(2000);
  servo.write(180);
  delay(5000);
  servo.write(0);
  delay(5000);
}
void loop() {  
}

Now how do use it in smartthings?
I’m new to coding.

f you’re not a programmer, I would recommend you either buy ready to run Smart Vents (e.g. Keen smart vents), or find a programmer that is willing to help you with your project. You may need to be willing to pay a programmer if you can’t find a volunteer. This is not something I am willing to take on.

Perhaps you could ask the Smart Blinds programmers to assist you. After all, a smart vent is just a smaller version of a smart blind. They may simply add a smart vent option to their smart blinds project.

You need a 12v power supply and some MOSFETs which will act as the interface from the low voltage arduino board to your 12v LEDs. You have to be careful about which ones you buy, there’s all kinds of fun stuff to look at like gate threshold values and voltage differentials, etc. I initially bought some that said they would work with Arduino but it ended up not working for my esp32 because it only outputs 3 volts as opposed to 5 volts and it wasn’t enough to switch the mosfets. These worked for me and should work for you:

Https://www.amazon.com/N-Channel-Power-Mosfet-RFP30N06LE-220/dp/B071Z98SRG

You will need one per color per strand. So if you using the rgbw strip you’ll need 4 per strip. And here is how to wire it:

2 Likes

So I think followed the wiki directions properly. I have a NodeMCU v1.0. It’s connecting to the network and I can ping it. I’ve added the device in the smartthings IDE, but I never get prompted for a configuration. I can do it manually in the SmartThings Classic app, or in the IDE, but it still never connect to my hub.

Any suggestions on what I might be missing?

You have to configure the Parent Device’s settings correctly in the classic app.

The three critical things for data transfer from your ST_Anything device to ST are:

Sketch

  1. IP Address of the ST Hub
  2. Port of the ST Hub (must be 39500)

ST Mobile Application

  1. Parent Ethernet Device’s Settings - MAC Address of your NodeMCU, all uppercase, no delimiters (available from the Arduino IDE Serial Monitor when when your NodeMCU boots)

The critical things for data transfer from ST to your ST_Anything device are:

ST Mobile Application

  1. Parent Ethernet Device’s Settings
    a) IP Address of your NodeMCU (available from the Arduino IDE Serial Monitor when when your NodeMCU boots)
    b) Port of your NodeMCU (available from the Arduino IDE Serial Monitor when when your NodeMCU boots)

After setting these parameters up in the ST Mobile App, be sure to click DONE. Behind the scenes some settings are taken care of and a REFRESH command is sent to your NodeMCU. You should see the REFRESH command in your Arduino Serial Monitor window.

1 Like

Well this is embarrassing: I hadn’t properly published all of my device handlers. Everything seems to work now. :slight_smile:

1 Like

Servo starts at zero and then when on button is pressed in SmartThings app Servo will turn to 180.
Then when off button is pressed then Servo will turn to 0.

I’m useing a WeMos D1 CH340 WiFi Arduino UNO R3 Development Board ESP8266.

ST_Anything_ESP8266WiFi loaded on it but but that all I can get.

What I’m not understanding is how to make ST_Anything_ESP8266WiFi talk. To see if SmartThings and is if SmartThings sending commands back?

Thanks VSeven I’ve bought some of those and they’re on their way, thanks for your help.

2d

My question is about linking my temperature sensing one with a 2 x 16 display so that it will show the temps.

Dan,

The simplest place to update a locally attached LCD display would be inside the sketch’s ‘callback()’ function. Simply uncomment the first two print statements and monitor the output within the Arduino IDE’s Serial Monitor Window. You should see your temperatures show up every time they send data to ST.

The string that is sent to ST is what is passed into the callback(string) function. Your updates should appear as “temperature1 76.8”, “temperature2 83.5”, etc…
You can then easily parse these strings into the name and value portions. Then, simply update your LCD screen with the data. Something like:

pseudo code
If (name == “temperature1”) {
updateLCD("Garage Temp = " + value)
}
If (name == “temperature2”) {
updateLCD("Attic Temp = " + value)
}

You get the idea… Hope this helps!

Thanks very much, I have tested my display with this simple code which works:

#include <Wire.h> // This library is already built in to the Arduino IDE
#include <LiquidCrystal_I2C.h> //This library you can add via Include Library > Manage Library >
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
Wire.begin(2,0);
lcd.init(); // initializing the LCD
lcd.backlight(); // Enable or Turn On the backlight
lcd.print(" Hello World "); // Start Printing
}

void loop()
{
// Nothing Absolutely Nothing!
}

And I have added your code to the area in my sketch as you suggested but its become clearer than ever that I don’t know what I’m doing as it doesn’t work. I commented out two switches which I thought would “free up” D3 and D4 for the display to use, I couldn’t see how D3 and D4 were defined in the sample hellow world display sketch so assumed something in the display library file defaulted to those pins?

Here is my code:

#include <SmartThingsESP8266WiFi.h>

//******************************************************************************************
// ST_Anything Library
//******************************************************************************************
#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 <Wire.h> // This library is already built in to the Arduino IDE
#include <LiquidCrystal_I2C.h> //This library you can add via Include Library > Manage Library >
LiquidCrystal_I2C lcd(0x27, 16, 2);

//#include <PS_Illuminance.h> //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

//#include <PS_TemperatureHumidity.h> //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h> //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries
#include <PS_Water.h> //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <IS_Motion.h> //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
//#include <IS_Smoke.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h> //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
// #include <IS_Button.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h> //Implements an Executor (EX) via a digital output to a relay
//#include <EX_Alarm.h> //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
//#include <S_TimedRelay.h> //Implements a Sensor to control a digital output pin with timing capabilities

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
//#define LED_BUILTIN 16
//#define BUILTIN_LED 16
//
//#define D0 16 //no internal pullup resistor
//#define D1 5
//#define D2 4
//#define D3 0 //must not be pulled low during power on/reset, toggles value during boot
//#define D4 2 //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15 //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_WATER_1 A0 //NodeMCU ESP8266 only has one Analog Input Pin ‘A0’

//#define PIN_ALARM_1 D0 //SmartThings Capabilty “Alarm”
#define PIN_SWITCH_1 D1 //SmartThings Capability “Switch”
//#define PIN_SWITCH_2 D4 //SmartThings Capability “Switch”
//#define PIN_SWITCH_3 D3 //SmartThings Capability “Switch”
#define PIN_SWITCH_4 D6 //SmartThings Capability “Switch”
#define PIN_CONTACT_1 D2 //SmartThings Capabilty “Contact Sensor”

#define PIN_MOTION_1 D5 //SmartThings Capabilty “Motion Sensor” (HC-SR501 PIR Sensor)
#define PIN_TEMPERATURE_1 D7 //SmartThings Capabilty “Temperature Measurement” (Dallas Semiconductor DS18B20)

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid = “"; // <—You must edit this line!
String str_password = "
*”; // <—You must edit this line!
IPAddress ip(192, 168, 1, 203); //Device IP Address // <—You must edit this line!
IPAddress gateway(192, 168, 1, 1); //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, 1); //DNS server // <—You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
IPAddress hubIp(192, 168, 1, 100); // smartthings hub ip // <—You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine. This is a sniffer to monitor
// data being sent to ST. This allows a user to act on data changes locally within the
// Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
Serial.print(F("ST_Anything Callback: Sniffed data = "));
Serial.println(msg);
If (name == “temperature1”) {
updateLCD("Outdoor Temp = " + value)
}

//TODO: Add local logic here to take action when a device’s value/state is changed

//Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
//st::receiveSmartString(“Put your command here!”); //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding “tile” defined in your
// SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
// - For details on each device’s constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// Device Handler names. (Note: “temphumid” below is the exception to this rule
// as the DHT sensors produce both “temperature” and “humidity”. Data from that
// particular sensor is sent to the ST Hub in two separate updates, one for
// “temperature” and one for “humidity”)
// - The new Composite Device Handler is comprised of a Parent DH and various Child
// DH’s. The names used below MUST not be changed for the Automatic Creation of
// child devices to work properly. Simply increment the number by +1 for each duplicate
// device (e.g. contact1, contact2, contact3, etc…) You can rename the Child Devices
// to match your specific use case in the ST Phone Application.
//******************************************************************************************
//Polling Sensors
static st::PS_Water sensor1(F(“water1”), 60, 20, PIN_WATER_1, 200);
static st::PS_DS18B20_Temperature sensor2(F(“temperature”), 15, 0, PIN_TEMPERATURE_1, true, 10, 5);
//Interrupt Sensors
static st::IS_Contact sensor3(F(“contact1”), PIN_CONTACT_1, LOW, true);
// static st::IS_Button sensor4(F(“button1”), PIN_BUTTON_1, 1000, LOW, true, 500);
// static st::IS_Button sensor5(F(“button2”), PIN_BUTTON_2, 1000, LOW, true, 500);
static st::IS_Motion sensor4(F(“motion1”), PIN_MOTION_1, HIGH, false);
// static st::IS_Smoke sensor7(F(“smoke1”), PIN_SMOKE_1, HIGH, true, 500);

//Special sensors/executors (uses portions of both polling and executor classes)
// static st::S_TimedRelay sensor8(F(“relaySwitch1”), PIN_TIMEDRELAY_1, LOW, false, 3000, 0, 1);

//Executors
static st::EX_Switch executor1(F(“switch1”), PIN_SWITCH_1, LOW, true); //Inverted logic for “Active Low” Relay Board
static st::EX_Switch executor2(F(“switch2”), PIN_SWITCH_2, LOW, true); //Inverted logic for “Active Low” Relay Board
static st::EX_Switch executor3(F(“switch3”), PIN_SWITCH_3, LOW, true); //Inverted logic for “Active Low” Relay Board
static st::EX_Switch executor4(F(“switch4”), PIN_SWITCH_4, LOW, true); //Inverted logic for “Active Low” Relay Board

//*****************************************************************************
// Configure debug print output from each main class
// -Note: Set these to “false” if using Hardware Serial on pins 0 & 1
// to prevent communication conflicts with the ST Shield communications
//*****************************************************************************
st::Everything::debug=true;
st::Executor::debug=true;
st::Device::debug=true;
st::PollingSensor::debug=true;
st::InterruptSensor::debug=true;

//*****************************************************************************
//Initialize the “Everything” Class
//*****************************************************************************

//Initialize the optional local callback routine (safe to comment out if not desired)
st::Everything::callOnMsgSend = callback;

//Create the SmartThings ESP8266WiFi Communications Object
//STATIC IP Assignment - Recommended
st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);

//DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
//st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

//Run the Everything class’ init() routine which establishes WiFi communications with SmartThings Hub
st::Everything::init();

//*****************************************************************************
//Add each sensor to the “Everything” Class
//*****************************************************************************
st::Everything::addSensor(&sensor1);
st::Everything::addSensor(&sensor2);
st::Everything::addSensor(&sensor3);
st::Everything::addSensor(&sensor4);

//*****************************************************************************
//Add each executor to the “Everything” Class
//*****************************************************************************
st::Everything::addExecutor(&executor1);
st::Everything::addExecutor(&executor2);
st::Everything::addExecutor(&executor3);
st::Everything::addExecutor(&executor4);

//*****************************************************************************
//Initialize each of the devices which were added to the Everything Class
//*****************************************************************************
st::Everything::initDevices();

}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
//*****************************************************************************
//Execute the Everything run method which takes care of “Everything”
//*****************************************************************************
st::Everything::run();
}

Any help with where I’m going wrong gratefully received!! How do I declare “name” so it knows what to do with the temp display for my test display of the 1st temperature sensor.

Thanks once again.

Dan.

The advice I provided was pseudo code, not real code. You need to parse the ‘msg’ into two string variables, name & value (which you need to declare as well.)

Afterwards, you would update your lcd using its library call, lcd.print()…

Get the idea?

     if (msg == "switch1 on") { val1 = 1}
     if (msg == "switch1 off") { val1 = 0}

/Users/bob/Desktop/st_v1.ino/st_v1.ino.ino: In function ‘void callback(const String&)’:
st_v1.ino:71:35: error: expected ‘;’ before ‘}’ token
if (msg == “switch1 on”) { val1 }
^
st_v1.ino:72:36: error: expected ‘;’ before ‘}’ token
if (msg == “switch1 off”) { val1 }
^
st_v1.ino:74:9: error: ‘val’ was not declared in this scope
if (val == LOW) {;
^
st_v1.ino:84:9: error: ‘val’ was not declared in this scope
if (val == LOW) {
^
/Users/bob/Desktop/st_v1.ino/st_v1.ino.ino: At global scope:
st_v1.ino:98:1: error: expected declaration before ‘}’ token
}
^
Multiple libraries were found for “Servo.h”
Used: /Users/bob/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/Servo
Not used: /Applications/Arduino.app/Contents/Java/libraries/Servo
exit status 1
expected ‘;’ before ‘}’ token

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor
//    data being sent to ST.  This allows a user to act on data changes locally within the
//    Arduino sktech.
//******************************************************************************************

int val1;     // variable for keeping local copy of the switch1 current state

void callback(const String &msg)
{

  Serial.print(F("ST_Anything Callback: Sniffed data = "));
  Serial.println(msg);

  //TODO:  Add local logic here to take action when a device's value/state is changed


  //NOTE:  you may need to play with the logic below to get the behavior you desire!!!
  if (msg == "switch1 on") { val1 = 1};
  if (msg == "switch1 off") { val1 = 0};
    if (val == LOW) {
      st::receiveSmartString("switch1 off");
    }
    else {
      st::receiveSmartString("switch1 on");
    }
  }
  }
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

You’re missing the semicolons at the end of each assignment.

if (msg == "switch1 on") { val1 = 1;} 
if (msg == "switch1 off") { val1 = 0;}

Would I add the servo code hear?

servo is not moving at all not.

int val1; // variable for keeping local copy of the switch1 current state

void callback(const String &msg)
{

Serial.print(F("ST_Anything Callback: Sniffed data = "));
Serial.println(msg);

//TODO: Add local logic here to take action when a device’s value/state is changed

//NOTE: you may need to play with the logic below to get the behavior you desire!!!
if (msg == “switch1 on”) { val1 = 1;}
if (msg == “switch1 off”) { val1 = 0;}
if (msg == “button1 pushed”) {
if (val1 == LOW) {
myservo.attach(PIN_SWITCH_1); //D4
myservo.write(180);
delay(2000);
myservo.detach();
st::receiveSmartString(“switch1 on”);
}
/**else {
myservo.attach(PIN_SWITCH_1); //D4
myservo.write(0);
delay(2000);
myservo.detach();
st::receiveSmartString(“switch1 off”);
}*/
//Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
//st::receiveSmartString(“Put your command here!”); //use same strings that the Device Handler would send
}
}

Has anyone managed to get a BH1750 sensor working with ST_Anything?

I world rather use the BH1750 than a photosensor because in that case it is possible to have a trigger based on a value.

That sensor uses I2C for analog input/output. The only thing that uses i2c in ST_Anything is the Si7021 Temp/Humidity sensor. You might have to adapt the code from that to work with the DH1750.

1 Like

Can you please explain this statement a little more? While I agree the photoresistor isn’t the most accurate illuminance sensor, it should be fine to relative lux measurements, right? You can even adjust the scaling when you define the sensor to be somewhat ‘calibrated’.

I2C devices pose a little bit of a more challenging design. As @Ryan780 mentioned, a user did submit a pull request for the Si7021 sensor, which uses I2C. You should be able to build off of that code, as well as the analog illuminance sensor, to create an ST_Anything class for the DH1750 sensor.

I do not have a DH1750 sensor to test with, so I can’t easily create the class and test it for you.

Can someone make a Servo sketch for ST_Anything?

It’s not just the sketch, you would have to build a ST_Anything capability built of the Servo library.