When it comes to upgrades, updating old IOT devices with the latest Tasmota can be quite a satisfying way to spend a Sunday. I was just tidying up my wiring in the office and noted a Tasmota’d Sonoff BASIC, so old it doesn’t even have an ID – check this out…
Not so much as an ID or version number. Back in 2019 I put the firmware Espurna on this unit – a project which seems to have now gone stale – though I notice you can define up to FIVE networks – I’ve never understood why Tasmota is limited to two. Let’s say Espurna has a few things going for it – but I prefer to stick with the actively developed Tasmota (Espurna last nightly built – 2022-06-13, Tasmota last nightly build half an hour ago). In both cases you are looking at local control of devices – no APPS needed and no far-eastern cloud dependency though it is easy with either a fixed external IP and a VPN to access this stuff from anywhere in the world. I’ve been using Tasmota for years now and it is so good that some time ago I ceased work on my own ESP8266 firmware (ESP-GO).
Enough history. I’m sitting in front of the board which is plugged into mains power. To start the ball rolling I checked out the free “Advanced IP Scanner” on my PC to look for any device added to the network that wasn’t there 5 minutes ago as I wasn’t entirely sure if this old board was running Espurna or Tasmota. Turns out it was the latter, so I COULD have found it with “Tasmota Device Manager”. AIS reported that the device was on internal address 192.168.1.159.
In the end, I simply punched http://192.168.1.159.lan into my browser – you might use a different suffix for local devices – I remember my old Vodaphone router back in the UK came set up to use .broadband – My router here is easily programmable and I set it to .lan as I’m lazy. I suppose I could have used .l to be REALLY lazy. The Sonoff BASIC appeared and normally I’d have gone to “Upgrade by webserver” to fit in the latest Tasmota.
In this case I had no idea what setup I had in the board and so I did two things – I first did the “Upgrade by Web server” you see above left using the standard URL within. After the board rebooted, I then selected an option I’ve never used before… so from the “main menu” – I chose “configuration” then “reset configuration”.
This completely reset the board configuration including WiFi as I quickly discovered, so off I went to my phone – set the WiFi to the “tasmota-xxxx” access point and in the phone browser went to 192.168.4.1 which is the default tasmota internal access point address.
I put in my “office” Wifi access point and left it at that. After the board rebooted, I could now access the device on my PC as normal – with no settings in there except access point.
I had no need to “configure module” as Tasmota assumes “Sonoff BASIC” by default. I went into “configure WiFi” and this time simply changed the hostname to “spare-old-sonoff”.
The NEXT thing I did after the reboot was to set up the MQTT credentials “Configure MQTT” so I could talk to the board by MQTT (in Node-Red) as well as this simple web interface.
The items I changed were “host”, “port”, “user”, “password” and “topic”. I left the rest as defaults.
At this point in the main menu I could hit “toggle” and hear the relay turn ON or OFF in the Sonoff unit. That left one more setting to change… in “configuration” “other” I set “device name” and “friendly name 1” to “spare-old-sonoff”. Had I gone on under “emulation” to pick the “Belkin Wemo single device” option, my Sonoff would now be seen by my Alexa Echo as “spare-old-sonoff” – but I left that out for now.
At this point from the main menu I often go into “console”. From there I entered a line with the word “time” (followed by ENTER). Now I could see that the device was an hour out. Entering another line from this site…
<a href="https://tasmotatimezone.com/">https://tasmotatimezone.com/</a>
Backlog Latitude 39.3260685; Longitude -4.8379791; TimeDST 0,0,3,1,1,120; TimeSTD 0,0,10,1,1,60; TimeZone 99
The time was now correct on the board. I could simply have entered:
timezone 99 or tz 99
But this way I ended up with more useful info about my location in the device – all of this took a LOT less time to DO than write up in the blog.
I like purple more than the default colours in my Tasmota webUIs and this page lets you change colours.. I ended up pasting this into the console as above…
WebColor {"WebColor":["#eaeaea","#252525","#282531","#eaeaea","#282531","#d7ccff","#1d1b26","#ff5661","#008000","#faffff","#694fa8","#4d3e7f","#b73d5d","#822c43","#1f917c","#156353","#faffff","#716b7f","#eaeaea"]}
and the result – a pretty new webUI.
Nothing to do now other than to make use of my spiffed up ancient Sonoff BASIC board. And in these units kitted out with Tasmota as against the new BASICR4 units under eWeLink – the green light on the unit is an indicator that the output is on or off. It also conveniently flashes when you power up, turning off when the WiFi connection is made and when there is an MQTT issue – I only just realised that last one – I turned off the RPi for an experiment, so no MQTT and suddenly the Sonoff started to flash. I just wish they’d used an RGB LED there so you could easily distinguish WIFI or MQTT setup/issues. Were it me, I’d use RED for a relay ON and I’d flash to BLUE for MQTT issues and flash GREEN or YELLOW for WIFI set/issues.
One day later I noticed this in the Tasmota page SETOPTIONS:
You can abbreviate SETOPTIONS in the console to so – i.e. so31 0
There is FAR more to Tasmota than this. The default output setup returns the output to it’s previous state after power cycling – that can be changed in a “so” – you have full control of timers, rules and much more – I’ll get to rules in a minute – it’s been a good learning day.
So, using Tasmota, the differences between the old BASIC and the new BASICR4 – the latter can have MATTER integration. Tasmota on the BASICR4 does show up a qrcode to indicate that it is about to intergrate into Matter – something I’m still struggling with – but here’s the thing – the original BASIC, as it is ESP8266-based (not ESP32), does NOT show up the QRcode and hence cannot be intergrated into MATTER.
However, note that I have spare-old-sonoff in front of me and in node-red-contrib-googlehome I can turn it on and off – and of course I can also integrate the device into Alexa as an option in Tasmota so not all is lost.
I note that of course the old BASICs don’t have overheat sensing – so I looked inside the old unit – there’s a connector with gnd, tx, rx, 3v3 and IO2 (which is unused on the old BASIC but comes to a convenient marked PCB hole)…
So, I connected a spare Dallas DS18b20 to the PCB underside gnd, 3v3 and IO2 – no need for a pullup resistor if you go into “console” and enter the line “so74 1” – then go into the “configuration” “configure module” section and set GPIO2 to DSD18B20 – and the result – you now have temperature sensing…
Ok,initially I thought I had to actually monitor that temperature on the Raspberry Pi and choose when to have my Node-Red turn off the output – but that’s no big deal.
Here’s the view from the Tasmota webUI. It works – and just adds more flexibility to an old Sonoff BASIC.
I could of course have used an AM2301 and gotten the humidity out as well but I figured that was overkill. If you buy DS18B20s from AliExpress they’re quite cheap.
AND NOW – thanks to SFROMIS amd PKKRUSTY on Discord…
Overheat protection entirely on the old BASIC board
Set the Tasmota on the BASIC to GENERIC (18) rather than the default SONOFF BASIC (1)
In the Tasmota console:
switchmode1 3 (makes it act as a button)
Set gpio12 to relay 1, gpio13 to LEDi 1, GPIO2 to ds18b20, gpio0 to switch 1
rule1
on ds18b20#temperature>80 do backlog switchmode1 15; power1 0; var1 0 endon
on ds18b20#temperature<70 do backlog switchmode1 3; var1 1 endon
on power1#state=1 do backlog power1 %var1% endon
rule1 1
rule1 5
We did think about possibly adding power1 1 in the lower restore but dismissed it as the primary reason for this code (non-volatile) is for safety….
80 and 70 are arbitrary untested temperature values. I’ll use a small heater as the load soon to test. The board typically sits off-load at 45-55c in my office. We tested button on/off, MQTT on-off and the UI itself (which can be a tad slow to respond but works).
So now, my old Sonoff BASIC has temperature monitoring – and can be set to turn off the output (and stop responding to changes) at temperatures of over 80c (or whatever you substitute for my test values).
If nothing else this is great fun – and in the process, the guys on Discord helped me update my Grafana installation (see update in THE SCRIPT blog entry) – I decided for now I’ll have Grafana monitor this device – I’m using the standard regular TELE info out of Tasmota to feed my RPi4 MQTT input to then fire the current temperature of the old BASIC unit to Grafana – watch…
That’s it for the Sonoff – a diversion with a Wemos D1 board
While I was sitting in front of the computer with half an hour to spare, I grabbed an old Wemos D1 board which happened to have a handy resistive divider attached comprising a 1k to ground and GPIO17 (analog input) and a connector at one end of a 4k7 resistor, the other end of which was also attached to GPIO17. I thought it might be nice to monitor a 12v car battery with this and set about using CONFIGURATION – CONFIGURE MODULE to set the board to GENERIC (18) so I could then set GPIO17 to ADC INPUT – and then in console use the command in CONSOLE:
AdcParam 6, 0, 1023, 0, 1720
That last value 1720 sets the range and on a pair of batteries totalling 3.25v, I got value 325 out. Good but no prize – (the 1722 was found by trial and error to get the range correct for a value of 325 out appearing in the webUI). It did – but when I rebooted the board, that value reset to about half of that. I went onto the TASMOTA Discord forum where once again SFROMIS got me out of a mess. It is still not obviously documented (to me anyway) but instead of selecting ADC INPUT I should have selected ADC RANGE for GPIO17. I did – and it works perfectly.
https://tasmota.github.io/docs/ADC/#commands
If anyone wants to try this (any old ESP8266 board) you need a steady power supply and avoid putting significant loads on any outputs you may have defined. I put a purple LED on GPIO12 which I set to PWM output – and varying that output from off to full in the Tasmota webUI had minimal to no affect on the ADC value. At one point the value crept up from 325 to 327 but not repeatably – most likely a PSU issue.
Anyone trying this and getting a slightly different value (I used standard 5% resistors) just modify that 1720 value a tiny bit.
Why did I use such low value resistors? Well I originally planned to check car battery voltage in the car, not the cleanest electrical environment. Of course, having no WiFi in the car, I realised I’d have to set the Wemos to my phone’s WiFi HotSpot to try this out in a live environment. All very nice but I can’t see what suffix the phone hotspot uses for local devices -duhhh. HOWEVER, turning the hotspot on and having told my wemos to use that hotspot… the hotspot on Android, holding the phrase “mobile hotspot” on the phone shows devices and my WEMOS appears, holding that gives it’s address on the network… and I can go there in the browser – simple – just not as simple as storing wemos2.local for instant recall in the browser – but there you are.. just MORE uses for the venerable and dirt cheap ESP8266. Those Wemos boards are something like €1.50 – and 2 resistors… I used a €1.50 adaptor board on top which takes in 12v power…. On the analog input, the ESP8266 takes 0-14 for full range but the WemosD1 like other board has a divider on-board making that 3v3 full range so my divider will be just fine for measuring car battery voltage (15.5v full range or thereabouts).
Peter, have you ever looked at TasmoAdmin? It provides a central web UI you can use to update and manage multiple devices. https://github.com/TasmoAdmin/TasmoAdmin
I mostly use ESPhome nowadays, but when I was using Tasmota I used TasmoAdmin to get the same sort of central management you get with ESPhome. It made keeping devices up to date a lot easier.
hi
All good EXCEPT – clearly this was written for Apache fans. I use nginx these days and there is no such thing as some of the apache folders mentioned or nginx equivalents – so I can’t proceed with that.
Pete
Yeah, the webserver config is really old, I think most people are running it in Docker (it’s just a single command) or the Home Assistant plugin. You could adapt the Apache config to Nginx but it’s not just copy and paste. I moved most of my server stuff to docker compose to cut down on exactly that sort of hassle.
It looks like their Docker setup is actually built on Nginx, you might be able to adapt that.
https://github.com/TasmoAdmin/TasmoAdmin/tree/master/.docker/rootfs/etc/nginx
Now I’m utterly confused. I put that rule1 (modified to DS1820) into the console and set rule to 1. I added in the backlog command – and rebooted. The button on my Sonoff still directly controls the relay – ideas as to the next step?
Just making sure you activated rule1 by typing “rule1 1”. I’ve been known to forget this bit or not do it correctly on a few occasions. If I get time tomorrow I’ll add a DS1820 to one of my old Sonoff Basic’s and give it a try.
Hi KB
Yes I did remember rule1 1 thanks. Anyway I’ve scrubbed all that…. what I’m really after is something simpler… I simply want the sonoff to respond to button presses and MQTT in the normal way – UNLESS the temperature is over X degrees in which case the device hsa to stop taking ON/OFF commands or button presses – and the output needs shuttinh off until the temperature drops to say X-10c. For the sake of argument X could be fixed at 80c.
IF you DO get the urge to tackle this – don’t forget so74 OR put a pullup resistor on the DS18B20 (the former seems more sensible). SFROMIS in the forums reminded me if using a rule to refer to DS18B20, not DS1820 as in the outdated Tasmota docs. I’m up to here in market/chemist and other chores first think in the morning or I’d be up half the night trying to crack this.
What about defining the button as a switch (switchmode1 3) and then if temp is too high, changing switchmode to 15. i.e. “`rule1 on ds18b20#temperature>80 do backlog switchmode1 15; power1 0; var1 0 endon on ds18b20#temperature<70 do backlog switchmode1 3; var1 1 endon on power1#state=1 do power1 %var1% endon“`
That rule would be one-shot (rule1 5) so it doesn't keep triggering continuously.
Hi PKKRUSTY
That seems sensible – and thank you for that – BUT that doesn’t stop an MQTT command from turning on the unit…
AND… it doesn’t work.
With the temperature at 44.9 I tried putting this into the console..
rule1 on ds18b20#temperature>43 do backlog switchmode1 15; power1 0; var1 0 endon on ds18b20#temperature<41 do backlog switchmode1 3; var1 1 endon on power1#state=1 do power1 %var1% endon
rule1 5
I waited - I still had manual control of the button - so I rebooted, waited - checked again - still I had control over the button and the output went on and off on demand.
I wish WordPress would make it easier to include photos etc in the comments. I just took a pic of the unit sitting there, on 🙂
Any possibility there's a mistake above? for reference, the temperature showing on the Tasmota ui is now 52c...
Pete
did you change the config from Sonoff Basic to Generic, giving you access to GPIO0, which you would change from Button to Switch?
Might be easier to continue discussion on Discord…
Yes.. discord.. scargill. When i get home. Out for morning coffee…
So I managed to get the “simple thermostat example” rules working on an old Sonoff Basic. I’ll explain below for those interested. I agree with you Peter about keeping the normal functioning of the Sonoff and still make it work as a thermostat. That’s exactly what I had set up a few years ago but I didn’t save my rules anywhere. I’ll try and work out what I did later.
So for the “simple thermostat example” on the old Sonoff Basic:
You need to ignore the very first instruction –
switchMode1 3 this needs to be the default of 0
Instead you need to detach the button from the relay by setting –
SetOption73 1
The rest of the setup is the same but you need to change the switch to a button in one part of the rule1. The part “ON Switch1#State DO event toggling1=%mem1% ENDON” should be changed to –
ON Button1#State DO event toggling1=%mem1% ENDON
I just copied the name of the temperature sensor from the Tele message and changed it in the rule so didn’t end up entering the wrong name for the DS18B20.
Hope this helps
See new update at the end…
That’s simple enough. Glad you got it sorted.
matter will never arrive on tasmota esp8266 because of memory limits, details here: https://tasmota.github.io/docs/Matter/
Meanwhile for those of us with Google Home and Alexa, the MQTT alternative works well. I would like to get that Tasmota’d BASICR4 working on matter but my attempts to date fail at the last hurdle. Comments welcome.
Already made on change – that resistor isn’t needed if you use “SO74 1” in the console – which activates an internal pullup.
I’m now looking at the Tasmota page you suggested “Simple Thermostat Example”… in their example – maybe simply changing minumum temperature to 0 and max to 60 ???
I’m familiar with rules but only ever used short ones…
Is this simply entered as one line?
Rule1
ON system#boot DO RuleTimer1 70 ENDON
ON Switch1#State DO event toggling1=%mem1% ENDON
ON event#toggling1=0 DO mem1 1 ENDON
ON event#toggling1=1 DO mem1 0 ENDON
ON Rules#Timer=1 DO Backlog var1 0; RuleTimer1 70; Power1 0 ENDON
ON tele-SI7021#temperature DO Backlog var1 1; RuleTimer1 70; event ctrl_ready=1; event temp_demand=%value% ENDON
ON event#ctrl_ready>%mem1% DO var1 0 ENDON
ON event#temp_demand>%mem2% DO Power1 0 ENDON
ON event#temp_demand<%mem3% DO Power1 %var1% ENDON
It works by just copying and pasting that whole block from the website into the Tasmota console. It fits in the one rule with room to spare(there’s 3 to use) but you could remove the extra spaces if needed. Then don’t forget to turn the rule on with: rule1 1
To test it’s working, I set the min just above the temperature the sensor is showing (as long as it’s below the low thirties) and the max in the low thirties. so I can trigger the max with the warmth of my hand by just holding the unit then it should cool down to below the min. I don’t currently have a unit with a temperature sensor attached so can’t test one.
I use a few Sonoff Basic’s. A few years ago I used a Sonoff Basic with a DS18b20 attached to control a heat pad in my greenhouse to protect my seedlings from frost. I used the Tasmota rules to create a thermostat. This way it is even more self contained with no need for the Raspberry Pi and Node-red. I now use that device for something else so can’t give an example. I just looked up the Tasmota rule cookbook and the simple thermostat example seems a bit more sophisticated than what I did but would do the job nicely.
https://tasmota.github.io/docs/Rules/#simple-thermostat-example
Perhaps it’s not as simple to set up as using Node-Red but it’s all in the one device.