Yes, I did, if you’re referring to using an ultrasonic sensor to determine if a garage is occupied or not.
It was more luck (and obviously help from @ogiewon) than anything else, as I had never before had anything to do with an Arduino and I no nothing about programming. The system is fairly reliable, with the sensors losing connection with the wi-fi network every few days. I’ve not been able to figure out why. (It is not a range issue, as both Adruino’s used in the garage, are within 4m from the AP.) A power cycle of the Arduino’s or rebooting the AP bring them back to live.
It there anything specific you wanted to know?
Yes, I am curious about how you made this work.
I can get the garage door opener working using the ST_Anything_GarageDoors_ESP8266WiFi sketch and I can get a modified version of ST_Anything_Ultrasonic_ESP01WiFi working. Modified to get distance rather than volume.
I am trying to create a mashup of both similar to the way that the Garage Doors sketch uses both the relay for open/close and the contact sensor for status.
Have you combined the two or are they separate devices and devices?
@ogiewon Dan,
Like Hendre, I want to use a ultrasonic sensor to indicate the status of my garage doors.
I have successfully got the garage doors working under one parent without the contact sensors.
I have successfully recoded the ultrasonic device handler and sketch to calculate distance rather than volume.
All good but I would like to replace the contact sensor in the garage doors code with the ultrasonic sensor. I am struggling to combine the two.
Any suggestions. It looks like I might have to mess with the IS_DoorControl.h and IS_DoorControl.cpp code
Yep, that might be a decent place to start. Just change the code to perform the ultrasonic measurement and covert the distance into an “open” or “closed” value. Don’t bother using the ultrasonic Device Handler code. Just trick the system into thinking it is a normal contact sensor.
Another idea would be to perform the ultrasonic measurement/calculation inside the sketch’s loop() function. Once you determine open/closed status, you could simply output that status to a GPIO pin. Then tie that pin to the door control’s contact sensor pin, thereby tricking the system into thinking that you are using contact sensors.
Have fun with it!
Could you post your recoded ultrasonic device handler. I would like to have distance capability but am not knowledgeable enough to develop anything.
Thanks
Tom
If you just want distance values from an ultrasonic sensor, simply create the device in your sketch as follows:
st::PS_Ultrasonic sensor1("voltage1", 60, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E);
As you can see I assigned it the name “voltage1” instead of “ultrasonic1”. This will cause it to create a Child Voltage device instead of the Child Ultrasonic device. This will report the simple numeric value from the sensor.
Thanks Dan.
Much easier than my approach. I think the output will still need some manipulation in the sketch to get the unit of measure desired.
Dan do you know if this will return the unit of time for the echo to do a return trip or will it return the distance traveled during that time?
Appears to be the distance, if my comments in the code are to be believed… I would have copied this probably directly from an example sketch for using the ultrasonic sensor.
Feel free to hack away at your local copy of the PS_Ultrasonic.cpp file to make it suit your needs. That’s the beauty of open source software!
void PS_Ultrasonic::getData()
{
//int m_nSensorValue=map(analogRead(m_nAnalogInputPin), SENSOR_LOW, SENSOR_HIGH, MAPPED_LOW, MAPPED_HIGH);
long duration;
// Clears the trigPin
digitalWrite(m_nDigitalTriggerPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(m_nDigitalTriggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(m_nDigitalTriggerPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(m_nDigitalEchoPin, HIGH);
// Calculating the distance
m_nSensorValue = duration*0.034/2;
// queue the distance to send to smartthings
Everything::sendSmartString(getName() + " " + String(m_nSensorValue));
}
Sorry. That part I got. It was the voltage name that threw me off.
It seems as if you know a lot more than what I do? Did you manage to get this working? I’ll gladly fire up my PC at home to share “my” sketch if necessary.
@949BFN Hendre,
I do not yet have this fully working. What I have is two ultrasonic sensors and two 5v relays working on a single NodeMCU board. I use a modified version of ST_Anything_GarageDoors_ESP8266WiFi sketch I have made no other code changes - yet. After the above dialogue with @ogiewon I am attempting to follow his lead and use as much existing code as possible and understand if I make changes the best place to make them. Ideally I will only modify the sketch.
The in process sketch creates four children due to two separate calls to PS_Ultrasonic and two calls to IS_DoorControl. The door controls work however the status on the door controls is not integrated with the status of the sensors. The sensors read distance accurately in cm using the voltage type as @ogiewon said it would.
More to come as I stumble through this. @ogiewon - this is amazingly powerful stuff!
Post withdrawn
Hi, I have not yet installed this to my SmartThing.
But I have a lot of arduino and have been a user of smartthings for many years.
I have a water tank that I want to have 4 sensors, each sensor is connected to my arduino.
From there I can have 4 LED indicating status of water level.
But as I understand from this thread, I can get this info directly I to my SmartThing?
How will it look inside my ST app?
Can I use it inside ActionTiles also?
Can I make my own icons and symbols inside the ST App to visual indicate a water tank?
I can’t find any screenshot from the app.
Thank you for all help.
@ogiewon - Dan,
Could you give me some guidance. I am trying to create a child device handler and similar to your door control/contact sensor using an ultrasonic sensor instead of a contact sensor.
I have an esp8266 with two relays and two sensors. I can control the switches using your sample sketch and i can read the sensors using either the voltage or the ultrasonic sketch.
Where would you point me to create a combination that opens and closes the doors and reflects the status based on an ultrasonic sensor?
I love this platform and would like to get this to work.
Thanks
Curt,
Did you try following my instructions from earlier?
Dan,
Thanks. I probably jumped the gun on sending my last request out of frustration and should have been specific.
When I replace the contact sensor with the voltage sensor I do indeed get the open/closed value in the in the “child button” on the parent screen, however
- I lose the ability to press the button to open or close the relay and:
- The sensor value doesn’t refresh with changes to the sensor condition.
I have decided to clear out ST_Anything from my Smartthings IDE and reload it to ensure I haven’t messed something up in your code in my IDE. All of it shows unchanged but who knows what I might have done by now…
I really am fascinated by the creativity and grateful for all of your hard work.
I will let you know how I progress when I get a clean slate…
LOL - You’ve totally lost me with the above…
Please, one more time, please tell me exactly what you’re trying to accomplish? And why are ultrasonic sensors better than simple magnetic reed contact sensors? I have never had a false reading with the super basic reed switches.
Also, what buttons are you referring to? Why not simply keep using your garage door opener’s button?
I’ll gladly try to help, if you can help me to understand your goals and requirements.
Trouble getting ST_Anything to work
I’m trying to setup a real basic app to test turning on a LED on the board and also when contact has closed to have it notify the smartthings app
I’ve followed through these instructions,
https://github.com/DanielOgorchock/ST_Anything
I’m using
board - NodeMCU ESP-12E
sketch - ST_Anything_Multiples_ESP8266WiFi which I commented out the extra sensors I didn’t need,
I’ve gone through the setup and config for Arduino and smartthings, imported the ST_Anything from github,
I set up my device on smartthings ide using Parent_ST_Anything_Ethernet as the device handler like the example
configured it on my android phone with the ip,port, mac address and number of buttons
I tried setting up with 1 button and 2, not sure if I need multiple
This is what my app looks like
I did notice that when I click refresh that the serial monitor for the ESP-12E receives a refresh command
It doesn’t set any buttons up and I am lost on what to do next, it just doesn’t appear to be working for me.
not sure if I missed a step.
Thanks for any help someone can provide.
Steve
I’d need to see your sketch to see if your edits are correct. Based on what you stated above, number of buttons should be zero.
//******************************************************************************************
// 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”
//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid = “”; // <—You must edit this line!
String str_password = “”; // <—You must edit this line!
IPAddress ip(192, 168, 0, 91); //Device IP Address // <—You must edit this line!
IPAddress gateway(192, 168, 0, 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, 0, 1); //DNS server // <—You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on
// Smarthings Hub Information
IPAddress hubIp(192, 168, 0, 101); // smartthings hub ip // <—You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port
// Hubitat Hub Information
//IPAddress hubIp(192, 168, 0, 143); // hubitat hub ip // <—You must edit this line!
//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(“temperature1”), 15, 0, PIN_TEMPERATURE_1, false, 10, 1);
//Interrupt Sensors
static st::IS_Contact sensor3(F(“contact1”), PIN_CONTACT_1, LOW, true);
static st::IS_Button sensor4(F(“relaySwitch1”), PIN_BUTTON_1, 1000, LOW, true, 500);
//static st::IS_Button sensor5(F(“relaySwitch2”), 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(&sensor3);
st::Everything::addSensor(&sensor4);
//*****************************************************************************
//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();
}