Menu
Loop timer supported devices (updating):all 1 gang switch/socket(required firmware ver. 1.5.0 and higher, G1 is excluded from the list), including S20 smart socket, Sonoff Touch EU/US, Sonoff Basic, Sonoff SV, Sonoff TH10/TH16, Sonoff RF, Slampher, Sonoff Pow (required firmware ver. 2.0.3 and higher), Motor Clockwise/ Anticlockwise Running WiFi. Apr 29, 2019 I lost the original firmware of my sonoff rf without making a backup. I tried other firmwares and the box starts up and connects with ewelink without being able to register. Is it possible to have a new original firmware or to make one from a bin file knowing that I have the id and the mac address.
WiFi Configuration
After flashing the device and attaching standard power to it, the device should start broadcasting a wifi SSID. The SSID will match the device type followed by a period and then some characters representing the devices MAC address. For example, the Sonoff TH would look like SonoffTH.3d8883d0f90f and the SmartLife H801 would look like esprgbw.5d7d404fe294. You then connect to the AP with the password: configme.
At this point, you may automatically be directed to a captive portal for the device in order to connect it to your WiFi network. If you don’t, then open a web browser and navigate to http://192.168.4.1. Here you are presented with a few options. You can either scan for your network to connect to or simply enter the network SSID and password. Either way, it is pretty self explanatory. After it connects to the network you specified, you will be booted back over to your home WiFi and the device should show up in your routers DHCP assigned license list. You can take note of the assigned ip address for some advanced configuration down the road, but it is not necessary to finish the setup in SmartThings.
SmartThings
Many third party devices (that are not Zigbee or Z-Wave) have a companion app that needs to be installed in order for the devices to work with SmartThings. The SmartLife versions of the devices found on this blog are the same way. You first install and publish the Sonoff (Connect) or SmartLife RGBW (Connect) SmartApps to guide you the rest of the way through the installation process. While you are at it, you might as well install the necessary device handlers that are listed on each device blog page.
At this point, go into the SmartThings app on your phone and install an instance of either Sonoff (Connect) or SmartLife RGBW (Connect). Only one instance of each is needed regardless of how many devices you install. For most people, clicking on “Discover Devices” will be the next step to take. Wait up to 5 minutes and your device should show up. Click the check box next to the device, hit next, and this will install the device for use in SmartThings. That’s it! Depending on which device it is, you may be able to do some additional configuration inside of the SmartApp, otherwise you can go back to the “Things” list, find the device, and start to play around with it. It will be a fully functional SmartThings device that can be used in other SmartApps, Routines, Phrases, etc. You can also now control the devices through Google Home and Amazon Alexa!
Normally the Sonoff switches don’t support MQTT but you can buy flashed devices that run the Tasmota firmware that does.
The Sonoff-Tasmota firmware provides three interfaces: MQTT, web and serial that can be used for controlling the switch.
In this tutorial I will cover basic setup of the Sonoff Tasmota MQTT Basic Switch and how to use MQTT to control and configure the switch.
Control Button
There is just a single button that is used to control the switch.
It can be used to manually toggle the switch on/off or to place into various configuration mode depending on how often it is pressed.
This link here has an overview of the button options.
Switch Configuration
There are two steps to the configuration:
- Wi-fi Setup
- MQTT Client configuration
Wi-Fi Setup
To configure the Tasmota switch you need to connect it to a Wi-Fi network.
Ip Address
The switch connects to a Wi-Fi network just like you mobile does and so s you will need to configure the SSID and password of that network.
There are several ways of doing this and the configuration methods are covered here under button usage
The easiest method is to use WPS followed by the android App.
If you use the manual method 4 short presses then note the following:
With this option the switch starts as a Wireless Access point. The SSID on mine was sonoffbasic-1122.
You then need to connect a computer to this access point and go to the IP address 192.168.4.1.
Note corrected from 192.168.1.4
You can then enter the SSID and password of the Wi-Fi network you will be connecting the device to.
When you enter this information into the webpage the switch will restart, connect to the Wi-Fi network and acquire an IP address.
Now in order to configure it further you will need to know the IP address it has acquired.
This isn’t as easy as it sounds but the device name on the network seems to be set to the same as the access point.
So you could try to ping this network name which should give you the IP address.
On my network the BT Home Hub displays all connected devices and was able to find the device IP address there. (screenshot below).
Configuring MQTT
The switch will start as an MQTT client and also a web server.
Initial device configuration is done via the web server. To access the configuration page go to
http://Device-IP/cn e.g
Click on configure MQTT button and you should see the screen similar to the one below:
You need to enter:
- The IP address or domain name of the MQTT broker
- The Port (default 1883)
- Client – This is used as the client -id and needs to be unique
- Username – Optional
- Password – Optional
- Topic – The client will publish and subscribe on this topic. The name should be meaningful.
- Full Topic -Defaults to topic/prefix -prefix is stat,cmnd or tele see below under MQTT default topics.
Note: You can use an external broker like test.mosquitto.org but it is better to use a local one. See installing mosquitto or installing mosca on node-red
When finished save the configuration and the switch should restart.
Sonoff MQTT Topics
Sonoff will subscribe to topics to receive control commands . It will also publish status information to topics.
Deciding on the topic structure is an important part of the configuration.
Each Sonoff device has a unique name which you configure in the topic section ( shown above).
This name will reflect the use of the device and should be meaningful e.g
main-light, outside-light etc
The prefix is either cmnd, stat or tele and the choice is usually
prefix +topic (%prefix%/%topic%/) or topic+prefix (%topic%/%prefix%/). Microsoft windows server 2008 r2 x64 torrent.
examples:
tele/main-light/ or main-light/tele
Using the prefix as the first part of the topic makes it easier to subscribe to multiple sonoff devices using:
tele/#, stat/# and cmnd/# options
Another option and my preferred option is to add your own prefix.
So if all the Sonoffs were used in your house you could use the topic hierarchy
house/prefix/topic or house/topic/prefix
now you can subscribe to all Sonoff devices using house/#
In this case I prefer house/topic/prefix.
To configure that use:
house/%topic%/%prefix%/
Starting Sonoff
On start the Sonoff device will subscribe to several topics. The exact topics depend on how you have structured the topic hierarchy. Here we are using the structure house/topic/prefix:
- house/main-light/cmnd/#
- house/main-light-1/cmnd/#
- house/sonoffs/cmnd/#
where
- main-light=topic name
- main-light-1= the client name or fallback topic
- sonoffs is the group name.
It also publishes its status and a Last will message wth the retained message flag set.
- house/main-light/stat/POWER ON
- house/main-light/tele/LWT online
Below is a screen shot showing the messages sent by a sonoff device starting up.
Controlling the Switch
You can control the switch i.e turn it on/off using either http or MQTT.
This is important to note as some systems may require http and if you have an existing control system that uses http then it might be easier to use that rather than going to MQTT.
This tutorial will mainly cover MQTT but I will also be covering http in another tutorial.
Turning on/off using mqtt
To turn it on/off you publish to the cmnd topic
The exact topic will depend on how you have set the topic structure. Below I use topic/prefix structure so to turn the device sonoff-light on and off I use the topic:
sonoff-light/cmnd/POWER1
With message on or off (case insensitive)
In the example below show how to so it using the mosquitto_pub client.
Turning on/off using http
You can use the curl command or easier still a web browser.
Enter the following
http://sonoff ip address/cm?cmnd=Power%20On
my ip address is 192.168.1.134 so I enter
http://192.168.1.134/cm?cmnd=Power%20On
Note: %20 is a space.
MQTT Default Topic Prefixes
The switch publishes and receives information on several topic prefixes, they are:
Topic | Sent by | Use |
---|---|---|
cmnd | PC,Smart Phone using an MQTT client | To control the Sonoff,set configuration and get status information |
stat | Sent by the Sonoff | Sent in response to a command |
tele | Status information | Report status information at set intervals |
The above topics are prefixed with the switch topic e.g.
topicbase/stat/
MQTT Commands and Responses
Besides turning the switch on and off, commands can be used to set various settings like the MQTT broker, port retain flag etc and the get information about the switch.
The switch uses a command response structure. Each command is acknowledged with a response.
MQTT commands use the topic structure:
How To Get Sonoff Mac Address
topicbase/cmnd/COMMAND
the result of the command uses the topic
topicbase/stat/RESULT John bean tire changer 7600 manual.
The result is contained in the message payload.
The screen shot below shows the command response messages for setting the MQTT retain flag on the mqtt client.
The screen shot below show the status messages that the Sonoff sends at regular intervals,
Setting the Group Topic
A collection of devices can be controlled by setting them to use the same group topic.
If our devices used the group topic housesonoffs for example we could turn a device on or off using:
house/housesonoffs/cmnd/POWER1 with message on or off
To set the group topic for a device use:
topic house/sonoff-light/cmnd/grouptopic with message group name. As shown below:
You should note that setting a group topic causes the switch to restart as it needs to subscribe to the new topic.
Controlling Using Python Demo Script
If you use python I have written a short demo script that you might find useful. You can download it below
Mac Address Changer
Notes
Because changing certain parameters results in a reboot you can change several parameters in one command using the backlog topic see MQTT Features for more details.
Mac Address Lookup
Resources
- Good video on flashing Sonoff and setup
Related Tutorials:
[Total: 9 Average: 5]