[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Yup, that would be great!

FYI - I haven’t forgotten about this… Just been busy this week. Hopefully will have more time later this week/this weekend.

1 Like

@kamran

Here is a version of your sketch that should communicate with ST. I have not tested it, but it does compile. You must already have the ST_Anything Arduino files downloaded and installed on your computer in order for this to compile.

You would still create a ST_Anything Parent device just like normal. A child Smoke device should be automagically created.

#include <SmartThingsESP8266WiFi.h>
//******************************************************************************************
//ESP8266 WiFi Information    CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
String str_ssid     = "yourSSIDhere";                           //  <---You must edit this line!
String str_password = "yourWiFiPasswordhere";                   //  <---You must edit this line!
IPAddress ip(192, 168, 1, 202);       // 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, 149);    // smartthings hub ip     //  <---You must edit this line!
const unsigned int hubPort = 39500;   // smartthings hub port

SmartThingsCallout_t messageCallout;    // call out function forward decalaration

//Create a SmartThings Ethernet ESP8266WiFi object
st::SmartThingsESP8266WiFi smartthing(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);

int analogInput = A0; //Change if not connected to pin A0
float vout = 0.0; //do not change
float vin = 0.0; //do not change
float R1 = 30000.0; //onboard resistor 1 value
float R2 = 7500.0; //onboard resistor 2 value
int svalue = 0; //do not change

bool smoke_detected = false;
unsigned long smoke_detected_time;
String lastStatusSent;


void setup(){
  pinMode(analogInput, INPUT);
  Serial.begin(9600);

  //Run the SmartThings init() routine to make the connection to the ST Hub
  smartthing.init();

  lastStatusSent="";
}

void loop(){

  // run smartthing logic
  smartthing.run();

  svalue = analogRead(analogInput); //this reads the value from the sensor
  vout = (svalue * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
  if (vin >= 4.0){
    smoke_detected = true;
    smoke_detected_time = millis();
  }
  else if (millis() - smoke_detected_time > 60000)  // if it has been more than 60 seconds since last chime.
  {
    smoke_detected = false;
  }
  
  Serial.print(vin,2); // prints the voltage
  Serial.println(" volts DC"); // prints the words "volts DC"
  //delay(100); //delay loop for 0.1 sec  //delay() statements are BAD for the SmartThings Communications Library

  if (smoke_detected == true){
    // TELL SMARTHINGS THAT SMOKE IS DETECTED
    if (lastStatusSent != "detected") {
      lastStatusSent = "detected";
      smartthing.send("smoke1 detected");       // send message to cloud
    }
  }
  else{
    // TELL SMARTTHINGS THAT SMOKE IS CLEAR
    if (lastStatusSent != "clear") {
      lastStatusSent = "clear";
      smartthing.send("smoke1 clear");       // send message to cloud
    }
  }
  
}

void messageCallout(String message)
{
    Serial.print("Received message: '");
    Serial.print(message);
    Serial.println("' ");
}
1 Like

Thank you @ogiewon. Will try this and report back. Thanks again!!

Did the UNO Wifi Rev 2 (6KB ram) port get merged? I’m interested in using the same board and don’t want to reinvent the wheel.

1m

Hi. What i meant is when i edit the device on smarthings app after creating it on the Samarthings IDE , do i need to choose 21 buttons for it? I count 21 devices in the sample sketch. I still havent been able to get it to work. I verified all device handlers are published, mac address is correct, hub and device ip’s are static and verified they are the correct ones. I am not very familiar with arduino. This is my first time playing with it. All i did to the sketch was to follow the steps and edited all the lines indicated in the sketch, which raises one question: what is the hubitat hub? What address should i assign it? Do the devices need to be connected for it to start updating and create the tile for it? thanks

No. Button devices are simple digital inputs on the Arduino. You only need to put a value in this field if your sketch defines any IS_Button devices.

Hubitat is a different hub, from a different company. Please post a copy of your Arduino sketch here in the forum so I can take a look at it to see if you’ve configured it correctly.

Please note that you need to uncomment the ST Hub lines below, and comment out the Hubitat lines of code, as I have shown below. The ST hub uses port 39500 while the Hubitat hub uses port 39501. If you’re sketch is using the wrong port, the child devices will never be created.

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

// Hubitat Hub Information
//IPAddress hubIp(192, 168, 1, 145);    // Hubitat hub ip     //  <---You must edit this line!
//const unsigned int hubPort = 39501;   // Hubitat hub port

I have started playing with my retired ThingShield again (supported Konnected panel but its not working out its too slow “huge delay”) so i’m going back to my old setup with ThingShield. I have installed everything per the readme but Child Devices are not created. I used Link
as is without any modifications. Arduino is working properly as in Arduino App in Serial monitor is giving responses when open and close sensors. Thank you

Are you using an Arduino MEGA 2560? The Arduino UNO does not have enough RAM to run the sketch you linked.

Did you properly pair the ThingShield with your ST Hub?
After zigbee pairing, did you change the DTH to the “Parent ThingShield” DTH?
What shows up in the Live Logs in the ST Web IDE?
What happens on the Arduino Serial Monitor Window when you click REFRESH on the Parent ThingShield device in the ST Classic App?

Yes I’m using an Arduino MEGA 2560.

Yup I have followed instructions in GitHub.

here is my live log

e15b12a6-908a-4896-8103-dcd15bdfeb67 6:35:39 PM: debug [name:, value:null, linkText:Arduino ThingShield, isStateChange:false, displayed:false]

e15b12a6-908a-4896-8103-dcd15bdfeb67 6:35:39 PM: debug Parsing name:

e15b12a6-908a-4896-8103-dcd15bdfeb67 6:35:39 PM: debug Parsing:

e15b12a6-908a-4896-8103-dcd15bdfeb67 6:35:38 PM: debug Executing ‘sendThingShield’ refresh

e15b12a6-908a-4896-8103-dcd15bdfeb67 6:35:38 PM: debug Executing ‘refresh()’

e15b12a6-908a-4896-8103-dcd15bdfeb67 6:35:38 PM: debug Executing ‘configure()’

e15b12a6-908a-4896-8103-dcd15bdfeb67 6:35:38 PM: debug Executing ‘configure()’

When the “Executing Refresh” line occurs in the Live Logs, what shows up (if anything) in the Arduino IDE Serial Monitor Window?

no activity in Serial Monitor Window only if i close or open PIN_CONTACT

It has been over 2 years since I had a ThingShield paired to SmartThings. So it is entirely possible that Samsung/SmartThing changed something on the platform that could have caused an issue.

Can you please share a picture of exactly how you have the ThingShield wired to the Arduino MEGA? Also, what position in the ThingShield’s little switch in? IIRC, it should be slid over to the pins 2/3 position.

Here are the detailed wiring instructions for using a ThingShield with the MEGA 2560.

The Arduino MEGA 2560 must use HardwareSerial “Serial1, Serial2, or Serial3” for communications with the ThingShield. MEGA 2560 Hardware Serial:

  • Use the new Hardware Serial constructor passing in a pointer to a Hardware Serial device (&Serial1, &Serial2, &Serial3)
    • definition st::SmartThingsThingShield(HardwareSerial* serial, SmartThingsCallout_t *callout);
    • sample st::SmartThingsThingShield(&Serial3, callout);
  • Make sure the ThingShield’s switch in the “D2/D3” position
  • Be certain to not use Pins 2 & 3 in your Arduino sketch for I/O since they are electrically connected to the ThingShield. Pin6 is also reserved by the ThingShield. Best to avoid using it.
  • On the MEGA, Serial1 uses pins 18/19, Serial2 uses pins 16/17, and Serial3 uses pins 14/15
  • You will need to wire the MEGA’s HardwareSerial port’s pins to pins 2 & 3 on the ThingShield. For example, using Serial3, wire Pin 2 to Pin 14 AND Pin3 to Pin 15.

Dan,

I did forget about this portion
You will need to wire the MEGA’s HardwareSerial port’s pins to pins 2 & 3 on the ThingShield. For example, using Serial3, wire Pin 2 to Pin 14 AND Pin3 to Pin 15

Thank you so much all children are created time to narrow it down to what i have.

Thank you

1 Like

Dan,
Is there a way to connect heat detector to ST_Anything? I have one in the kitchen, Landry room and garage. I have removed my old panel like 5 years ago and didn’t save any input data.

Thank you

I have zero experience with that device. The brief description says it has a normally open contact - so maybe you could wire it like a normal ST_Anything contact sensor? This is only IF the contacts are ‘dry contacts’, which means there is no voltage coming from the Heat Sensor’s normally open contacts.

I’m now using the adt smartthings . What is the hubPort?

As far as I know, it is still 39500. I have never used an ST ADT Hub, so I do not know if it behaves the same or not.