[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

You definitely need the “AT Firmware” on the ESP-01 for it to work with the Arduino using the latest ST_Anything_Multiples_MEGAWiFiEsp.ino sketch. It also has to be wiried into pins 18/19 on the MEGA.

For me, I use:

  • You must start with the ST_Anything_Multiples_MEGAWiFiEsp.ino sketch as it is designed for this HW combination.
  • A dedicated 3.3v power supply for the ESP-01 module as I do not believe the Arduino’s 3.3v pin is really capable of providing enough current. I do tie the Gnd pins from both the Arduino and the dedicated 3.3v supply together so they share a common voltage reference.
  • ESP-01 running the AT firmware as verified by connecting it to a FTDI USB to 3.3v serial adapter. I never flashed the ESP-01 as I am really not sure how to make sure it is running the “AT Firmware”

Others are trying to get a reliable Arduino MEGA + ESP-01 combination working as well as shown below.
https://community.smartthings.com/t/announcing-the-st-anything-arduino-thingshield-project/9087/688?u=ogiewon

Very glad to hear it is working for you! Have fun!

Richard,

I have released v2.6 of ST_Anything which includes support for the ThingShield. Please see the details in the first post of this discussion. Hope this helps you solve the issue you’re having. I welcome the feedback!

OK, so I have looked at the code you provided as well as your initial comments. It appears you have tried to merge two of my classes (EX_Switch + InterruptSensor) into a combined class. I am sure that you could eventually get this to work, however there is a much simpler method to accomplish your goal of adding local control.

ST_Anything is designed to allow 99% of user customization to occur within the Arduino (.ino) sketch without having to change the ST_Anything library. The other 1% of the time is typically when someone needs to add a new device to the library (e.g. new temperature sensor, or new ST Capability.)

I do not believe you need to go through the trouble of adding a new device class. Inside the Arduino sketch is a function called “callback()” which can be used to implement local control very easily. This function is called whenever data is sent to the SmartThing cloud. This allows you, the user, to see what events have occurred within ST_Anything and to take local action if desired. Here is one possible example of how to use this function. As you can see, we will need to have defined two “button” devices and two “switch” devices. When a user pushes a momentary button, ST_Anything will send the data to the ST Cloud. The function below is called and it will toggle the value of the appropriate switch device.

Let me know if this makes sense. I have not tested this exact code below so you may need to make s few tweaks to get things working to your liking. Also, the below code ensures that ST receives the proper updates for the change in switch1 and switch2 states. Thus, you can change then locally or from ST and the value in ST will always be correct.

Another benefit of this method is that the “button” presses are still sent to ST where you can use them in other automation routines if desired. This is like having a custom Aeon Minimote made from an Arduino and some momentary buttons.

//******************************************************************************************
//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.
//******************************************************************************************

int val1;     // variable for keeping local copy of the switch1 current state
int val2;     // variable for keeping local copy of the switch2 current state

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


  //NOTE:  you may need to play with the logic below to get the behavior you desire!!!
  if (msg == "switch1 on") { val1 = 1};
  if (msg == "switch1 off") { val1 = 0};
  if (msg == "switch2 on") { val2 = 1};
  if (msg == "switch2 off") { val2 = 0};
  
  if (msg == "button1 pushed") {
    if (val == LOW) {
      st::receiveSmartString("switch1 off");
    }
    else {
      st::receiveSmartString("switch1 on");
    }
  }


  if (msg == "button2 pushed") {
    if (val == LOW) {
      st::receiveSmartString("switch1 off");
    }
    else {
      st::receiveSmartString("switch1 on");
    }
  }
  
  //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
}

What do i need to remove from code to allow Alexa to control my ST ‘Routines’

I’m guessing the # include door control in the ino firmware?

And more lines in the device handler?? I know Amazon won’t allow Alexa to touch anything with door control…

It would be cool to be able to speak “I’m Home” to trigger ST routine to DISARM my current setup (i am not using any smart door control devices)

Thanks!!

You should not need to change any code in order to allow Alexa to control the Child Devices.

Have you gone into the “Amazon Echo” SmartApp in your phone’s SmartThings app and added the new devices that you’ve created? The Echo/Dot can only control devices that are “Switches”, “Thermostats”, or “Locks”.

So, from one of my stock “ST_Anything_Multiples” examples, you should see the alarms, switches, and relaySwitches. That’s all that Alexa can turn on or off. Alexa cannot interact with the other sensors.

Once you select those, be sure to ask Alexa to discover your devices. This is the only way to add new devices to Alexa.

If you want Alexa to run SmartThings Routines, that has absolutely nothing to do with ST_Anything. There are numerous community discussions devoted to Echo/Dot integration with SmartThings. I am sure you’ll have better luck in those threads.

Yes, it looks like it’ll only interact with my ALARM (relaySwitch) and not my ST “Routines” i have in place…

I’ll check the other forums!

Thanks!

Thanks for the info, now my question is:
If the switch is toggle type would work this code?

For a toggle, the code would need to change to a slightly more simple version. However, please realize that if a “switch” has been turned off by the local physical toggle switch, you will still be able to turn it on via ST. To turn it off via the physical switch, you will need to toggle it on and then off again. That is why most people use momentary buttons, not toggles for local control.

