Skip to content
Some nodemcu based to run sonoff wifi enabled plugs through MQTT
Lua Shell
Branch: master
Clone or download
Latest commit d53f040 Jul 20, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Update Nov 3, 2018
default_config.lua Shameless steals on jesstr version Nov 3, 2018
init.lua syntax error (#4) Jul 20, 2019
mqtt.lua Shameless steals on jesstr version Nov 3, 2018


Some nodemcu based code to run sonoff wifi enabled plugs through MQTT The button on the device can also be used to toggle the state of the plug

Main difference with jesstr ( fork :

  • on this one : power status and command are available in the same topic /cmd/power (useful when multiple remotes should stay in sync). One more command : "/cmd/status" which returns the state on top of jesstr's timed version
  • on jesstr's one : command is on /cmd/power and status on /state/power

How To

Clone the repo Symlink and (available on github) in the main repo copy, rename it to and update it according to your needs execute


  • config.lua : as its name implies
  • init.lua : runs the wifi connection and launches ota and broker modules
  • http.lua : web server (http) and over the air updates module
echo -e "**LOAD**\npage.tmpl" | cat -  page.tmpl | socat -u stdin TCP:ipaddress:80 -- updates the page.tmpl file on device
echo "**RESTART**" | socat -u stdin TCP:ipaddress:80 -- restart esp8266
  • mqtt.lua : mqtt client module
mosquitto_pub -h "myMQTTserver" -t "/myMQTTpath/myClientID/cmd/power" -m "on" -- turn plug on
mosquitto_pub -h "myMQTTserver" -t "/myMQTTpath/myClientID/cmd/power" -m "off" -- turn plug off
mosquitto_pub -h "myMQTTserver" -t "/myMQTTpath/myClientID/cmd/status" -m "" -- immediately returns status in /myMQTTpath/myClientID/state/#

Sonoff pin layout and GPIOs stolen from Pete and the community
Wifi connection loop stolen from marcelstoer/wifi-watch.lua
nodemcu firmware generated with Marcel's NodeMCU custom build machine (just add MQTT to the standard module selection)
Correction of shameful bugs, multi-wifi enabled, install script and other stuff by jesstr, thank you !

You can’t perform that action at this time.