[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Appreciate the response…just want to confirm that these two are what I need:

  1. https://www.aliexpress.com/item/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/32529101036.html?spm=a2g0s.13010208.99999999.270.F0GzbW

  2. https://www.aliexpress.com/item/New-Relay-Shield-for-Arduino-WeMos-D1-Mini-ESP8266-Development-Board-WeMos-D1-Relay-Module-Free/32773079321.html?spm=a2g0s.13010208.99999999.262.F0GzbW

And just want to confirm that I have space on the Wemos D1 Mini for a push button and perhaps an open/close sensor?

Are they any wiring schematics to have a better idea of how this will look all together?

Thanks

A 12v relay won’t work with the D1 mini. You have to use a 5v or 3.3v. Remember that the relay is most often rated by it’s controlling voltage and the switched voltage. Any of these relays work with the D1.

Got it…thanks again!

In that case, I will order these two:

  1. https://www.aliexpress.com/item/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/32529101036.html?spm=a2g0s.13010208.99999999.270.F0GzbW

  2. https://www.amazon.com/Icstation-Channel-3V-Optocoupler-Development/dp/B01FK11HV4/ref=as_li_ss_tl?ie=UTF8&qid=1503174798&sr=8-2&keywords=icstation+3v+relay&linkCode=ll1&tag=konnected-io-20&linkId=b4310d1b35773f41b3273617b106988d

And I am guessing I can use a simple doorbell as my exit push button. Is this all I need? I do have a breadboard and breadboard connectors.

Is there any wiring schematic on how this will all be wired?

Thanks

If you give me a minute I can draw one up for you. Just hold on.

1 Like

I’m in a government building and they block aliexpress so I can’t verify for you here.

Based on the URL’s I would say yes.

I use a Wemos D1 Mini for a dual garage door setup with two relays, two door sensors, and threw on a temperature sensor just because I had so much space left. If I wanted I could also implement 2 of the the new car presence sensor that were just developed.

In short yes. The Wemos D1 mini exposes all available GPIO of the ESP8266. 10 of which can be used by the ST_Anything scripts: A0 and D0-D8.

Your gate motor should provide a 2-wire cable that would be wired to a switch. Connect the gate motor wire to the COM (common) and NO (normally open) terminals of the relay. Connect a momentary push button to COM and NO of the relay. Connect a open close sensor to D3 and GND.

Saw your latest post: I would use a waterproof button depending on how exposed this all will be.

Edit: I don’t see a way to setup a button into the door control script so I updated the wiring description.

For the pin defines use this
//Gate Door Pins
#define PIN_DOORCONTROL_CONTACT_1 D3 //SmartThings Capability “Door Control”
#define PIN_DOORCONTROL_RELAY_1 D1 //SmartThings Capability “Door Control”

Under Interupt Sensors use this
static st::IS_DoorControl sensor15(F(“doorControl1”), PIN_DOORCONTROL_CONTACT_1, LOW, true, PIN_DOORCONTROL_RELAY_1, LOW, true, 1000);

2 Likes

This is assuming you’re using the 3.3v relay and not the 5v and that you are going to power with a step down from 12v to 5v.

2 Likes

Thanks for putting this together.

I will go ahead and purchase these two components: D1 Mini & Relay

It will likely be a while before I receive these but in the mean time I am going to find and install the door strike.

I actually want to control when the push button functions…for instance, I don’t want it to operate in away/night mode. In that case, should I just wire the push button directly on the D1 Mini board? Instead of also connecting it to the relay?

Thanks

1 Like

I would connect to the D1 mini board and then add a line to your st_anything sketch for button. You can then control when that button does something through many of the different button apps or through WebCore.

static st::IS_Button sensor1(F("button1"), PIN_BUTTON1, 1000, HIGH, true, 1000);

You can find the details in the ST_ANYTHNIG Arduino library. This brings the button out as a regular button in ST. However, it won’t show up as child device like the door control or relay/contact would. It will be part of the parent device. (and all that will make sense when you set it up in ST.)

2 Likes

Looks like there’s a new wifi101 library which fixes some lock-ups… Hope it helps

2 Likes

Can someone shed some light on how to use the relay function but also have it sense if the thing being controlled is on?

Right now i’m rigging up an espresso machine that just needs a 5V pulse so that’s easy enough with the relay but then since it turns off, smartthings thinks it’s off too. So if using Alexa on echo, to turn it on and then off later, you have to ask her to turn it on twice.

Any help would be cool

I have used the times relay function in conjunction with a virtual device. Whenever the virtual device changes status (turns on or off) the timed relay turns on or off to toggle the device on or off.

1 Like

The TimedRelay ST_Anything device has no way to know if the device attached to the GPIO pin is on or off. It is designed to create a momentary button press type of solution. The code is designed to turn the output ON when it receives an ‘on’ command from ST. This output will stay active for a user specified period of time OR until it receives an ‘off’ command from ST. This allows ST to interrupt the TimedRelay sequence, to cut it short if needed.

If this behavior is not desired, you can create a separate version of the “Child Relay Switch” device. Simply change the name to something like “Child Relay Switch Custom” and then modify the off() function to do the exact same thing as the on() function. Save and publish. Then go into your list of Devices, find your existing device, and change it to use this new DTH.

Afterwards, you’ll be able to have Alexa “turn on” and “turn off” this device, with both commands simply causing the output to turn on momentarily.

Hope this helps!

Dan

That’s why i created a virtual device… The status of the virtual device is kept and the timed relay simulates a button press on a remote controller (literally in this case by using a hacked relay). Wasnt that what you were looking for @jpoppinmoneyunit?

@Ryan780 I definitely understand what you’re proposing. By using a Virtual Device, you can keep track of what might be the state of the actual device. Unfortunately, all it takes is someone pressing the button on the physical device to get the Actual State versus Virtual State out of synch.

My approach is very simple, and does not require any additional logic to tie the virtual device and ST_Anything Child device together.

Both approaches have there pros and cons. Always good to have options.

Oh… Absolutely. Mine is a light that has no other control than the remote which is now in the closet. So, no chance of it being any other way.
I’ve actually used it to control my RF controlled ceiling fan. It is hacky and doesn’t look pretty but it cost me less than $20 (much better than the 80 for the zigbee device from Home Depot). And it’s all thanks to ST_Anything.
What I don’t understand is how the child device type of switch would turn off after a period of time on the esp board? Wouldnt you also have to modify the sketch? See, you’re such an expert you forget how far ahead you’re thinking compared to us that are not so smart. :grin:

I also had a question as far as integrating servo control in ST_Anything. I have it set up on 3 different windows for control of my blinds but I would like to use the other pins on the board for motion sensors or contact sensor and whatnot and it seems that the easiest way would be integrating the servo into ST_Anything. This is the sketch. I know there’s a lot of junk in here about the webserver but I’m not really interested in that.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <Servo.h>

#define WLAN_SSID       "Caslerville" //change to your Wifi SSID
#define WLAN_PASS       "toomanysecrets" //change to your Wifi Password

MDNSResponder mdns;
ESP8266WebServer server(80);

int servoPin = D2; //Servo on GPIO0 or NODEMCU pin D3
const int buttonPin = D1; //manual button on GPIO12 or NODEMCU pin D6
int buttonState = 0;
int direction = 0;
int setting = 0; //Startup with blinds closed
int position = 90;
Servo servoA;

String webPage = "";

void setup(void) {
 
  delay(1000);
  pinMode(buttonPin, INPUT_PULLUP);
  Serial.begin(9600);
  delay(500);
  Serial.println("Blind Startup Sequence");
  delay(500);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);
  WiFi.begin(WLAN_SSID, WLAN_PASS);
  // Set a static IP (optional)
  //IPAddress ip(10,0,1,50);
  //IPAddress gateway(10,0,1,1);
  //IPAddress subnet(255, 255, 255, 0);
  //WiFi.config(ip, gateway, subnet);
  // End of set a static IP (optional)
  delay(500);
  int i = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    ESP.wdtFeed();
    if (i > 40)                                        // Try 40 times to connect to Wifi
      Serial.print("Restarting Wifi"); ESP.reset();    // Reset Wifi stack if more than 40 trys
    i++;
    WiFi.begin(WLAN_SSID, WLAN_PASS);
    // Set a static IP retry (optional)
    //IPAddress ip(10,0,1,50);
    //IPAddress gateway(10,0,1,1);
    //IPAddress subnet(255, 255, 255, 0);
    //WiFi.config(ip, gateway, subnet);
    // End of set a static IP retry (optional)
  }

  Serial.println();
  Serial.println("WiFi connected");
  Serial.println("IP address: "); Serial.println(WiFi.localIP());

  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }


