[RELEASE] ST_Anything - Arduino/ESP8266/ESP32

I have absolutely no idea what that means. Just forget it. I will NEVER ask you for anything ever again. Goodbye.

Put the word ‘static’ at the beginning of this line:
st::PS_TemperatureHumidity sensor1(F(“temphumid1”), 120, 1, PIN_TEMPERATURE_1, st::PS_TemperatureHumidity::DHT22, “temperature1”, “humidity1”, false);

It makes sure the object will exist for the duration of the program rather than just the duration of the function.

2 Likes

I bought a voltage sensor that I plan to attach to my smoke detector’s siren (Nest Protect) so I can communicate to ST (as Works with Nest is no longer functional).

I am fairly new to Arduino and ST_Anything (previously programmed logic and API on a Pi with Python and just used the Arduino for SPI/I2C communication).

Any tips on what kind of approach would work best (using a ESP8226 board)? I am thinking about having a certain voltage threshold trigger a button press and send that back to ST but I am open to other implementations.

If you can tap into the Nest Protect to get a constant DC voltage when the alarm is active, then I would simply use the ST_Anything IS_Smoke device. It uses a digital input pin, so all you need to do is use a voltage divider pair of resistors, to make sure the voltage from the Nest Protect is below the Digital Input trigger threshold when there is no alarm, and above the digital input threshold when there is an alarm.

This way ST_Anything will simply create a Smoke Alarm device within SmartThings that you can use just like any other Smoke Alarm device.

1 Like

The voltage is not constant (it fluctuates as the siren beeps). Is there a simple way to use a bool to tell ST if the smoke detector went off?

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;

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

void loop(){
  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

  if (smoke_detected == true){
    // TELL SMARTHINGS THAT SMOKE IS DETECTED
  }
  else{
    // TELL SMARTTHINGS THAT SMOKE IS CLEAR
  }
  
}

So at the “if (smoke_detected = true){” statement can I send the is_smoke alert to SmartThings without having a physical connection to one of the pins?

Thanks

OK, that helps…

Is this sketch going to only be used for detecting the status of the smoke detector? If so, we can simply add SmartThings communications support to your existing sketch.

Thoughts?

1 Like

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.