How to turn off the light automatically when you go out using esp32

How to turn off the light automatically when you go out using esp32

January 23, 2021 · esphome, esp32, iot, home assistant

Everytime you go out and you forget to turn off the light !

Don’t worry, you are not alone in this situation. We are all LAZY. In this article, we will make it simple and easy to make some economy on your electric bill, but we will also contribute to save the planet.

Requirements

Before starting the tutorial, you should have these materials.

Finding the Mi band MAC adress

if you know already your band bluetooth MAC adress, you can skip this part.

In your terminal run the command and find the name of your band in the output:

$ sudo hcitool lescan
Or
$ sudo hcitool lescan | grep Band

lescan means : low energy scan

ESPhome configuration

If you are not familiar with esphome [check this article](/how-to-monitor-your-home-temperature-with-esp32-and-xiaomi-mijia-using-esphome/.

Run ESPhome on your computer, and prepare the esp32 configuration:

substitutions:
  # Modify variables based on your settings
  hostname: "livingroom"

esphome:
  name: $hostname
  platform: ESP32
  board: esp32dev
wifi:
  ssid: wifi_ssid
  password: wifi_password
  fast_connect: True

# Enable logging
logger:

# Enable Home Assistant API
api:
  reboot_timeout: 0s

web_server:
  port: 80

ota:

time:
  - platform: homeassistant
    id: homeassistant_time

# Enable Bluetooth scanning for this ESP32
esp32_ble_tracker:

# Example configuration entry
binary_sensor:
  - platform: ble_presence
    mac_address: XX:XX:XX:XX:XX:XX
    id: mibandpresence
    name: "Presence MiBand EntryESP"

Check the binary_sensor ble_presence for more information Now you can flush your esp32 with the configuration above.

If you find any problem during this tutorial: Please leave a commment and I will reply very soon!

Configuring smartbulb

If your smart bulb is not configured yet, you can refer to this video to see how to setup it

Home assistant automation

Once your esp32 is configured, connected to the internet and to home assistant, let’s create the automation.

Indeed, 2 automations are required :

Turn off when I leave home automation

Do the following :

Turn off when I leave home automation

Do the following :

If you like this tutorial, please give me support by subscribing to my Youtube channel my youtube channel

I hope this article was useful, please write a comment if you succeed and share it with your friends!

Home assistant automation create Home assistant automation create 2

Building something like this in production?

I help teams turn setups like this into reliable, monitored infrastructure.

Get a free consulting call

Get my monitoring stack checklist

The exact checklist I use when setting up observability for a new team. No spam, unsubscribe anytime.