Integrating Sonoff Mini with ST. My findings

I wanted to create a new topic dedicated specifically to the new Sonoff Mini as it has done my head in for the last 2 weeks.

I have been playing around with Sonoffs for a little while now, and I quickly got drawn to @erocm1231’s firmware and DTHs and have been using a couple of basics and a couple of THs and they work brilliantly.

I’ve just recently seen the new Sonoff Mini and thought it looks amazing for a requirement I have.
I want to use this in a light switch, this is different to the basic in that it has 2 terminals that you can connect to a rocker switch and change the state manually as well.

I bought a mini, have flashed it (not fun, I soldered some leads and did it that way!) with Eric’s firmware and it works but I lost the ability to use the switch terminals.

So for the first time, I decided to use Tasmota. I knew nothing about it but had read a little in Eric’s topic and figured it was worth a go.
Because I had put Eric’s firmware on the device, it made it very easy to flash it again with Tasmota through the OTA feature. ( I know the mini does have this feature out of the box but it looked a PITA)
with a little googling etc I found that Tasmota was able to utilise the switch terminals by setting GPIO4 to Switch1 (9).
Now I thought it was all sorted except I did not know how to get this integrated into Smartthings.
With a little more googling, I found @brettsheleski’s DTH and I thought I was nearly there. But, the instructions left me a little confused and I could not get it to work.

Following Brett’s instructions I had installed the 2 DTHs and had put in my IP address in the parent device but it would not spawn a child device so I kept trying and trying but couldn’t really get anywhere.
At this point I gave up. I reached out to erocm1231 to see if he could suggest a way of changing that GPIO on his firmware but unfortunately he doesn’t really support that firmware anymore (although he still seems happy to try and help people) so he suggested I try his forked Tasmota firmware but I would need a DTH.
I’m not really sure what the difference is between his firmware and Arendst’s original but I still could not work anything out.
I have created a DTH before but only something very basic, I certainly am not a programmer!
At this point I gave up again!

Today I picked it up again. I still have Eric’s forked Tasmota firmware on the device but in ST I started again.
I created Brett’s 2 DTHs in IDE again, created a new device and picked the Tasmota device type. In the app, I added the IP address and hoped!

Still nothing.

I ten thought I’d try and be clever. I started looking at the code on the Tasmota DTH and eventually worked out that the module that shows in the app for my device was 0 yet this was not listed in the DTH code. So I added 1 line at line 202 and typed “case 0: // Sonoff Mini”
In the app, I then opened the device again opened the preferences, hit save and found the child device had been created!

YAY it works!

I now have a child device in ST that controls the mini!
The only issue is that if I use the switch then it does not update the status of the device. Luckily Brett has a SmartApp for that. I will play with that tomorrow.

Now what I would like to do is create a new DTH that can do this all as one and not need to create a child device or have a SmartApp but to be honest this is probably well beyond me.

For now, it works and I am happy.
But I thought I would share my findings in case anyone else is thinking about using these devices or is currently struggling with them.

If anyone has any questions or I have not explained well then please let me know.

1 Like

I’m glad you got it working with the Sonoff Mini. I do not yet have any of these devices yet for me to test with. Please submit a pull request with the code modifications you did in order to get the Sonoff Mini working.


1 Like

Hello I have smartthings, and I have acquired some mini sonoff. I’m interested to know your dth

Hi Brett,
I haven’t forked your repository yet I just tweaked it in IDE.
I will do though and I will submit a pull request. Just need a chance to sit and do it.

If you want to adopt it in the meantime. I literally only added:
case 0: // Sonoff Mini
into line 202

Cheers for the DTH. Works well.

Hi Jose,
It’s definitely not my work. Credit all goes to @BrettSheleski.
His DTH is here:

Just read the readme file VERY carefully.

Then add line 202 as I described above.

1 Like

im seeing a problem and not getting the child to spawn.
I set up a NodeMCU with tasmota and tested that and it works fine.

I am getting an error when it tyes to run the reload section…

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:32: error java.lang.NullPointerException @line 137 (spawnChildDevices)

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:32: debug Module: [0:Sonoff Mini]

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:32: debug GPIO: [GPIO16:[0:None]]

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:31: debug createCommandAction(Status:0) to device at

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:31: debug REFRESH

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:31: debug createCommandAction(gpio:null) to device at

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:31: debug createCommandAction(module:null) to device at

f238384b-83c4-4e02-a5eb-0693db62a3e8 21:13:31: debug RELOAD

