Announcing the "ST_Anything" Arduino/ThingShield Project

Hi Dan,

Thanks very much for all your work on ST_Anything! I am successfully using it to control 5 433MHz switches, based on your examples and documentation.

Now I’m trying to rework your RCSwitch implementation so that my 5 RF switches show up as individual things (similar to my light bulbs), rather than being controlled together through one ThingShield thing. The reason is that I’d like to control the switches individually through my Harmony remote, but as of now only the Arduino ThingShield device can be linked and I can’t control the switches individually.

I tried to clone the ST_Anything_RCSwitch handler, ST_Anything_RCSwitch Multiplexer SmartApp, and Arduino ThingShield device, editing each to manage only 1 separate switch; however, none of them work. The original (combined) version still works fine.

There are two log entries produced:
DEBUG: Executing ‘rcswitch1on’ = 'rcswitch1 on’
WARN: KEY: ZBLIB device.endpointId=null, device.zigbeeId=D052A8000D9B0007, device.deviceNetworkId=myswitch1, gitRepo: null, deviceType: MySwitch1handler, manufacturer: null, model: null

Is this even possible? If so, could you please point me in the right direction?

Thanks-
Eric

Here are the basic steps to using ST_Anything_RCSwitch:

  1. Load ST_Anything_RCSwitch.ino on your Arduino (requires all of the associated library files to have also been installed in your Arduino Libraries folder.) Sounds like you’ve done this already.
  2. Create a new “ST_Anything_RCSwitch” DeviceType Handler in the ST IDE (under Device Handlers) and paste in the ST_Anything_RCSwitch.device.groovy code. Save and Publish.
  3. In the ST IDE (under Devices), change the Device Type of your Arduino to your new “ST_Anything_RCSwitch” Device Type Handler from step 2.
  4. Create a new “Virtual Switch” DeviceType Handler in the ST IDE (under Device Handlers) and paste in the VirtualSwitch.device.groovy code. Save and Publish. NOTE: You must use my virtual switch device handler groovy code from my Githib repository.
  5. In the ST IDE (under Devices), create a new device (call it whatever you want) and assign it to use the “Virtual Switch” DeviceType from step 4.
  6. Repeat step 5 until you have created a virtual “switch” device for each of the Arduino’s real RC Switch devices.
  7. In the ST IDE (under Smart Apps), create a new Smart App called “ST_Anything_RCSwitch_Multiplexer” and paste in the groovy code from ST_Anything_Switch_Multiplexer.smartapp.groovy. Save and Publish.
  8. Using your phone/tablet, start the SmartThings app and “Add a new SmartApp” - select the “ST_Anything_RCSwitch_Multiplexer” app that you created in step 7.
  9. Configure the new smart app to use the Virtual Switch devices you created in steps 5/6. Configure the smart app to use the Arduino device you revised in step 3. Save the settings.

Try to get everything working with just the default three switches from my example code. Once you have that working, you should be able add the extra two switches to the sketch, device handler, and multiplexer smart app source code modules.

Basically, what is happening here is the following:
-Arduino reads real world data and sends to ST
-Events are raised in the ST_Anything_RCSwitch device
-The ST_Anything_RCSwitch_Multiplexer smart app sees these events, and in turn, updates the virtual switch devices with the current state of the Arduino’s inputs.
-Any other smart apps that are looking at the virtual switch devices will then receive an update and act accordingly.

Hope this helps!

Dan

Hi Dan, just got home and had a chance to try the modified SmartThings Library.

You are the “Man”, thank you very much,

the SmartThings Library with the Arduino Leonardo using the Hardware port, Serial1, works like a charm…

I believe for all the work you have done here , you deserve some compensation, and I am willing to make a contribution.

I would like to see the SmartThings Library, be capable being used with hardware serial ports with the Arduino DUE, the Teeny 3.2, and the Arduino 101

