First off thanks in advance for anyone who can help me out with these small issues!
I am using high level relays to control two light circuits with an ESP01 and everything works great but the lights states are inverted. ie when they are on they show off and vise versa. Is see it commented in the code it is for a low level relay so how can I change this? I tried changing the below from LOW to HIGH which did not work and also tried LOW, false and this also didn’t work. Do I need to adjust anything in the ST_Anything library or can I do it right in my sketch?
static st::EX_Switch executor1(F(“switch1”), PIN_Daylight, LOW, true);
static st::EX_Switch executor2(F(“switch2”), PIN_Nightlight, LOW, true);
Also when I added the device to ST it added an extra button so I now have two “switch 1” and one “switch 2”. Can I just delete the duplicate child or will this mess everything up? And lastly, is there anyway I can prevent both switches from going on? I want one or the other on or both off. I would like to do this in the arduino sketch so it is not possible for both circuits to be on at the same time. MY voltage regulator cant handle both circuits on at once.
//******************************************************************************************
// File: ST_Anything_Multiples_ESP01WiFi.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 ESP8266-01 (ESP-01) 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 ESP-01's WiFi.
//
// ST_Anything_Multiples implements the following ST Capabilities in multiples of 1 as a demo of what is possible with a single ESP-01
// - 1 x Contact Sensor device (used to monitor magnetic door sensors)
// - 1 x Motion devices (used to detect motion)
//
// Note: The tiny ESP-01 only has 2 GPIO pins, so this example is somewhat limited. Use the ST_ANything_Multiples_ESP8266WiFi.ino example to see
// what else is possible. As long as you only try using 2 pins, you can use them for whatever you'd like.
//
// 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-02-21 Dan Ogorchock New example specifically for running everythin on a ESP-01 (no Arduino required!)
// 2017-04-24 Dan Ogorchock Updated for use with new v2.5 Parent/Child Device handlers
// 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_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 <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
//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_Daylight 0
#define PIN_Nightlight 2
//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid = "Internet"; // <---You must edit this line!
String str_password = "password"; // <---You must edit this line!
IPAddress ip(x, x, x, x); //Device IP Address // <---You must edit this line!
IPAddress gateway(x, x, x, x); //Router gateway // <---You must edit this line!
IPAddress subnet(x, x, x, x); //LAN subnet mask // <---You must edit this line!
IPAddress dnsserver(x, x, x, x); //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(x, x, x, x); // 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
//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 ESP-01
// 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
//Interrupt Sensors
//Executors
static st::EX_Switch executor1(F("switch1"), PIN_Daylight, LOW, true);
static st::EX_Switch executor2(F("switch2"), PIN_Nightlight, LOW, true);
//*****************************************************************************
// Configure debug print output from each main class
//*****************************************************************************
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
//*****************************************************************************
//*****************************************************************************
//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();
}