SmartThings Community

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

arduino
alarm
dth_misc
esp8266
esp32

(Dan) #2327

Thanks, but I want to see the Device, not the DTH. On your My Devices tab in the ST Web IDE, click on the Parent Device you manually created, so I can see all of the details.


(Sean Rudden) #2328

That would make more sense, here it is:


(Dan) #2329

Everything there looks normal. I was hoping that you had simply forgotten to assign your Hub to this device, but it looks like you did.

Without Live Logging, I am not sure how to help you troubleshoot this issue.

As for renaming the device to remove the error message, that only works because I trap the new error you created by removing the numeric part of the name within the Parent Device Handler code, and log that error to Live Logging. The Parent Device Handler never even tries to create a child device without that numeric suffix to the device name. Also, the Device Names must follow the standard naming outlined in the ReadMe file. Otherwise, the parent will not know what type of child device to create.


(Denis Grabocka) #2330

Ok great i got it compiled, flashed on my NODEmcu and the SmartThings IDE and App part configured but i installed ST_Anything_Multiples and i obviously i got a long list of devices that i do not need.
All i need is 2 relay buttons/controls to turn on and off an electric curtain …do i just remove the buttons i do not need from the ST app and keep just the relay button and a switch button and use those as the 2 controls i need or will it be better to flash ST_Anything_Relays on my ESP8266??

As a matter of fact i am actually only looking for 2 momentary buttons … which sketch does that best since my curtains have 2 momentary buttons one for open one for close than stop automatically when they reach the end of direction.

The relays should respond to the default D pins assigned in your sketch right?? since i did not change any of that on the sketch other than the IPs and wifi config

Thank you very very much
Denis


(Dan) #2331

Just for clarification… You would like two digital outputs, that after being turned on, automatically turn off after a few seconds. Is that correct? Anything else? I can whip up that sketch very quickly once I know all of your requirements.

UPDATE: Here is the base sketch to start from. You’ll need to modify the WiFi section, or course. This sketch uses Pins D1 and D2 on a NodeMCU ESP8266 board.

//******************************************************************************************
//  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
//              - 2 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...))
//    
//  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
//    2018-11-13  Dan Ogorchock  Revised for DENIS GRABOCKA's requirements
//
//******************************************************************************************
//******************************************************************************************
// 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_TIMEDRELAY_1          D1  //SmartThings Capability "Relay Switch"
#define PIN_TIMEDRELAY_2          D2  //SmartThings Capability "Relay Switch"

//******************************************************************************************
//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 Port: UNCOMMENT line that corresponds to your hub, COMMENT the other
const unsigned int hubPort = 39500;   // smartthings hub port
//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 Handler 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
  
  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  static st::S_TimedRelay           sensor1(F("relaySwitch1"), PIN_TIMEDRELAY_1, LOW, false, 2000, 0, 1);
  static st::S_TimedRelay           sensor2(F("relaySwitch2"), PIN_TIMEDRELAY_2, LOW, false, 2000, 0, 1);
  
  //Executors
  
  //*****************************************************************************
  //  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);
     
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
    
  //*****************************************************************************
  //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();
}

(Denis Grabocka) #2332

Yes that is it you got it right… and man than you so much for being such a great help and so quick to reply.

One last think what do i select or use on the SmartThings side what kind of device?/

Thank you again
Denis


(Dan) #2333

Simply follow the same instructions from the ReadMe on the ST IDE side of things. If you already have a ST_Anything Parent Device, remove it (not the groovy code, the device.) Then, manually create a new Parent Device for this particular NodeMCU Board (unique MAC address for each board), configure its settings in the ST Classic App, and the two Child Devices will be created. Then you simply turn them on, and they will automatically turn off after 2000ms (you can change that value in the sketch as needed.)


(Patrick Blinkhorne) #2334

