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

arduino
alarm
dth_misc
esp8266
esp32

(Steve ) #2287

Thanks I think I need to start from a fresh example I think I may have messed up some of the code as it’s still not working.
I thought best to leave your example as it was so deleted the line for the sensor 1 and pasted in your line.
st::PS_TemperatureHumidity sensor1(F("temphumid1"), 120, 7, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT21, "temperature1", "humidity1", false);
And left all the commenting as it was but it still won’t compile, but like I say I think I messed up some code somewhere I’m going to try reading up on the basics of Arduino as I hate asking all the daft questions :frowning:


#2288

Do you have a library for the particle that integrates with ST? I bought a photon and it’s still sitting in the box because I found it so difficult to work with.


(Dan) #2289

Steve,

Was there a particular reason that you started with the I2C example sketch? Unless you are planning on using one of the sensors in that example sketch, I would recommend you start with the ST_Anything_Multiples_ESP8266WiFi.ino sketch as a starting point.

If all you want to start with is a single DHT21 sensor, try the following sketch (you still need to edit the Networking Section.) Your DHT21 sensor’s data pin should be wired to pin GPIO D1 on your NodeMCU ESP8266 board. Connect the DHT21’s power and ground to the NodeMCU’s 3.3v and Gnd pins respectively.

//******************************************************************************************
//  File: ST_Anything_Multiples_ESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one NodeMCU ESP8266 to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the NodeMCU ESP8266's WiFi.
//
//            ST_Anything_Multiples implements the following ST Capabilities as a demo of what is possible with a single NodeMCU ESP8266
//              - 1 x Alarm device (using a simple digital output)
//              - 1 x Contact Sensor devices (used to monitor magnetic door sensors)
//              - 1 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc...)
//              - 1 x Motion devices (used to detect motion)
//              - 1 x Smoke Detector devices (using simple digital input)
//              - 1 x Temperature Measurement devices (Temperature from Dallas Semi 1-Wire DS18B20 device)
//              - 1 x Relay Switch devices (used to turn on a digital output for a set number of cycles And On/Off times (e.g.relay, etc...))
//              - 2 x Button devices (sends "pushed" if held for less than 1 second, else sends "held"
//              - 1 x Water Sensor devices (using the 1 analog input pin to measure voltage from a water detector board)
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2015-01-03  Dan & Daniel   Original Creation
//    2017-02-12  Dan Ogorchock  Revised to use the new SMartThings v2.0 library
//    2017-04-17  Dan Ogorchock  New example showing use of Multiple device of same ST Capability
//                               used with new Parent/Child Device Handlers (i.e. Composite DH)
//    2017-05-25  Dan Ogorchock  Revised example sketch, taking into account limitations of NodeMCU GPIO pins
//    2018-02-09  Dan Ogorchock  Added support for Hubitat Elevation Hub
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP8266WiFi
//******************************************************************************************
#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 <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_CONTACT_1             D2  //SmartThings Capabilty "Contact Sensor"
//#define PIN_BUTTON_1              D3  //SmartThings Capabilty Button / Holdable Button (Normally Open!)
//#define PIN_BUTTON_2              D4  //SmartThings Capabilty Button / Holdable Button (Normally Open!)
//#define PIN_MOTION_1              D5  //SmartThings Capabilty "Motion Sensor" (HC-SR501 PIR Sensor)
//#define PIN_SMOKE_1               D6  //SmartThings Capabilty "Smoke Detector"
//#define PIN_TEMPERATURE_1         D7  //SmartThings Capabilty "Temperature Measurement" (Dallas Semiconductor DS18B20)
//#define PIN_TIMEDRELAY_1          D8  //SmartThings Capability "Relay Switch"
#define PIN_TEMPERATUREHUMIDITY_1   D1  //SmartThings Capabilties "Temperature Measurement" + "Relative Humidity Measurement"(DHT21)

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "yourSSIDhere";                           //  <---You must edit this line!
String str_password = "yourWiFiPasswordhere";                   //  <---You must edit this line!
IPAddress ip(192, 168, 1, 227);       //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 / Hubitat Hub TCP/IP Address
IPAddress hubIp(192, 168, 1, 149);    // smartthings/hubitat hub ip //  <---You must edit this line!

// SmartThings / Hubitat Hub TCP/IP Address: UNCOMMENT line that corresponds to your hub, COMMENT the other
const unsigned int hubPort = 39500;   // smartthings hub port (default)
//const unsigned int hubPort = 39501;   // hubitat 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);
  
  //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("temperature2"), 15, 0, PIN_TEMPERATURE_1, false, 10, 1); 
  static st::PS_TemperatureHumidity sensor9(F("temphumid1"), 60, 40, PIN_TEMPERATUREHUMIDITY_1, st::PS_TemperatureHumidity::DHT21,"temperature1","humidity1");
  
  //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              sensor6(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_Alarm executor1(F("alarm1"), PIN_ALARM_1, LOW, true);
//  static st::EX_Switch executor2(F("switch1"), PIN_SWITCH_1, 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); 
//  st::Everything::addSensor(&sensor5); 
//  st::Everything::addSensor(&sensor6); 
//  st::Everything::addSensor(&sensor7);  
//  st::Everything::addSensor(&sensor8);  
  st::Everything::addSensor(&sensor9);  
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
//  st::Everything::addExecutor(&executor1);
//  st::Everything::addExecutor(&executor2);
    
  //*****************************************************************************
  //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();
}

(Steve ) #2290