void loop() {
buttonState = digitalRead(buttonPin);

if(buttonState == LOW && setting <= 180 && direction == 0){
  setting++;
  delay(0);
  if(setting == 180){
    direction = 1;
    }
  }
  
if(buttonState == LOW && setting >= 0 && direction == 1){
  setting--;
  delay(0);
  if(setting == 0){
    direction = 0;
    }
  }

if(position < setting){
   servoA.attach(servoPin);
   servoA.write(position++);
   delay(5);
     Serial.print("Setting: ");  
     Serial.println(setting);
     Serial.print("Position: ");
     Serial.println(position);
   }
   
if(position > setting){
   servoA.attach(servoPin);
   servoA.write(position--);
   delay(5);
     Serial.print("Setting: ");  
     Serial.println(setting);
     Serial.print("Position: ");
     Serial.println(position);
   }

if(position == setting){
  servoA.detach();
  }
server.handleClient();
}

(I’ve tried to pull everything I can find about the webserver that it has out since I wouldn’t need that with ST_Anything.)

What I’m really looking for is some direction on how to get it integrated with ST_Anything. I’ve gotten the beginning parts, I think. I’d have to create a new executor class and then reference that in the parent device type, correct? Are there any other references to the class? And I know I have to apply a factor of 1.8 to whatever dim level is set in ST. And I know i have to create a new child DTH like the child dimmer switch.