I’ve attempted this on a 9g servo actuating my blinds and it’s still buzzing for me :frowning: I’m assuming the test would be to apply a level change, wait a second and then attempt to move the servo? At this point it shouldn’t buzz?


(Dan) #2335

Correct. Assuming the last two parameters are “true” and some “number of ms”, the servo should be powered off after a move as the PWM signal is stopped after the “number of ms”. You can tweak the number of ms as you see fit.

st::EX_Servo executor1(F(“servo1”), PIN_SERVO, INITIAL_ANGLE, true, 750);


(Patrick Blinkhorne) #2336

It looks like this, I assume this is correct?

static st::EX_Servo executor1(F(“servo1”), PIN_SERVO_1, 90, true, 1000); //last argument is the starting angle for the servo (0-180)


(Dan) #2337

Looks correct to me.

If you use example Arduino Servo sketches, can you properly disable power to the motor? I am curious if you take ST_Anything out of the equation, does the servo behave as expected?


(Brian Spranger) #2338

The last time I played with servos I had to use a relay to cut the power. I couldn’t get the servo to respond correctly to disabling the pwm signal.


(Sean Rudden) #2339

I was able to make a copy of the parent device handler and I changed the state.alertMessage to show me the error, '${e}'. It turned up this: physicalgraph.app.exception.UnknownDeviceTypeException: Device type 'Child Door Control' in namespace 'ogiewon' not found. How do I fix it?


(Dan) #2340

That would usually mean that you do not have my “Child Door Control” device handler properly added to your ST Web IDE and Published. How many “Locations” do you have on your account? Are you sure you’ve added/published the device handlers to the correct ST Location?

Did you ever get Live Logging to work on your account? If not, something is messed up on your ST account in my opinion. You really should get ST Support to fix it.


(Sean Rudden) #2341

The device handlers are published to my home hub, as shown in the previous screenshots. Smartthings Support did help me figure out the problem with live logging, I set up smartthings on a different account than I was using, so I accessed my primary account and live logging worked. I will try to install ST_Anything on my other account and see if that helps.


(Sean Rudden) #2342

Its fixed! I guess since ST_Anything was not published on the primary account, I continued to get this error. This should be a note for others that ST_Anything must be on the primary account of your hub or ST_Anything won’t work.

Thanks for the help,
Sean


(Denis Grabocka) #2343

@ogiewon Ok i got it hooked up and it works perfectly but i have 2 observations:

  1. From boot the relays are triggered the LEDs are red and they remain red (and go back to ON red) unless you touch the buttons on the app to trigger them than they go briefly off and than back to red so it works but on the opposite per say like NC not NO. When i think they are supposed to be triggered on tap and go back to off.

  2. On the ST app side Relay number 2 button works nicely you touch it it says (ON and blue) in 2 seconds it goes back to off and gray just as it is supposed to… on the other hand Button 1 for relay 1 when you touch it it says (Turningon and blue) and remains like that until you go and touch it again for it to go to off… although the relay is triggered and back again in 2 sec like normal. So it seems like either ST is not refreshing fast enough (but why is it doing it just fine for R2) or there is something on the sketch end.

Is there a way to fix this 2 minor nuisance??

Thank you again for everything and much appreciated
Denis


(Patrick Blinkhorne) #2344

I’ve tried it with non-st_anything and unfortunately it’s still doing it. It will still fight motion when its completed the throw :frowning: Does anyone know if this is servo specific? As in, would another brand/size of servo perform as we’re expecting?


(Dan) #2345

Just to be sure… Is your non-ST_Anything example sketch calling the Arduino Servo library’s detach() function? This is the call the ST_Anything Servo device uses to try to release the servo and make it quiet.

https://www.arduino.cc/en/Reference/ServoDetach


(Dan) #2346

Yes, all custom code must be installed using the primary ST account for the hub you’re using.

I do not recall anyone ever trying to use a sub-account. Congratulations! You’re the first! :wink:

I am glad to hear you got it working.