The SmartThings Arduino Shield is not the best form factor for a lot of projects, but it does have a reasonable price. It would be nice if the SmartThings group would offer the ( programmed ) ZICM357SP2-1 chip on a smaller breakout board, or a chip itself.

Again, Dan, Thank you for all of your efforts.

Ben

1 Like

Any Chance u could make mysensors integration?

Anything is possible, however I just don’t have the time to work on a MySensors integration at this time

You should probably start with one of the MySensors Arduino Gateway sketches and then tweak it to work with SmartThings. The real work would be on the groovy side of things. That’s really not my expertise.

Dan

@ogiewon Thank you for the great work. My application was to come up with a way to detect if doors in the house are open or close state as the house is pre-wired to a alarm system. So I was only interested in CONTACT sensor. I do not have other sensors available. So these suggestions are to help make life easier in anyone trying to do the same.

  1. I modified ST_Anything_Doors : This has predefined names such as leftdoor, rightdoor etc. This may not be generic to anyone who try to adopt the code, I wish if the code had names such as “contact1”, “contact2” so that it is easier to apply to any scenario without modifying the code. (Problem is modifications need to happen at 3 places, groovy for main code, groovy for multiplex, arduino code.)

  2. I got it to work through multiplexer and virtual device code so that I can use the open/close state to activate an alarm. That is all fine. May be there is a straight-forward way to implement without multiplex/virtual device. I am not a groovy programmer, but minimote device code has it implemented, within the device. Take a look at that code and see how they have implemented. In minimote device, you can press any button out of the 4 it has, and that press can be used to trigger an event. Minimote code Link here.

I had to do lot of trial and error before I could get it to work. I have build my prototype logic, and next is to install it into my alarm system. Your code was very helpful. I wish if ST provided a better code and samples to integrate into Thing Shield.

1 Like

Impressive job, well done!

1 Like

Dan,

First, thank you for all your hard work!
I have implemented your Doors and Windows project successfully. My current alarm system that I am attempting to replace, chimed whenever a door or window was opened. I am trying to replicate this functionality. Is there any way to pull a pin low on the arduino for a short interval every time a door or window is opened? Any help would be greatly appreciated.

Charlie

@rebelnme

Charlie,

Yes, I believe everything needed to accomplish this already exists within the library. I’ll take a shot at tweaking my Doors and Windows example to turn on a digital output pin for a second whenever any of the sensors sends an “open” command to SmartThings. Shouldn’t take too long…

Dan

@rebelnme

Charlie,

I have a working example sketch that utilizes a feature I call “local callback” within the Arduiono sketch to allow a developer to “listen in” on the traffic being sent to the ST ThingShield. By doing this, the sketch is able to determine anytime a door or window sends an “open” command to the ST cloud. Whenever that happens, the callback routine then is able masquerade as the ThingShield and “send” a command to one of the Arduino’s ST_Anything “Devices.” In this case, I have added a “TimedRelay” device that uses pin A0 as a digital output to fire a relay for 500ms. This would be used to implement your “chime” whenever a door or window is opened.

Take a look at the example found in my GitHub repo at https://github.com/DanielOgorchock/ST_Anything/tree/master/Arduino/Sketches/ST_Anything_Doors_Windows_wCallback

Please let me know if this works as expected for you.

One thing to be aware of… ST_Anything, by default, refreshes the status of every one of its sensors every 300 seconds as specified in the “constants.h” header file. If any door or window stays open for an extended period of time, the “chime” will trigger during these periodic status refresh cycles. If this behavior is not desired, you have a few options available.

First, simple uncomment the following line of code in constants.h to disable the periodic refresh logic:

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

Uncommenting the above line will solve the problem, but may lead to reduced data integrity should an update be missed between the Arduino and the ST cloud for any reason.

A second approach, which I have used previously, is to keep track of the previous value for each of the door/window sensors within your Arduino sketch. Use this information to determine whether or not a true change of state from closed to open has occurred, and only then execute the logic to trigger the chime.

Let me know how this goes for you!

Dan

Dan,

