Announcing the "ST_Anything" Arduino/ThingShield Project

arduino
esp8266
thingshield
dth_misc
alarm

(Dan) #379

Why not just bypass the Arduino and hub altogether, and just connect directly to the ST cloud? Since the wemos are just ESP-8266 boards, with wifi, they can directly connect without having to use the ThingShield.

There are numerous examples here in the forums of people doing exactly this.


(David P.) #380

So I had another Idea for the thingshield and a project.

I have an old garage door opener just like my current one. It accepts signals from Homelink (which seems to be prolific anymore)

I was thinking of either using its board, or finding something smaller that could receive teh signal from one of the other buttons on my homelink to use it as a “goodbye” or “I’m Back” trigger?

The wife plays along with this stuff but she would never use the phone app, but pushing a button in her car when she leaves to make sure everything is off she would do. I realize its not perfect since im talking about a toggle but… Something to use another homelink button for at least :wink:

Edit: One step closer:


(Ben Wolodko) #381

Hi Dan,

I am currently out of town, back on the 18th of June,

I would really like to try the Smartthings library with Leonardo Hardware serial port support.

I picked up a bunch of the Tinkerkit TKLCD devices that sport a LCD screen as well as aAtmega32u4 cpu, and a form factor to be mounted on a panel, for LCD viewing.

the connections on the back of this device are molex type connectors that allow wired connection to serial, I2C, DI/O and AI/O devices.

The decision to purchase these devices, was partly based on your header file discussion on memory, and the use of Hardware serial ports.

I read the Arduino Leonardo page with them stressing the separate Hardware serial port, with Debug happening with the USB port. The other part was the form factor to be able to mount the unit, and have a local LCD readout. More memory that the UNO, better form factor for me than the Mega , and a hardware serial port. a winner in my terms …

Anyway, It is very capable of doing what I want to do, except for receiving data on the RXD line.

Dan, If you have a webpage that I could make a donation to I would gladly. I feel Smartthings should be doing this type of library / code interface work, but for many other platforms.

If there was code where the “library” or call was just the data to be sent or reecived, by smartthings and the programmer, had to explicitly set

what the serial port was called i.e “Serial1”, and what pin numbers were TXD, and RXD, , as well as the baudrate and its associated parameters

this could be used by may other micros.

That being said, I would like to try the Smartthings.cpp and .h files that support the Leonardo with hardware serial port.

Thank you for your efforts, they are much appreciated

Ben


(Dan) #382

Ben,

What you’re asking for is exactly what my version of the ThingShield library does. You can either use a SoftwareSerial port by calling the exact same constructor as the regular ThingShield library and simple pass in the Rx and Tx pins ( but only certain pins work!). Or, you can call my Hardware Serial constructor (as shown above) and just pass in the proper enum for HW_SERIAL1, 2, or 3.

Dan


(Daniel) #383

Hi Dan Ive been reading all the related posts and I found that ST hub doesnt allow UDP communication, also I found some projects of ppl sending commands on the LAN but they are not able to pull the sensors status. For that reason I think that is better to use the shield to communicate with the hub. In order to do that I used the Wemos to send the sensors status wirelessly to a Wemos receptor " wemos wireless comm" and then I transfer the values to each imput of your Anything project. (It is working well but is not efficient enough)


For that reason I would like to improve the performance and time response by conecting the Wemos receptor to your anything module trough I2C. Do you think that is possible to modify the sketch of teh anything module to get the data directly to the variable rather than from the GIOP if yes could you please explain me how to do it.

Thanks you
Dan Perez


(Dan) #384

Have you looked an example like the following yet? Direct esp8266 to ST cloud ( no hub). Just another idea.

As for using ST_Anything, you could just create your own class which implements your communications with your ESP8266 devices and then makes the correct calls to send the data to ST via the ThingShield.

However, if that is all the Arduino is going to be used for, I don’t know that’d bother using ST_Anything. Instead, just write your own simple sketch based on one of the examples provided by ST for using the ThingShield.


(Eric) #385

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


(Dan) #386

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


(Ben Wolodko) #387

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


(Joakim Olerius) #388

Any Chance u could make mysensors integration?


(Dan) #389

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


(BoruGee) #390

@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.


(kev dyer) #391

Impressive job, well done!


(Charlie Weeks) #392

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


(Dan) #393

@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


(Dan) #394

@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


(Charlie Weeks) #395

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


(Dan) #396

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


(Charlie Weeks) #397

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


(Dan) #398

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