And that’s where I start to get lost. What sections of that sketch would I then have to put into a separate library for ST_Anything? I’ve tried looking at the EX_Switch_Dim but after about 10 mins my eyes go crossed and I get a migraine. :stuck_out_tongue:

So, any direction you might give me to start this on my own would be HUGELY appreciated. Or even if you could point me to a good how-to website that would start to get me on the right direction would be great. I know more than the average Joe on programming but by no means am I a coder (using Linux is still like trying to speak French…I can get by but can’t have a conversation). Thanks for any help you can give Dan. Again…you’re the best!

I should have said to modify a copy of the “Child Relay Switch” DTH.

The Arduino code always “turns off” the device automatically after running through the timing sequence.

So in my “solution”, you still cannot look at ST to see whether or not the physical device is on or off. But you can use Alexa to execute a timed relay cycle with more natural language.

I’m still not understanding how the device in ST’s would keep its status of “on”. When the relay shuts off by the timer it would turn off in ST, won’t it? If you want to track the status of the device (on or off) you have to have a virtual device, right? I don’t think I’m following what you’re saying.

I am also interested in an application with servos.

I want to make a add-on for my hvac registers so I can better regulate the temperature of each room.

Dan and Ryan, thank you for your input!

Dan, What you said is precisely what I wan’t to do. The espresso machine will most likely be turned on/off with either Alexa or the button and I don’t necessarily care if ST says it’s on or off, I just want the “Alexa off” to trigger the relay momentarily as well.

I will try what you said but my programming is pretty weak. The fact that I got this far is pretty amazing in itself. I’m just not seeing the off()/on() commands you’re talking about. Is it part of this? PIN_TIMEDRELAY_1, LOW, true, 3000, 0, 1);

Or do I need to go into the included <S_TimedRelay.h> library somehow?

Thanks again

Jake

1 Like