[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

I fixed the code comments to include the required F() around the name of the device. Sorry about that!

I am able to send the preferences/settings in the device handler from ST back to the sketch and parse them. I have just one more step I am struggling with.

Instead of putting everything in the sketch, Iā€™m trying to put everything into a library similar to all the other devices but my library needs to be able to call the beSmart() function in the rgb library. I tried adding a parameter to the constructor in the sketch passing the reference to the rgb executor but I canā€™t figure out what type it would be or how I reference the pointer in my custom library.

static st::PS_Ultrasonic sensor1(F(ā€œultrasonic1ā€), 60, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E, &executor1);

Is there an easy way to make the refresh a little longer, say 30 minutes? 5 minutes just seems a bit excessive as far as network traffic goes. If itā€™s not a one-line type change, then donā€™t worry about it.

Just edit ā€œconstants.hā€ in the ST_Anything library. Within that file, you can choose to disable the automatic refresh, or adjust the timing of it.

OK, sounds like youā€™re making some progress, but I am a little confused now. You have two ST_Anything devices defined in your sketch, correct? One is the PS Ultrasonic sensor, and the other is an EX RGB light?

Now, what are you sending from ST to the Arduino, and which of these devices needs to receive it? The Everything Class is designed to take anything sent to it from SmartThings, look up the device by name, and then call that deviceā€™s beSmart() function.

Using the pair of callback functions in the sketch is how ST_Anything is designed/architected to accomplish local device-to-device interactions. It is easy to call another deviceā€™s beSmart() function by simply ā€œsending a new name/value pairā€ to Everything from within the callback function, as shown below.

st::receiveSmartString("rgbSwitch1 on");  //use same strings that the Device Handler would send

Just change the ā€˜onā€™ to whatever youā€™d like and let Everything take care of it for you.

1 Like

The cabinet will be powered via a contactor, which is controlled by the Arduino. The whole process is within the sketch, without any inputs from Smartthings. I only added st_anything for monitoring in the Smartthings app. :slight_smile:

1 Like

I assume itā€™s this:

static const int DEV_REFRESH_INTERVAL=300;

Correct. The comments are pretty self-explanatory in the constants.h file.

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

Is it possible to bind a device to a variable instead of a pin?

Lets say I use touchRead to get a value. Depending of what the value is I want to set e.g a contact as open or closed.

I would recommend you simply create a new ST_Anything library Device Class that supports touchRead instead of using a standard pin. That is how we designed this library to be used. We encourage users to contribute additional devices to the project in the form of new device classes.

Sending the string directly made things so much easier. The only thing I added to your suggestion was an extra parameter to the constructor in my library referencing the name of the other device.

static st::PS_Ultrasonic sensor1(F(ā€œultrasonic1ā€), 60, 300, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E, ā€œrgbSwitch1ā€);

Then I use that variable when I send the string so Iā€™m not hardcoding anything in the library.

st::receiveSmartString(m_nRgbSwitch + " 000000");

However, I did run into a few other problems.

st::Everything::run() uses st::PollingSensor to determine the polling frequency of the sensor. I can easily increase the frequency of the poll by changing the second parameter in the sensor constructor to one second. But, when the polling library was written there was probably no reason to assume that the polling would ever be run more frequently than once every second. However, I need it to run about five times per second. The st::PollingSensor constructor accepts the interval parameter in seconds and converts it to milliseconds so I passed in 0.2. But, the interval parameter is defined as long which doesnā€™t accept numbers with decimals. So, I went through the st::PollingSensor library and changed the interval parameter type to float instead of long.

The second problem I have is that beSmart() in both of my libraries wants to update the hub every time it is called which a problem when I am calling it five times per second, so Iā€™m working on adding a second interval parameter to both of the constructors. One interval will be for my local sub-second poll, and the other will be for the frequency of sending updates to the hub.

1 Like

Iā€™m still not clear how this callback works. Iā€™m almost done with my intercom project. Audio/Amplifier/Relay/button sensing all working as in the arduino sketch. Now I want to add the ST part. right now I have a loop that scans the buttons and sets the relays.

With ST integrated I want to use ST to log messages about what buttons were pushed. Okay, these are not ST buttons, but rather analog voltages on the Analog pins. These needs to react fast for the intercom to work without lag. I want to be able to set up some ā€œEnablesā€ per channel via the ST device app to control the behavior somewhat? Any pointers?

my loop looks like

void loop () {
scan_buttons;
set_relays;
}

When the buttons are debounced, I set an array B[15][5] with value 0, 1, 2, 3, 4. for channel B[i] where
0 is no button pressed, 1 is button 1 pressed, 2 is button 2 pressed , etcā€¦

set_relays with use that information to set the channel relays as needed.

OK, I have an idea of what youā€™re trying to accomplish, however I am missing how SmartThings plays a role in this.

If you want a custom sketch (and it sounds like you do based on what I have read above), youā€™ll probably simply want to ADD some SmartThings capabilities to your sketch, versus trying to use ST_Anything.

ST_Anything is an application framework, that assumes you are attaching standard devices (temperature, humidity, luminance, relays, etcā€¦) to the microcontroller. ST_Anything then takes care of the rest, making it much simpler to integrate with SmartThings/Hubitat.

Underneath, ST_Anything is using one of my various ā€œSmartThingsā€¦ā€ communications libraries (example sketches are included with those microcontroller specific libraries) in order to integrate with SmartThings. Adding one of these libraries to your existing sketch may be the simpler way to go, especially since it sounds like youā€™re a programmer.

What youā€™ll need to decide is how youā€™d like to have your microcontroller appear within SmartThings, using standard ST Capabilities (e.g. switches, buttons, temperatures, etcā€¦) Once you figure that out, I can provide some more guidance. If it is as simple as logging button presses, that is pretty darn simple. These would easily map into the SmartThings ā€œButtonā€ Capability. Youā€™d probably want a SmartApp to monitor the button presses and perform any ST actions desired. webCoRE, for example, could handle this.

This is similar to what I am doing in that all of my functionality has to be local becauseā€¦lag. I am using ST to be able to monitor the sensor (on a much less frequent basis than it is being read in the sketch) and to be able to update some of the parameters I am using in my sketch on the fly with device settings in ST.

In my current project, I am separating the local sensor polling mechanism from the ST polling interval in my sketch but it may be worth consideration to change how polling works in ST_Anything to allow for this with any device.

I hear youā€¦ however I think your use-case is pretty unique. That is why I recommend to users with special needs to simply add ST integration to their existing sketch. This is exactly how the original ā€œSmartThingsā€ library for the ThingShield was designed.

My son and I looked at the up-front frustration this caused for most users and built ST_Anything as a way to greatly simplify integrating sensors (like my homeā€™s pre-wired alarm contact sensors) with ST.

All of my ā€œSmartThingsā€¦ā€ communications library are based off of the original ā€œSmartThingsā€ Arduino library, and follow the original architecture. I did this to make sure users could still reference the original ThingShield documentation and example sketches produced by ST.

1 Like

Can you share some of your code?

Itā€™s not all there yet but it will be soon. Just look for the most recently modified files in the dev_Seth-Miller branch.

Dan,
Iā€™m more a hardware guy than a programmer. However, I can hack software to make it work. What I really want SmartThings to do is

(1) Log what buttons were pushed and what Channel. I.e. the Values of B[15:0] in the SmartThings device
(2) Ability to set boolean variable in the arduino from the App. I.E.
boolean channel_mute [4] = { FALSE, TRUE, TRUE, FALSE};

In the DTH, I would like 4 channel_mute ā€œvirtualā€ buttons.

additional pointer will be greatly appreciated.

thanks.

I was looking for arduino code examples in your branch but I didnā€™t see it. Can you point me to a specific file?

Look at Traffic Light in the libraries folder.