SmartThings Sonoff-Tasmota Device Handler

2,230 views
Skip to first unread message

Brett Sheleski

unread,
Apr 27, 2017, 12:04:40 PM4/27/17
to SonoffUsers
After getting my first Sonoff I flashed it with Tasmota and ended up wiring it to control my basement lights (with the existing 3-way switch connected to GPIO 14 to not break existing functionality).  So far so good.

I wanted to get it tied into my existing SmartThings ecosystem but didn't see any SmartThings device handlers through my use of the Google.  So I decided to create one.

For anyone else interested see the device handler below:


So far it is able to poll for the current status of the Sonoff, and turn it on and off.  That's all I needed for my use-case.

Time to buy more Sonoff's!

Mike Gilmartin

unread,
Dec 30, 2017, 1:31:21 PM12/30/17
to SonoffUsers
Hey Brett,

Thanks for sharing the device handler.  I've been going back and forth for months on replacing my ST Hub with an open source custom solution.  Mainly because the ST app seemed limited and basic.  First I went thru a ton of 3rd party apps....found Stringify which worked great albeit a tad buggy on Android but the developers seemed to be squashing bugs fast.  Then...to my horror....Comcast bought them and development has slowed considerable. Also, unsure if ComCast will even allow me to use it a year from now. I also liked the idea of running my own server to get rid of cloud lag at least while home....do not care so much if routines are running with some lag if I am away.  After many months of learning one new technology/language/hardware after another I'm now leaning back towards keeping my Smartthings Hub.  The deciding factor was when I stumbled across the webCoRE SmartApp that lets me easily create any possible automation I will ever need without having to learn another language.  Which goes to show you....Samsung actually did a good job making an open system.  But now I have the reverse problem.  In my circular quest for an open source solution I've gathered a ton of 8266 based devices including Sonoffs.  Currently, I have a Raspberry Pi running an MQTT broker and Node-Red to control my Sonoff and other 8266 based chips. What I like about this system is it is super fast as it is all within my LAN. All my Zwave and Zigbee stuff is still on ST but my switches run locally on the hub (don't care about motion/door/window sensors).  So now I'm trying to bridge the 8266 stuff back over to SmartThings and stumbled across you device handler (DH). Your (DH) works great if I only use SmartThings to control the state of something like a Sonoff.  However, I have devices with a standard wall switch hooked up to GPIO 14 on a Sonoff running Tasmota but your DH does recognize when I toggle the switch (it eventually does when the hub polls the device but that can be up to 10 minutes).  Then I found the following Sonoff DH in the ST forum https://community.smartthings.com/t/release-sonoff-sonoff-th-s20-dual-4ch-pow-touch-device-handler-smartapp-5-10-smart-switches/45957.  He has a much more sophisticated Device Handler which includes a companion SmartApp that immediately recognize when I use the manual switch.  However, he is not using Tasmota but rather a very limited custom version of ESPEasy. I need his DH functionality but with Tasmota.  So my question is.....before I start down the path of learning Groovy and custom Device Handlers....have you ever looked at his code and considered upgrading yours so we have the best of both worlds.....instant ST integration with Tasmota?  I'm guessing the answer is probably no but thought I would ask before taking the plunge myself....yet another new language!. If indeed no then I'm sure I can figure it out.  Of course when I do I'll be sure to return the favor and share it with you and others. I've already learned quite a bit from your example and I kinda understand his (after reading a ton of Groovy documentation and other sources....he uses automatic device discovery...which I do not need.....and if I leave that out it might not be so bad).  However, near as I can tell that functionality is integrated with the good part.  Tx  Mike.

Brett Sheleski

unread,
Jan 2, 2018, 7:56:26 AM1/2/18
to SonoffUsers
I realize that turning the Sonoff on/off externally from SmartThings can cause a delay until SmartThings decides to poll the device again.  For me, I don't really care about the delay, but I can see how it may be more important to others.

Off the top of my head, I don't know of a simple solution.  

I suppose what could possibly be done is develop a SmartApp that can manually call the Poll() (I'd have it take any device that implements the Polling capability, not just Sonoff's. see: http://docs.smartthings.com/en/latest/capabilities-reference.html#polling) method on any assigned device(s).  Then expose the SmartApp with an HTTP endpoint that can be triggered from your Raspberry Pi.  Since Tasmota will trigger an MQTT message every time it is triggered, Node Red could be configured subscribe to the appropriate topic and make the HTTP call to tell SmartThings to Poll all assigned devices.

The above is kind of roundabout, but should do the trick.

There is also a SmartThings to MQTT bridge project out there on GitHub (https://github.com/stjohnjohnson/smartthings-mqtt-bridge).  I've used it a tiny bit and seems to work fairly well.  It may be possible to use this to manually set the state of a device.  If so, I'd setup something in Node Red to subscribe to the appropriate topic for when the Sonoff is toggled, and send off another message to set the state properly (or at least call the Poll() method).

BTW, I'd prefer to move this discussion to GitHub.  Please file an issue there (https://github.com/BrettSheleski/SmartThingsPublic/issues)

Cysix

unread,
Jan 14, 2018, 9:38:53 AM1/14/18
to SonoffUsers
https://github.com/stjohnjohnson/smartthings-mqtt-bridge works perfectly with SmartThings v2.  I'm using with with Home Assistant as the main user interface.  I have multiple Sonoffs used as switches, environmental sensors etc.  Home Assistant interacts with the Sonoffs.  I create dummy (virtual) switches in SmartThings and keep them synced with the Sonoffs through Home Assistant automation.
Reply all
Reply to author
Forward
0 new messages