Thanks again for all the hard work. It worked great. I did add state change but only for doors, since I do leave the back patio door open now and again. Now I am actually working on being able to send an open/close signal back to the arduino from smartthings. This would allow me to send the chime from my garage door which is on a wireless sensor.

Charlie

1 Like

To have ST send the “Chime Request” to the Arduino, all you need to do is add a “switch” tile to your Device Handler and make sure the name it uses is simply “switch”. Take a look at my ST_Anything.device.groovy for an example of a Device Handler which implements the Switch Capability. You’ll need to add the following, IIRC:

  1. capability statement near the top for “switch”

  2. The tile for “switch”

  3. and the “on()” and “off()” functions

This will allow anything within SmartThings to then turn on your “chime” switch, which is really implemented as a TimedRelay within the Arduino. It will also turn off automatically and update the ST Cloud with the correct status.

Dan

Dan,

The switch works great, thanks. I really appreciate all the help in being able to swap my existing alarm over to smart things. I hate to even ask anything else, but I do have one other question/problem. At random times, doors or windows will show open and then instantly closed. Last night it was the back door opened and closed at 11:19 pm waking me up as if there was an alarm. This is the second time this week. I have gone through the history of all the doors and windows and it seems to be random which window or door and the time. Just so happened twice while I was sleeping and once while at work. Do you know if anything that might cause this problem. I have gone through all the wiring looking for lose wires, check the power supply and anything else I can conceive.

Sleepy,
Charlie

Charlie,

Sorry to hear about the false alarms. I have not seen this behavior in my setup, however I also do not have any audible alarming configured. No one else, who has used my library, has reported this issue.

On suggestion I have for troubleshooting is to disconnect the field wiring from the Arduino, and simply add a jumper to ground for each and every door/window pin to make sure they are all “closed”. Then, give it some time to see if the problem occurs. If not, then you have a field wiring, sensor device, or power supply problem.

Dan

Hi Dan,
Your “ST Anything” Arduino/ThingShield Project is great - and addresses exactly what I’ve been wondering about. My home has a disused alarm system, and while I’ll be ripping out the bulk of it, I wanted to make use of the various sensors. A couple of days ago, I picked up an arduino mega clone and arduino shield, and using Kendrick Coleman’s “Noob Guide”, I was able to get things working for door contact sensors. The old system also has a couple of motion and smoke detectors. Assuming I adjust (if necessary) for voltage differences, is it reasonable to treat these as if they were ‘doors’? Or do I need to treat them as different device types?
Thanks in advance for your reply!
Bob

Bob,

Check out my ST_Anything_Alarm_Panel.ino example sketch which I helps another user develop to replace an alarm panel like yours. It includes support for smoke detectors.

Dan

Dan,
Actually, I looked briefly at the ST_Anything_Alarm_Panel.ino example. I also saw that there was a matching device handler created (ST_Anything_Alarm_Panel.device.groovy). Sorry for a dumb question, but I assume I’d also need a corresponding multiplexer SmartApp, and I haven’t been able to find that. Nor do I see a virtual device handler for a smoke detector. Or can something else be used?
Bob

Bob,

You should be able to easily merge pieces and parts from the various samples (Arduino and Groovy) to create a custom solution for your home. That was always the intention of this project…to enable users to easily use an Arduino with SmartThings to solve home automation problems, without having to worry too much about the gory details of the code.

So, you should be able to create your own multiplexer app based on the various other ones that already exist. Additionally, creating a Virtual Smoke Detector Device Handler should only take a few minutes if you simply use the other virtual device handlers as samples.

If you get stuck, let me know and I’ll try to assist as my schedule permits.

Dan

Hi Dan,
No problem - I didn’t see the point of ‘inventing the wheel’ if it already existed. Since this is all completely new to me, I don’t know what I don’t know. But I’ll dig into it. If I run into a wall, I’ll let you know.
Bob

1 Like

Another option is to put a relatively high value in the parameter that determines how many times it has to see a state change before it reports it.

1 Like