[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Good question… There is no way currently to delay “turning on” the timed relay device. Under what circumstances would this be required?

I do have a somewhat creative solution, which involves using two timed relay devices in the Arduino sketch… In the “callback()” function of the sketch, you could wait for the first “timed relay” to go from “on” to “off” (you’ll receive a sequence of string messages like “relaySwitch1 on” and “relaySwitch1 off” in that callback() function which your code can “listen for”.) Once you see the on/off sequence from the first one, you could simply trigger the second one (i.e. “relaySwitch2 on”) by issuing a ‘st::receiveSmartString(“relaySwitch2 on”);’ command in the callback() function. This is the exact same command that would be sent by the ST cloud, via your phone app, if you pressed the relaySwitch2’s main tile.

The reason I say you should look for the “relaySwitch1 on” and “relaySwitch1 off” sequence to occur in that order BEFORE calling ‘st::receiveSmartString(“relaySwitch2 on”);’ is because ST_Anything updates all device statuses every 5 minutes, even if nothing has changed.

Does this make any sense to you? If not, I can whip up some sample code that might help explain it better.

You can also perform delays in SmartApps like webCoRE which might be a simpler solution, although the timing will not be as precise.

If you could explain your use-case, that would help determine the best solution.

Please do NOT add and delay() statements in your sketch of any of the ST_Anything library files. Doing so will cause communications failures as the Ethernet/WiFi libraries need to be called continuously. The network libraries are called with in the following command. In fact, this call is what processes all of the network and I/O checks/updates.

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}

Hey Dan, no I’m not yet using the latest version with OTA. A click on the little reset button resolved the situation, btw, so really not sure what is going on.

On a different note: you write that one should not use delay() as the network libraries need to be called continuously. Would it be possible to add a St_anything specific delay function that takes care of that?

If you need to perform a task every so many milliseconds, just use a traditional Arduino non-blocking method of performing timing using the millis() function. See the following for an example of a non-blocking Arduino timer. This technique is used within ST_Anything routinely to avoid blocking calls.

https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

Were you able to reproduce the double sending of voltage at the poll interval using my sketch on your MKR1000?

Sorry for the delay. I’ll try to load it on my MKR1000 this weekend and will let you know the results.

Hi Dan @ogiewon !
I have completed my security system integration based on your ST_anything code and wanted to share - What would be the best place for it? your Github WIKI ? https://github.com/DanielOgorchock/ST_Anything/wiki2

Also, I am trying to make a wall switch based on ESP-01 and a relay board, so any suggestions which sensor/executor to use? The idea is this - use an existing in-wall-toggle switch, to wire up it as a local contact to turn the light on/off, as well as turn the relay off/on via Samsung ST, plus monitor the state.
Something like this one http://a.co/hpq9iu8
I am able to control the relay via ST light automation app as :
Using IS_contact sensor as a trigger for relay
//EX_Switch arguments(name, pin, starting state, invert logic) change last 2 args as needed for your application
static st::EX_Switch executor1(F(“switch1”), PIN_RELAY_1, LOW, true);

It would be much better and cleaner to use ST_anything to do this task as well.
Any suggestions? Thanks in advance!

Sure, I guess you add something to the wiki. It’s empty now. Might as well use it for something.

As for the question about the wall switch… I am not sure what the question is. Using the EX_Switch is exactly correct.

If you’re trying to implement local control, take a look at the “relays with local control” example sketch.

Personally, I think you should stick with UL certified devices when dealing with high voltage (110/220 VAC) wiring. You don’t want to burn your house down.

@kampto After looking through your sketch in detail, I know exactly why you’re seeing the double voltage transmissions!

ST_Anything has a buit-in automatic refresh feature. This feature causes every sensor/device/executor defined in your sketch to update SmartThings every 5 minutes, regardless of whether or not anything has changed. The ensures that SmartThings is always up to date with current data. Imagine a scenario where you have a contact sensor device attached to a window. Most people do not use their windows in their houses very often. Thus, it might be days, weeks, months, or even years before a change of state is detected. Since ST is not 100% reliable, we decided we should send regular updates of data for every device in the system every 5 minutes (or 300 seconds) to keep ST updated in the event of a cloud outage/data integrity issue.

In your sketch, you set the polling interval for your voltage sensors to every 300 seconds. This is why you’re seeing double transmits.

If you want to adjust or disable the Auto Refresh feature, simply edit Constants.h in the ST_Anything library and modify the following line(s) of code:

//#define DISABLE_REFRESH		//If uncommented, will disable periodic refresh of the sensors and executors states to the ST Cloud - improves performance, but may reduce data integrity`




//Interval on which Device's refresh methods are called (in seconds) - most useful for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above
			static const int DEV_REFRESH_INTERVAL=300;				//seconds - Used to make sure the ST Cloud is kept current with device status (in case of missed updates to the ST Cloud) - primarily for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above

Hi Dan.
This is correct-I want a local control of that switch. (Want to use the rocker as button)
I am an electrical engineer and pretty good with the hardware part, but have a very little experience in the coding.
Do you mind to point me at a sketch example which you mentioned "relays with local control” ?
I would guess the ST control has to override a state of local control-so, I could turn of the light if needed. (Let’s say I turned it on and left the house).
Thanks!