Thanks so much for that @ogiewon.
That sketch worked great i wasn’t too sure which ESP sketch was for my NoceMcu so that’s why i tried the I2C.
On my smartThings app though it created 3 “things” for the humidity and 2 for the temperature 1 of each are reporting the correct readings is this right?
and if so am i able to safely delete the ones that say -1.
one final thing i renamed the working humidity and it renamed ok but it gives me a unexpected error when renaming the temperature, but i remember reading about the naming has to be the same is that why.
Thanks for all the help


(Dan) #2291

Yes, delete the extra child temperature sensor that doesn’t work.

In the ST Classic App, you can rename each child in its settings page (at least on iOS).


(Steve ) #2292

Thanks deleted them fine,
No for some reason the temperature wouldn’t rename in the app.
I logged into the SmartThings ide and that let me change it ok.
But then I wanted to change the icon and to change F to C and it pops up with this error :cry:
Even though when I go back to the thing page it has change the F to C reading but not the icon.


(Dan) #2293

That looks like an Android Device, correct? If so, I have no way of debugging that platform. Others have mentioned Android related issues in the past.


(Steve ) #2294

yeah its Android.
Its not a problem like i say it lets me edit it through the SmartThings website


(Brandon Jackson) #2295

I’m also looking for neopixel (ws2812b) support, the most basic would be color/brightness, but having a few buttons for preset modes (from the WS2812FX library as an example) would be awesome. I’m willing to test anything you need, I tried looking a the code to work on it myself but got lost pretty quick!


#2296

Yeah…still nothing that’s compatible with SmartThings. The closest thing I’ve been able to find is a program called McLighting. It has MQTT and Homeassistant support but I just can’t find the time to learn either of them to be able to use. What it does have though is control through a REST API. So, you can control it through simple web calls. I’ve been using it in conjunction with webCoRE for a while now.


(Allan) #2297

I worked for hours (30+) trying to get ST_Anything to work with programmable LEDs using the standard NeoPixel libraries. Long story short I couldn’t get it to work reliably on either a ESP32 or ESP8266. For small strands (less then 30 leds) it was ok but more and the controller would reboot due to a watchdog timer issue caused by the library blocking calls until it was done. Turns out programmable LEDs are extremely time sensitive so they block the controller from doing anything else until they are done which most controllers don’t appreciate. I tried using the FastLed library which purposely has programming to get around this limitation but I couldn’t get it integrated into ST_Anything like I could with the NeoPixels library.

I started work on a simple DTH that just makes HTTP calls to a ESP8266 running McLighting or FastLed but didn’t get very far. I still have the framework DTH if someone more experienced wants to give it a try. It would be nice to have it built into ST_Anything so you can use the same controller for other stuff but with the cost of a ESP8266 being like $10 it might be easier to just have one dedicated to this.

If anyone wants to play with the code I have the .cpp, .h, and DTH saved to my GitHub.


#2298

It’s not so much having another board. I just want to be able to turn a switch off and turn off the LEDs rather than having to have a rule tied to a virtual switch and… You know all that’s entailed. It’s just a pain. Plus, when I use them for notifications (fading in a certain color), I have to run a webcall to find out what the current settings are, store that, then do the notification, then set it back again. It’s a REAL pain. I got it to work well with McLighting but I need one piston per strip. And it doesn’t work at all from Hubitat. So, a native DTH would be much nicer. I saw your DTH… I couldn’t find the sketch for the ESP that went with it though.


(Allan) #2299

My libraries are in here. EX_RGBAddressable_dim.cpp and .h: https://github.com/vseven/SmartThings_VSeven/tree/master/Modified_ST_Anything_Libraries. There is also a 8266 sketch in the same directory that I sent to a couple people to test which all had the same results as me. Need to have the “NeoPixel” library installed for it to compile.


#2300

Thanks a bunch.


(Allan) #2301

NP, last I remember it should compile and “work”. For testing I told the sketch its just a standard RGBSwitch so it would use the existing DTH (so the ST_Anything parent device wouldn’t need to be modified for testing). Test it with LEDs set to like 15 and see if it works and increase until it fails.

Like I said the “FastLED” library should get around the issues but I couldn’t get the code formatted properly to include that library. The NeoPixel library was relatively easy to include.

Also: https://github.com/DanielOgorchock/ST_Anything/issues/103 and you might want to try this NeoPixel library in place of the stock one: https://github.com/Makuna/NeoPixelBus I’m hoping nothing in my code would have to change to test that as you’d just change the reference.


#2302

That should actually work perfectly actually. I’m trying to encoporate a 16 light strip to do some under cabinet lighting but could easily shorten it to 15. I’ll let you know if I’m able to get it to work.
Thanks!


(Steve ) #2303

Hiya.
I did this sketch last week which worked great (DHT21)
But I wanted to test the board with 2 sensors attached on another sketch and that seemed to work fine but I decided to go back to how it was.
So I reloaded your sketch and like last time it created 6 child devices 3 for temp and 3 for humidity with one from each being the working one so I renamed them.
But as soon as I delete any of the other extra child devices the working ones stop working for some reason.
Have you had this issue before ?
Its didn’t do this last week when I deleted the extra devices, Do you know why its creating 6 devices for 2 sensors ?
Thanks


(Allan) #2304

I’ve had the same issue with my DTH22 sensors. It seems it only started happening in the last month or two. I just waited about 10 minutes and then went into each one and looked for ones that hadn’t updated since 10 minutes ago and deleted those. The remaining actual sensors all have been working fine.


(Steve ) #2305

Yeah that’s what I’ve done , I set it back up again yesterday and left them running all night and deleted the ones not working but still nothing :thinking:
I’ll try it again.
Cheers


#2306

I might be over thinking this but how do you trigger the Interrupt contact sensor using logic from within the Arduino?

Say every 5 seconds contact sensor 1 reports closed, then the next 10 seconds it reports open, continuously.