Here is an example of the code.Again, I have not compiled or tested this. Please note that I switch from “button” devices to “contact” devices as they are more appropriate to be connected to a toggle switch.

//******************************************************************************************
//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


  //NOTE:  you may need to play with the logic below to get the behavior you desire!!!
  if (msg == "contact1 closed") {st::receiveSmartString("switch1 on");}
  if (msg == "contact1 open") { st::receiveSmartString("switch1 off");}
  if (msg == "contact2 closed") {st::receiveSmartString("switch2 on");}
  if (msg == "contact2 open") { st::receiveSmartString("switch2 off");}
  
  //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
}

My friend thanks for your collaboration, he solved the issue with the following code.

Simply implement a flag to know what to do when switching the switch regardless of whether it is open or closed, this is the code.

void callback(const String &msg)
{
  //Uncomment if it weould be desirable to using this function
  Serial.print(F("ST_Anything_Miltiples Callback: Sniffed data = "));
  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed

  if (msg == "contact1 closed"){
      if(flag1 == 0)
          st::receiveSmartString("switch1 on");
      else
          st::receiveSmartString("switch1 off");
  }
  if (msg == "contact1 open") { 
      if(flag1==0)
          st::receiveSmartString("switch1 on");
      else
          st::receiveSmartString("switch1 off");
  }
  if (msg == "switch1 on")
      flag1=1; 
  else
      flag1=0;

if (msg == "contact2 closed"){
      if(flag2 == 0)
          st::receiveSmartString("switch2 on");
      else
          st::receiveSmartString("switch2 off");
  }
  if (msg == "contact2 open") { 
      if(flag2==0)
          st::receiveSmartString("switch2 on");
      else
          st::receiveSmartString("switch2 off");
  }
  if (msg == "switch2 on")
      flag2=1; 
  else
      flag2=0;
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line(s) as you see fit)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

Gracias por su ayuda.

De nada.

Have fun!

Hi Dan,

I can’t find the button child DH from the github. Where can I find it?

Thanks,
Jess

Jess,

There is no “Child Button” Device Handler. The Parent takes care of simply raising the “Button Pushed” and “Button Held” events to the rest of SmartThings. In the Parent’s “gear” configuration page, you can configure the number of buttons to match the number of button you created ion your sketch. Then it is simply a matter of pointing other SmartApps (e.g. webCoRE) at your Parent Device.

I have a Aeon Minimote, who Device Handler is nothing but a single icon. I didn’t think it was really worth creating a Child Button Device Handler as I did not know what I would put in it. Do you have any ideas or a specific use case? If so, I am sure I could whip something up.

Dan

Dan,

I found that I only need the switch DH, not the button. All good now.

Cheers,
Jess

1 Like

Dan,

This is just what I’ve been looking for!

Thanks for all of this!

Any chance of using the Native ability of the NODEMCU to get its IP Address from the DHCP Server?

Looking at SmartThingsESP8266WiFi.h it seems to be hardcoded to require the IP Address to be typed into the sketch.

Is there a specific reason that you had to implement it that way?

Thanks again for getting this to work!

treborjm

Rob

(It’s Robert backwards)

Robert,

Thanks! Yes, the reason I hardcode the NodeMCU’s IP address is because the current design needs to know the address and port to send data from the ST cloud, through the hub, to the device on your home network. DHCP would not guarantee the address would not change. Of course, you could use static DHCP address reservation in your router, I suppose. That would require a minor code change to implement.

I figured most people need to customize the sketch for their particular use case, so why not make sure you set the network settings to make sure they don’t change?

Happy to discuss your use case, and make revisions if necessary.

Dan

Hey Dan,

Any news on ws2812b led support in the future? Any way I can help out?

Dan,

Thanks for getting back to me so fast!

I totally get it… It makes sense to keep the code like that.

I do keep the IP all of my devices static, using my DHCP server to assign those addresses. DHCP has a record of the addresses that I have assigned to MAC.

How much trouble would I cause if I changed the code in the esp8266 dot h file??? Was thinking of removing the arguments for the IP, gateway, DNS, and subnet. I’m sure that there’s a dependency associated somewhere. Currently, it’s working… but I have several other ESP’s to add. Changing the code for each ESP is necessary. <edit: well, actually for each different contact or sensor, so… I guess I really I’d need to have different code for each ESP anyway.>

I am by no means a master coder… I am certainly dangerous when it comes down to it. So, if you think that I’m headed down a treacherous path, lead me away.

Thanks again Dan!

Sorry, no news on LED support at this time. I have been consumed with other development activities as well as life in general.

If you want to take a stab at adding LED support, I suggest you start with one of the existing ST_Anything C++ classes and make a new one that supports everything you’d like to do. You’ll then need to add a new Child Device Handler on ST side, as well as changes to the Parent Device Handler.

Rob,

So, it is pretty easy for me to remove the requirement for a static IP address. I am planning on adding support for more Arduino Ethernet and WiFi shields very soon to the “SmartThings” communications library. I will add a new constructor to the ESP8266 WiFi class that does not require the static IP settings. This will then result in DHCP working. By adding a new constructor, everyone’s old code will still work, and you’ll have the flexibility to use static DHCP IP addressing from your router.

How does this sound? I should have something ready for you to test either tonight or tomorrow night.

Dan