Objective

We got ourselves a Glade automatic air freshener for our bathroom. It can be set to spray every 9, 18, or 36 minutes. The manufacturer advertises that a single canister should last about two months if you use the longest interval. The freshener itself isn’t too pricey, but the refills? They cost more than refreshener, kind of like how printers are cheap but the ink costs a fortune. Of course I won’t go bankrupt because of them, but having to remember to get new refills every couple of months is a pain I often forget about. I also disliked a general inefficiency by spraying when no one was around.

With few mods and automation, the freshener now only triggers when when the toilet is flushed by adding a door sensor to the flush mechanism. This adjustment has greatly increased the lifespan of the canisters. Here are the details:

The company says a canister will last 60 days on a 36-minute spray interval.

Here’s the math: Daily sprays: 1440 minutes / 36 = 40 Sprays over two months: 40 x 60 = 2400

So, a canister runs out after 2400 sprays. But according to few months of poop statistics, the big flush button is used four times a day.

This means the canister’s lifespan has increased from two months to 600 days (2400 / 4), or 20 months — effectively tenfold.

Next up, I’m thinking of installing a sensor to detect volatile organic compounds (VOC) above the toilet, because VOC levels go up with heavy bathroom use. I already track VOCs in our living areas to keep an eye on air quality, but haven’t set it up in our bathrooms yet. This should make the system even more efficient, especially because not every bathroom visit is… you know, equally smelly.

Hardware Setup

The air freshener is a Glade automatic air freshener. The modifications included integrating an ESP8266 microcontroller with an ESP01 relay:

I also modded it to run directly from a 230V outlet instead of batteries, which furtherly reduces the maintenance.

The discovery that gave me the idea for mod was that disconnecting and reconnecting the power supply to the freshener causes an immediate spray, regardless of the interval setting. The ESP01 relay’s role is to normally keep the freshener unpowered. However, when a command from Home Assistant is received, it powers the device for just enough time for one initial spray before cutting the power again. This gave me control over air freshening via the Home Assistant.

Below you can see the modded air refresher with the ESP01 on the right side. It is connected to relay installed on the back and is not visible in the picture. On the left there is a DC-DC converter that adjusts the voltage to the same level as battery.

Additionally, a door sensor was installed in the large toilet flush button using a Mi Window and Door Sensor, allowing Home Assistant to detect flushes.

Integration into Home Assistant

The ESP01 module is flashed with ESPHome and communicates with Home Assistant through an API. The door sensor uses Zigbee and integrates with the Home Assistant using ZHA integration.

ESP config:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#
# Lokacija: v glade-u v spodnji kopalnici
#

substitutions:
  devicename: esp01s-sp-kop-glade
  channel: sw_spodnja_kopalnica_glade
  ip: 192.168.x.x

esphome:
  name: ${devicename}

esp8266:
  board: esp01_1m

logger:
  level: INFO

# Enable Home Assistant API
api:
  encryption:
    key: xxxxxxxxxxxxxxxxxxxxxx

ota:
  password: !secret wifi_password
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: HIGH # for ESP8266 LOW/HIGH are mixed up, esphome/issues/issues/1532
  fast_connect: true
  manual_ip:
    static_ip: ${ip}
    gateway: 192.168.x.x
    subnet: 255.255.x.x
    dns1: 192.168.x.x
    dns2: 192.168.x.x
  ap:
    ssid: ${devicename}
    password: ${password}
    manual_ip:
      static_ip: 192.168.x.x
      gateway: 192.168.x.x
      subnet: 255.255.x.x
      dns1: 8.8.8.8
      dns2: 8.8.4.4

web_server:
  port: 80

time:
  - platform: sntp
    id: my_time

captive_portal:

switch:
  - platform: gpio
    name: ${channel}_relay
    pin: GPIO0
    inverted: true

Automation Logic

The automation logic is straightforward: pressing the large toilet button changes the sensor status to “open”. Home Assistant then instructs the ESP01 to activate the relay for a few seconds, triggering the air freshener to release a burst of fragrance.

Screenshot of Home Assistant automation:

The potential for further automation includes additional refresh triggers, such as turning on the bathroom lights or upon returning home after an extended period.