How to update a virtual device using the arduino library

I’m using a RFID reader (RC522 compatible) connected to an NodeMCU/ESP8266 and my intention is to have RFID keyfobs unlock the front door. I’ve created a virtual Button device on the Smart Things portal and my door lock is a zwave device that’s been working fine since day one. I’m using WebCoRE to unlock the door when the virtual button is pressed, and that works. My problem is, how do I get the ESP8266 to send the message to the hub that the virtual button has been pressed, especially when I’m not using a physical pin on the board?

Any suggestions?

Look at ST_Anything


I saw that. I figure that the solution would be using method send(), but I’m not sure what the message format would be and I’m not seeing any examples.

If you’d rather roll-your-own Arduino sketch, check out my ‘SmartThings…’ communications libraries. These libraries are used behind the scenes by ST_Anything to handle all of the network communications tasks between the Arduino board and the ST Hub. There is a ReadMe specific to the “SmartThings…” libraries, including a very basic On/Off example based on the original SmartThings ThingShield example.

Of course, I really believe you should consider using ST_Anything since it already supports the ST Button Capability. You could embed your RFID reader logic within the sketch’s loop() function, being sure to not use the delay() statement which causes the WiFi communications to be impacted. Then, simply set a Digital Output Pin to HIGH momentarily. Tie that digital output pin to a Digital Input pin being used by the ST_Anything Button Device. This will emulate a user pushing a physical button. You could also tie a real button to this same input for testing, or for local control.

You could also just send the properly formatted string of “button1 pushed” (IIRC) from within the sketch.

for example

st::Everything::sendSmartString("button1 pushed");
1 Like

I thought about doing that - tying one pin to another, but I’m out of pins for what I’m doing on the ESP8266. 5 pins are used by the RC522 and 3 pins by the RGB LED that I use for status. That leaves me short 1 pin to do that pin bridge.

I’m aiming for using the sendSmartString() method. I’ll update once I have it working.

1 Like

If you’re really tight on pins, don’t even bother to assign one to an IS_Button device.

All you really need to do is issue the ‘st::Everything::sendSmartString(“button1 pushed”);’ command each time your RFID tag is swiped.

On the ST Groovy side, just create the ST_Anything Parent Ethernet device, and configure it to have 1 button (along with the IP, Port, and MAC address.) No child devices will be created, as the Button Pushed event will come directly from the Parent Device. When the parent receives the “button1 pushed” string from the ESP8266, it will create the proper Button 1 Pushed event on SmartThings.

I was wondering if I’d have to add the sensor.

I did all that you said and it works great. Thanks for the assistance!

1 Like

Awesome! Glad to hear it is working.

I know it’s been a while since you posted this. I am just getting started with the Arduino IDE and ST_Anything, but have been working with SmartThings for a while.

I did get the 8266/RFID working.

Can you share your code on how you pushed those “open” and “close” messages to Smartthings?

I am hoping you can help me out. I am trying the Smartthings LED example for ESP8266. Everything compiles OK, but the status of the button in the app never changes, and in the IDE Logs, I do not see any received responses - also, since it will not toggle, I cannot get the LED to go on.

Should mention, I did confirm the IP address of my hub.


What is your ultimate goal? Knowing that may help guide the solution options available to you.

Please share a copy of your Arduino Sketch (with WiFi credentials redacted.) Also, which Groovy DTH are you using?

1 Like

Thanks for your response. I am attempting as the OP, to get an RFID device working. I have finally been able to compile it and run it inside of ST_Anything_Multiples_ESP8266WIFI.

I think all I need now is to know how to trigger the button or contact, so that SmartThings knows the even occurred (I would then use WebCore to trigger the action to open my garage door).

Also, would there be any way to pass the RFID ID back to SmartThings so that I know who’s fob triggered the event?

You’ve answered your question by quoting the line of code you’d need to execute above.

st::Everything::sendSmartString("button1 pushed");

This will send a button pushed event to ST, which can be used by webCoRE, or any other SmartApp, to take whatever action you’d like.

You can send whatever data you’d like to ST in the same way as above. Just use a different Button “Number” for each RFID tag.

st::Everything::sendSmartString("button1 pushed");
st::Everything::sendSmartString("button2 pushed");
st::Everything::sendSmartString("button3 pushed");

Thanks for the tip, when I run this command, I get:

exit status 1
no matching function for call to ‘st::Everything::sendSmartString(const char [15])’

Prior to this, I had to retype the command, as the quotes can in as special characters.

Sorry about the double quotes… I copied that line from above…

Try storing the command in a String variable, and the pass that variable into the sendSmartString command.

1 Like

yeah, I found you reporting that in the ST_Anything thread - thanks for all the help.

1 Like

Just wanted to follow up - everything is working perfectly now. I had not realized that buttons don’t need to be explicitly defined, which gives me back access to the pins (e.g. for LED Status lights for the RFID panel.

In fact, I was surprised that I get 32 possible buttons in WebCore, and both Pushed and Held - for a total of 64 unique RFID fobs that cab be assigned.

Thanks again for all your help.