then I checked the iFan03 (which is device 71 (and yes the iFan02 is device 44 still) and I had the same error.

98311039-3b9f-4d2b-9dd7-16ffd452b5e4 21:20:38: error java.lang.NullPointerException @line 137 (spawnChildDevices)

98311039-3b9f-4d2b-9dd7-16ffd452b5e4 21:20:38: debug Module: [71:Sonoff iFan03]

98311039-3b9f-4d2b-9dd7-16ffd452b5e4 21:20:38: debug GPIO: [GPIO:Not supported]

So I need to see what is happening in the code, but I wondered if anyone had and thoughts!

BTW… module 0 is only temporary… this is the module you use to set a manual template. They might add a fixed template to the code later.
Also you need to be careful with module 0 because other templates can be manually uploaded to module 0.

Can anyone help me here. When I add the DH, there is already a line 202 with “case 0: // Sonoff Mini”. But when I add it, it still finds it as a “Module 1”

What am I doing wrong here?
Am I using the wrong Tasmota firmware?
I’m using the recomended sonoff-basic.bin. But it seems like you are using a homebrewd one?

I think I’m seeing the same problem. I fixed this by changing line 137 to
def moduleId = state.module.keySet()[0].toInteger();
replacing lines 311 - 314 with
My knowledge of groovy and TASMOTA ( is basic at best, so I don’t claim that these changes are correct, only that they appear to have worked for my Sonoff Mini’s. Your mileage may vary.

Pull request for these changes submitted to Brett

1 Like

@Anders_Dalsgaard I had this for a while, but when I used the template
{"NAME":"Sonoff Mini","GPIO":[17,0,0,0,9,0,0,0,21,56,0,0,255],"FLAG":0,"BASE":1}
it seemed to get correctly reported.

Hi there. I tried everything mentioned here, and nothing works in ST so far.

  1. I installed BrettSheleski’s Tasmota firmware
  2. I installed Brett’s updated device handlers
  3. I created the device as it says in his github

My device is shown as Module 0 in SmartThings app, and nothing triggers the creation of the child device.

Any advise?

Somehow it was created in the morning when I woke up.
Now I need to set-up the smart app

For clarification, my code example starts at line 200. So far, any other variation will not save without an error. Am not able to autodetect, so I naturally tried to input the ip address manually. Though it is recognized by the smart things app, the user interface is unusable, no toggle.

200 def headers = getHeader(userpass)
202 “case 0: // Sonoff Mini”
203 def hubAction = new physicalgraph.device.HubAction(
204 method: “GET”,
205 path: uri,
206 headers: headers

I have been struggling to get my Sonoff mini’s integrated with Smartthings. I been reading articles and blogs, and have made some progress, but I am still seeing flaky results. I loaded Tasmota v6 on the mini, and can get to the device from my browser. Within the browser the toggle works as expected as does the external latch switch (state change). I can manually add it to Smartthings via Sonoff Connect SmartApp. Sonoff Connect works great for other Sonoff devices (basic & r3), but not the Mini.

Is the template I am using causing me trouble?
{“NAME”:“Sonoff Mini”,“GPIO”:[17,0,0,0,9,0,0,0,21,56,0,0,255],“FLAG”:0,“BASE”:1}

Is there an updated Sonoff Connect SmartApp which is compatible with the mini DiY zapped with Tasmota v6 or better.

Thanks, Glenn

You are not alone. I am working on this as well, just don’t have the time to dedicate to this in depth. What may have to happen, is running mqtt on a pc or raspberry pi, to have the only real time update capability. Not a fan of this option but I’m new enough at this I may just have to learn something new again.

Hello fellow integrator!

I bought a couple minis and rather than flash and deal with all the backend pieces I did the following:

Setup with the Ewelink app.
Add them to IFTTT.
Control them with Smartthings/IFTTT integration.

I have a bunch of other Sonoff devices I’ve flashed but this works fine and all you have is an extra app to deal with and slight delay.

Hope this helps!

I did the same…but the delay is quite severe…5 to 10 seconds…so the solution for me only works in a non time sensitive situation.
Admit, I won’t bother with more minis until they are more user friendly…well, for me!

I have a mhcozy that utilized the eWelink app for my garage door opener. I quite simply connected it’s relay connection to my door bell button and voila, a google voice request through my bluetooth enabled motorcycle helmet and my garage door goes up 30 seconds before I’m home. In the case of flashing Tasmota to a few Sonoff Mini’s, I was hopefully integration to smartthings would be easier as other devices have been previously merged. I’m having to learn an awful lot at one time to make much sense of all this but I am motivated, having flashed Tasmota to a couple devices already, to eliminate the use of the eWelink app at all. DrZzs on youtube has done just that. He has an example of how to flash Tasmota to them, but doesn’t use smartthings to do it, so if I want to do this and make it work with a Tasmota Mini, I have to learn mqtt and Home assistant.

Agreed. Mostly my use is for several basement lights to voice command them all off when we’re headed upstairs and don’t have to go back through the entire basement for them to all get turned off. I also don’t want to wait two more months for this to be complete. So I’m working as fast as I can to get this finished.

I have been using Brett Shelski’s device handler for my sonoff mini’s and they have been working great. Make sure you also add the smartapp that polls the devices every minute. I find this acceptable since I rarely turn on the devices outside of smartthings automations. Detailed instructions are on his github page. The only thing that is inconvenient is the you will end up with two devices for each switch. One is a parent device that you don’t interact with and a child device which you would normally use for your automations. I created a room called “do not use” and put the parent devices in there.

Thanks for the feedback, it’s always good to know I am not alone. I have been through Brett’s page multiple times. He’s a god in this space, BTW. I loaded his two device handlers into smartthings, and added the Mini back in using the Tasmota handler. The screen in Smartthings is jumbled a bit, but it is pulling some information from the device (Tasmota ver, mac addr, ssid name, hostname, etc…).

Also, I noticed that Brett has this comment with regard to the power handler “For Sonoff-Basic, Sonoff-4CH, and Sonoff Dual devices this is required”. Is this required for the Mini too? If so, how do I configure the Mini to have a power handler device too?

I haven’t given up on the Mini yet, but after about 12 hours on it, I am about too.
Thanks Integrators!

Tasmota -

Power Handler -

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.