[RELEASE] ST_Anything v2.9.7 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi

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!!

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

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.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.