I always think it is worth periodically re-visiting things you’ve tried before, even when the first attempt led to tears. Things change. And so it was that I pulled out and old (original 4-pin connector) Sonoff Basic recently and gave Tasmota a go. It is some time since I looked at this. Off I went to the Tasmota site looking for a binary file for the Sonoff BASIC. Voila. Binary files for lots of boards including Sonoff Basic.
Next I had to remember how to flash this on my Windows PC. I tried esptool.py and quickly realised this was not going to work on my PC without figuring out where Python is hiding. It just so happens I have esptool.exe on there, in my c:\espressif\utils folder.
I connected the Sonoff to the PC via a handy USB FTDI cable (4 pins inc. gnd, 3v3, serial in and serial out) and having checked which USB port the FTDI was connected to (thanks Arduino IDE) I then went off here: https://github.com/nodemcu/nodemcu-flasher and grabbed in my case the Win64 version of the single file ESPFLASHER.EXE, told it about the relevant COM port and where I’d put the sonoff BIN file (You put the file path under CONFIG). Making sure I’d started the Sonoff in FLASH mode (i.e. holding down the black button).. I pressed FLASH. A moment later, it was done.
For those who would rather use a command line –I have esptool.exe in my c:\espressif\utils folder. I opened a cmd.exe box, moved to the c:\espressif\utils folder and entered the following information:
esptool.exe -–port com15 write_flash –fs 8m –fm dout 0x0 d:\user\Peter\desktop\sonoff-basic.bin
Of course the com port and file location is unique to my situation and this way it all looks fiddly.
Before hitting ENTER to program, I disconnected the FTDI from the PC, held down the button on the Sonoff, restored the connection to the FTDI – and hit ENTER while holding the button for another couple of seconds – all with two hands. A short time later, the flashing process was complete. Easy.
I put the FTDI away, put the Sonoff board back in it’s box and connected mains to the board. I then altered the WIFI on my phone to use the Sonoff.. and set the phone browser to 192.168.4.1 – the default address of the Sonoff. A menu came up and I set up the name of my normal WIFI router in the office along with password, also the name of a router elsewhere in the building along with it’s password. I also told the Sonoff about my Pi MQTT broker and password. finally I gave the unit a name – “sonoffA”.
All done, rebooted the Sonoff, reset the phone WIFI. Trust me, things don’t often go that smoothly.
From there, turning the output on and off in the Sonoff was simply a matter of looking up (remembering) the relevant Tasmota commands.
In Node-Red, I set up an INJECT node to fire stuff at an MQTT node:
string payload: ON
and another for OFF of course.
That worked. Next I tried first sending a PULSETIME command (as above but using PULSETIME instead of POWER). With a value of 50 I got 5 seconds. Nothing of course then happened until I sent the ON command (or pressed the button on the Sonoff) then the output came on for 5 seconds. This is where I found the commands;
with no payload, injected into MQTT lets the Sonoff return the status of the output after an on or off command (by software or pressing the hardware button on the Sonoff) and when the timer times out.
All of that was easy. Last time I tried Alexa with this kind of setup, I almost took up woodworking. This time, thanks to:
it was a breeze. No https:, no other hassles, I installed the node, refreshed the screen added the Alexa node to Node-red – my test flow.
I told Alexa to find devices and it found sonoffA. I told Alexa to turn sonoffA ON. Nothing. It took me a minute to twig of course that the sonoffA I’d just set up has nothing to do with the real unit sonoffA. Duh. I fired the output of the Alexa node into MQTT via a FUNCTION NODE as follows:
msg.topic="cmnd/" + msg.device_name + "/POWER";
I have so very far to go to get up to speed but this is a start. Lovely. Thankfully, the Tasmota software does not appear to be case-sensitive. Seriously, I don’t think I’ve missed anything out – it was THAT easy.
Oh yes, nearly forgot, last night i set the emulation mode to 1 (see the Emulation entry below) and set a friendly name for the same board before renaming it and without that Node-Red node, as it turns out, I didn’t do that with sonoffA. So right now I can ask Alexa to turn “my board” on directly – ie without that node or I can talk via the node and a function…. so here, as the light in my head turns on – is a summary – I can tell Alexa to turn “my boad” on” then turn “sonoffA” off – same thing – same real board. If I tell Alexa to turn “madness” on, hte output ends up in the debug node, but there is no real device called “madness”. Indeed, do I actually need the Alexa node? It appears not for Sonoff – but for devices that don’t support Alexa, sure.
Here it all is – and yes I am using the Node-Red dark theme which Mr Shark pointed me to.. https://github.com/bonanitech/midnight-red
More here as I get more ambitious. I’ve one or two Sonoff BASIC devices floating around.
For those who like to get their Sonoffs from Amazon, here’s a link.
Price: normal £9.9, 15% off with link i.e. £8.42 after discount, available from 2018.12.26 to 2019.01.31
And yes, using the Web interface after setting up the Sonoff, I did try the OTA command to ensure I have the latest ROM – it worked a treat ALSO. If only life was always this easy.
In case you’re wondering how to turn stuff up and down when the payload is “on”. Check out the “madness” node- I told Alexa to set madness to 5 and looking at the whole message, not just the payload, we see..
Theo Arends deserves a medal for the work he’s done on Tasmota, as (to a lesser extent) does the Singapore-based team who made node-red-contrib-alexa-local.
I now know how to get the APP to forget my previous naming attempts – as I give the Sonoffs actual useful names. I’ve called one “my desk light” (friendly name for Alexa) with a hostname of “my-desk-light” to which Windows adds “.broadband” – hence I can access the unit from my PC browser as http://my-desk-light.broadband (for simplicity I also make the mqtt topic my-desk-light.
And as my infatuation with Sonoff + Tasmota continues, I’ve just flashed a Sonoff 4CH PRO. To do that I used the same code, and again used the “NODEMCU Firmware Programmer” in Windows, this time in SPI mode DOUT and assuming 1MB of FLASH (well, it worked – under ADVANCED). I had to temporarily hardwire GPIO0 to ground and once flashed I seemed to be short of Alexa instructions so I immediately ran OTA. After that I had access to all 4 outputs and their buttons – as I’d called the unit “sonoff-four” I gave friendly names for Alexa of “sonoff-four-one”, “sonoff-four-two” etc. Worked a treat. I tested all 4 buttons and outputs and noted all 4 LED indicators worked too.