Sure. Here’s the example to help get you started.

Yep that was it!! I changed the Constant.h refresh to 3600sec and polling is only once every 300sec as I set in sketch. This would also explain my house power mega+esp devices random publishing in between the poll interval. This is good timing because I’m about to deploy this thing 300miles away at my cabin where I can only make changes when I visit every 30days.
Is it possible to change the .h file to do the refresh in 300sec only if it hasn’t sent in the past 300sec?

So 2 things came up this months that would benefit battery operated devices:

  1. Lengthen the rissi send interval to 5min+
  2. Increase the Constant.h refresh to much more than 300sec. I Set mine to 3600.

Separate low power librarys? The possibilities will never end!.. Thanks again for your great work…

With the latest version of ST_Anything/SmartThings libraries, I moved the RSSI refresh interval to SmartThingsEthernet.h which is found in the SmartThings library folder. It still ramps up to this max time.

//Adjust the RSSI Transmit Interval below as you see fit (in milliseconds)
//  Note:  When the board first boots, it transmits frequently, then slows over 
//         time to the interval below.
#define RSSI_TX_INTERVAL 60000 

If you want to change the starting RSSI send interval, modify the SmartThingsWiFi101.cpp file in the SmartThingsWiFi101 library folder. Find the following line and change the ‘5000’ to whatever you’d like.

RSSIsendInterval = 5000;

If you want to change the ramp rate to get to your final RSSI target transmit interval, simply modify the folowing section of code.

				if (RSSIsendInterval < RSSI_TX_INTERVAL)
				{
					RSSIsendInterval = RSSIsendInterval + 1000;
				}

Hi,

I’m new to Arduino and SmartThings–I’m impressed by this project! I have an electronics background, but my C++ programming skills are rusty.

I have a test setup running with your ST_Anything v2.9 thank to all who support this project.

I’m looking to add something that I believe is pretty common for home security systems – Door open/close chime.

I’ve already created a basic function to emulate typical beeps using a buzzer, but now I will like to create a function that plays the buzzer tones when any door/window sensor changes state. Since my need does not necessarily need to go through the cloud, I was curious about how to implement either of the two options:

  1. The hacked way: Add a function under loop() that monitors any of the input pins that I will like to trigger the door chime, then the tones will play if there is a trigger. This will probably cause issues or may never work since the IOs of interest are being polled by your code.
  2. Using proper C++ (which I’m rusty on) : Figure out how to create a function that points to the memory pointers where you are debouncing the IOs (I believe this is the InteruptSensor function) and use that to play the door chime tones. I forsee a declaration such as doorchime(sensorpointers, Buzzerpinnumber) where sensorpointers is some kind of array that includes the sensor pointers, and the Buzzeroinnumber is where the “local” buzzer would connect to (someone may need to send this out to Smarthings also to enable a different connected device to play the tones).

I think option 2 is the correct path, but I don’t know where to start.

Any hints would be appreciated…

Thanks!

You most likely will want to add a TimedRelay device (“relaySwitch1l) to implement a chime. You can adjust the on-time/off-time/number of cycles to create a single beep, or multiple beeps. Once you have this working, you just need to activate it locally, within the sketch, whenever a door or window is opened.

The best place to catch these events is in the “callback()” function in the sketch. Uncomment some of the lines to show you what is being sent to the ST hub/cloud in the Arduino Serial Monitor window. Then, simply add some logic to catch messages that .startswith “contact” and .endswith “open”. Then, issue a st::everything::receive command with “relaySwitch1 on” which simulates receiving the on command from SmartThings. This will activate your chime/beep you created earlier.

All of this will be handled locally in the Microcontroller, with not cloud dependency.

Note: Please do not implement any dalay() commands, as those will screw up the ST communications.

Sorry for the late reply. What I am trying to do is trigger the remote for my car to start it. I need to lock twice followed by a 4 second start press.

I am new to coding and do not know alot but I will look into the callback function and see if I am able to figure it out. Thanks for your help!

James,

Let me know if you need some help. I think I could modify an example sketch for you pretty quickly if it would help. Just let me know the exact sequence needed (what pin(s), how long on and off, etc…)

Dan

Yes It would help. I have found the callback section you are talking about, but I am unsure how to use it. I need pin 14 to turn on 1 second, turn off 1 second, repeat once. After that completes I need pin 12 to turn on 5 seconds, then off. After that the cycle is done.

Okay, I’ll try to whip up something tonight or tomorrow. What microcontroller are you using? I a can create a sketch that should be pretty much ready to run for your application once I know that.

esp8266 Thanks Dan your awesome!

Dan,
ST_Anything is great. I have a couple in my house. I have added some custom code in some of them using the st call feature to drive some switch outputs based on local inputs. It works great, but as you are aware when internet connection is lost my ESP8226’s don’t work. I wanted to add a line of code that checks for an active internet connection (to the ST cloud) and if false then I can command the output pin locally using digitalwrite, can you advise on how you would recommend I accomplish this?

PS,
I work in the commercial building automation industry and your creation ST_Anything is very well thought out and implemented! Well done!

Dave