Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Software which runs on an ESP8266 and publishes an MQTT topic which can be used for different purposes of automation.

I myself use it to toggle a state in Home Assistant, which automates my flat, so it understands that I'm either going to sleep in the evening, or just woke up in the morning. It then can automate the appropriate things accordingly.

It consumes a minimal amount of energy and can be run on batteries for a really long time, I assume at least months if not years. It does it by booting up just to connect to wifi and sending this one MQTT command, after that it is set to go into deep sleep imediatelly.


Hardware schema

Hardware photo


Getting the code

git clone


Open the espbutton/espbutton.ino file in the Arduino IDE.

It expects the credentials for your WiFi and MQTT in the file like this:

#define ssid "myssid"
#define password "mypass"
#define mqtt_server ""
#define mqtt_port 1883
#define mqtt_user "user"
#define mqtt_password "passwd"
#define topic "sensor/sleeping"
#define topic_content "toggle"

Change the credentials so it matches your wifi and MQTT credentials. You may also change the topic if it makes sense for you.


  1. Open the sketch found under espbutton/espbutton.ino in the Arduino IDE
  2. Under File -> Preferences set as Additional Boards Manager URLs:
  3. Chose under Tools -> Board the "Node MCU 1.0 (ESP12-E Module)"
  4. Under Sketch -> Include Library -> Manage Libraries -> Search for "PubsubClient" and install the one "by Nick O'Leary"
  5. Connect GPIO0 to GND with help of the Prog. switch
  6. Press the Upload button


This file is part of esp8266-button.

Copyright 2018 Jeena

esp8266-button is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

esp8266-button is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with esp8266-button. If not, see


No description, website, or topics provided.




No releases published


No packages published