Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
![How to get the mac address for sonoff x How to get the mac address for sonoff x](https://wiki.smartsimple.com/images/5/51/2019-05-ticket-87438-1.png)
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
commented Apr 9, 2018
I have many Sonoff devices, mostly basic switches. Once I name a device something I can no longer see the MAC address in the app. I also have several routers and APs. I would like to be able to give the devices a name in the router's database so I can identify which Sonoff is connected to what AP etc. The original firmware doesn't support static IP-addresses. I just pushed an update for the app that also supports the Sonoff-Tasmota firmware, which does support static IP-addresses. However, it's not trivial to install an alternative firmware (that said, at the moment it's the only way to support devices that are shipped with firmware 1.6. I am trying to get the ip address of the sonoff setup as a sensor so i can display it in HA. I have tried: platform: mqtt name: 'IP Test' statetopic: 'tele/fishtank5heater/INFO2'. Jun 19, 2017 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. Sep 07, 2017 It is quite easy to get sonoff MAC address via http, just tap on information ( or type ipaddress/in? ) as example here's one of my sonoff.
I am trying to get the ip address of the sonoff setup as a sensor so i can display it in HA. I have tried: platform: mqtt name: 'IP Test' state_topic: 'tele/fishtank5_heater/INFO2' value_template: '{{ value_json['IPAddress'] }}' but it appears not to work. what is the correct JSON script to achieve this? and is the INFO2 broadcast over mqtt? |
commented Apr 9, 2018
You have to send command: status 5 You will get as response (example) stat/sonoff-17DBAE/STATUS5 = {'StatusNET':{'Hostname':'sonoff-17DBAE-7086','IPAddress':'192.168.2.150','Gateway':'192.168.2.1','Subnetmask':'255.255.255.0','DNSServer':'192.168.2.1','Mac':'B4:E6:2D:17:DB:AE','Webserver':2,'WifiConfig':3}} |
closed this Apr 17, 2018
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
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.
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.
Ip Address
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%/).
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
![How To Get The Mac Address For Sonoff How To Get The Mac Address For Sonoff](https://smartlifeautomated.files.wordpress.com/2016/08/sonoff_web4.png)
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
Free halo 3 for mac. 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.
2wire 802.11 g usb wireless adapter driver windows 10. 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
How To Get The Mac Address For Sonoff Driver
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:
topicbase/cmnd/COMMAND
the result of the command uses the topic
topicbase/stat/RESULT
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
Notes
Mac Address Lookup
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.
Resources
- Good video on flashing Sonoff and setup
Mac Address Changer
Related Tutorials:
[Total: 9 Average: 5]