====== Useful Sonoff / Tasmota commands ====== Once you've got the [[https://github.com/arendst/Sonoff-Tasmota/|Tasmota]] firmware installed in your [[https://www.itead.cc/sonoff-pow.html|Sonoff POW]] and it's contactable on your network, you'll (probably) want to configure it to do something useful. I installed [[https://mosquitto.org/|Mosquitto]] on a Raspberry Pi (including the client package) and configured Tasmota to talk to it: From the **Configure MQTT** menu, set: * **Host** = DNS name or IP address of the machine you installed Mosquitto on * **Client** = Meaningful identifier for this particular Sonoff (I called mine SonoffOne, SonoffTwo etc for now) * **Topic** = The same as the client name * **Full topic** = //Location///%topic%/%prefix%/ where //Location// = some identifier for the network, room, building etc where this Sonoff is installed (in the examples below, this is "Home") * The **User** and **Password** should be set to any username and password you have configured into Mosquitto The Sonoff will then start publishing messages to the MQTT server, which you can subscribe to and read from the Mosquitto-client: mosquitto_sub -h mqtt.servername.or.address -t '#' -v Will show all messages which get sent to the MQTT server, for any topic. When you restart the Sonoff, it will publish some messages such as: Home/SonoffTwo/tele/LWT Online Home/SonoffTwo/cmnd/POWER (null) Home/SonoffTwo/tele/INFO1 {"Module":"Sonoff Pow","Version":"5.12.0","FallbackTopic":"SonoffTwo","GroupTopic":"sonoffs"} Home/SonoffTwo/tele/INFO2 {"WebServerMode":"Admin","Hostname":"Sonoff-Two","IPAddress":"192.168.32.33"} Home/SonoffTwo/tele/INFO3 {"RestartReason":"Software/System restart"} homeassistant/switch/SonoffTwo/config (null) Home/SonoffTwo/stat/RESULT {"POWER":"ON"} Home/SonoffTwo/stat/POWER ON Home/SonoffTwo/tele/STATE {"Time":"2018-02-15T16:22:22","Uptime":"0T00:00:15","Vcc":3.247,"POWER":"ON","Wifi":{"AP":1,"SSId":"Wireless","RSSI":94,"APMac":"00:25:9C:83:7E:69"}} Home/SonoffTwo/tele/SENSOR {"Time":"2018-02-15T16:22:22","ENERGY":{"Total":0.000,"Yesterday":0.000,"Today":0.000,"Period":0,"Power":0,"Factor":0.00,"Voltage":216,"Current":0.000}} The last two lines will then be repeated every five minutes with up to date values. You can configure the Sonoff **far** more via MQTT than you can via the web interface. See these pages for more information: * https://github.com/arendst/Sonoff-Tasmota/wiki/Commands * https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Features Here are some particularly useful commands: Change the measurement reporting interval from 5 minutes to 10 seconds (which is the minimum you can set): $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/cmnd/TelePeriod -m 10 Change the blue LED so that instead of simply being on all the time to indicate power is applied, flash when there is MQTT activity: $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/cmnd/LEDstate -m 6 Set the relay so that it is always on when the Sonoff is powered, and cannot be turned off by pressing the button: $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/cmnd/PowerOnState -m 4 Make the commands and responses a little more verbose - change "cmnd" to "command", change "tele" (which stands for telemetry) to "value", and change "stat" to "status": $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/cmnd/Prefix1 -m command $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/command/Prefix2 -m status $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/command/Prefix3 -m value Note that: - changing "cmnd" to "command" means you also have to send commands with "command" in them, as shown in the last two lines above - each of the three commands above causes the Sonoff to restart, and it won't respond to another command until it's up and running again, so don't just type them all one after another - wait until you see the device reappear on the MQTT event stream before sending it the next command - the "backlog" command can be useful in this instance - it allows you to send several (up to 16) commands all in a single string, and all get acted on at once (particularly useful if you need tochange the network SSID and password, for example): $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/cmnd/Backlog -m "Prefix1 command; Prefix2 status; Prefix3 value" Set the voltage and power measurements to show one decimal place (default is none; one decimal place is all that's available): $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/command/VoltRes -m 1 $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/command/WattRes -m 1 Set the timezone the Sonoff is being used in: $ mosquitto_pub -h mqtt.servername.or.address -t Home/SonoffTwo/command/Timezone -m 1 Note that most of the above commands will also report back with the current setting if you use **mosquitto_pub** with the **-n** option instead of **-m //value//**. There are also some very useful commands for [[.calibrate|calibrating]] your POW. ---- [[.:|Go up]]\\ Return to [[:|main index]].