Free library · Project
GPO temperature monitor for EV granny chargers
This free project watches the power point your EV granny charger is plugged into and warns you if it starts to overheat. It costs about A$25–40, takes an evening to build, and never touches mains wiring.
What it does
- Reads two DS18B20 sensors on one data wire: one taped to the GPO faceplate, one measuring room air
- Works out how much hotter the GPO is than the room (the "rise"), every 10 seconds
- Four levels: OK, Watch, Warning and Alarm, shown on a red LED and an active buzzer
- Serves a live web page on your Wi-Fi with the temperatures, the current level and the highest reading since start-up
- Keeps alarming locally even if Wi-Fi drops
- The BOOT button mutes the buzzer for 15 minutes (the LED keeps showing the level)
- Flags a Sensor Fault if the GPO sensor is unplugged or gives bad readings
Why this matters, and what the readings mean, is covered in the companion blog post: Is your power point cooking? Granny chargers and GPO heat.
Parts list
Prices are approximate Australian retail and vary by supplier.
| Qty | Part | Notes | Approx. (AUD) |
|---|---|---|---|
| 1 | ESP32 dev board (DevKit V1 or similar) | Any board with MicroPython firmware | $12–20 |
| 2 | DS18B20 temperature sensor | Stainless waterproof probe (as pictured) or TO-92 type; either works on the faceplate or for room air | $3–8 each |
| 1 | 4.7 kΩ resistor | Pull-up for the data line | $0.20 |
| 1 | Active buzzer, 3.3 V | Under 20 mA so it can run straight from a GPIO | $2–3 |
| 1 | Red 5 mm LED + 220 Ω resistor | Status light | $0.50 |
| 1 | USB power supply + cable | Plug into a different outlet if you can | $10 |
| — | Kapton (polyimide) tape | Heat-resistant tape to hold the sensor on the faceplate | $5 |
| — | 3-core thin cable, ~1 m | Sensor leads | $3 |
| — | Small enclosure, breadboard or stripboard | $5–10 |
Total: about A$25–40.
Wiring
Both DS18B20s share the same three wires. Use normal mode (VDD to 3.3 V) rather than parasite mode: it is more reliable with two sensors and a metre or so of cable.
| From | To | Notes |
|---|---|---|
| DS18B20 GND (both) | ESP32 GND | Left pin, flat face towards you |
| DS18B20 DQ / data (both) | ESP32 GPIO 4 | Middle pin |
| DS18B20 VDD (both) | ESP32 3V3 | Right pin |
| 4.7 kΩ resistor | Between GPIO 4 and 3V3 | One resistor for the whole bus |
| Buzzer + | ESP32 GPIO 26 | Buzzer − to GND |
| LED anode (long leg) | GPIO 27 via 220 Ω | LED cathode to GND |
| BOOT button | GPIO 0 | Already on the board: no wiring |
For a louder 5 V buzzer, drive it through an NPN transistor (e.g. 2N2222 with a 1 kΩ base resistor) from GPIO 26 instead of directly.
ESP8266: GPIO 26 and 27 don't exist on the ESP8266, so change BUZZER_PIN, LED_PIN and DS_PIN at the top of main.py to suit your board.
Mounting the sensors safely
Everything in this project stays on the outside of the power point. Never remove the faceplate, drill it, or put anything inside the GPO. Work on fixed wiring must be done by a licensed electrician.
- Switch the GPO off and unplug the charger before fitting the sensor.
- Put a small dab of thermal paste on the flat face of the GPO sensor and press it against the faceplate, as close to the charger's socket as you can. Just above the socket, or between the socket and its switch, works well.
- Hold it down with two layers of Kapton tape. Ordinary electrical tape can soften and lift when warm.
- Route the sensor cable so it doesn't pull on, or tangle with, the charger plug.
- Fix the room sensor about 30 cm away, at a similar height, out of direct sun and away from the charger's control box (that box gets warm too).
- Mount the ESP32 where you can hear the buzzer, and power it from a different outlet if you can.
The sensor reads the faceplate surface, which is cooler than the contacts inside and lags behind them. The default alarm levels allow for that, so don't raise them to stop a nuisance alarm. Find out why the GPO is warm instead.
The code
The onewire and ds18x20 modules are built into the standard ESP32 MicroPython firmware, so there is nothing extra to install. You need two files on the board: boot.py (connects to Wi-Fi) and main.py (sensors, alarm and web page).
Download boot.py and main.py (zip)
boot.py
Put your Wi-Fi name and password in the two lines marked REPLACE.
# boot.py - AP Design Labs: GPO Temperature Monitor
# Runs first at power-up. Connects to Wi-Fi, but gives up after 15 s so
# the local buzzer/LED alarm in main.py still works if Wi-Fi is down.
import network, time, gc
try:
import esp
esp.osdebug(None) # quieten debug output
except Exception:
pass
gc.collect()
SSID = 'REPLACE_WITH_YOUR_SSID'
PASSWORD = 'REPLACE_WITH_YOUR_PASSWORD'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('Connecting to Wi-Fi...')
wlan.connect(SSID, PASSWORD)
t0 = time.ticks_ms()
while not wlan.isconnected() and time.ticks_diff(time.ticks_ms(), t0) < 15000:
time.sleep_ms(250)
if wlan.isconnected():
print('Wi-Fi OK - open http://%s on your phone' % wlan.ifconfig()[0])
else:
print('Wi-Fi not connected - running local alarm only')
main.py
All the settings you might want to change are at the top.
# main.py - AP Design Labs: GPO Temperature Monitor for EV granny chargers
# ESP32 + 2 x DS18B20 (one on the GPO faceplate, one measuring room air)
# MicroPython, upload with Thonny. Free Library project - apdesignlabs
import machine, onewire, ds18x20, time, socket, json, gc
# ------------------------------------------------------------------
# SETTINGS - change these to suit
# ------------------------------------------------------------------
DS_PIN = 4 # DS18B20 data line (4.7k pull-up to 3.3 V)
BUZZER_PIN = 26 # active buzzer +
LED_PIN = 27 # red LED via 220 ohm resistor
BUTTON_PIN = 0 # BOOT button on most ESP32 boards = mute
SAMPLE_S = 10 # seconds between readings
MUTE_MIN = 15 # minutes the BOOT button silences the buzzer
# Sensor addresses. Leave as None the first time; the Shell prints
# the addresses it finds. Then paste them in (see the post).
GPO_ROM = None # e.g. '28ff641e8216c3a1'
AMB_ROM = None
# Alarm levels - rise of the GPO above room temperature (deg C)
WATCH_RISE = 10
WARN_RISE = 20
ALARM_RISE = 30
ALARM_ABS = 60 # GPO surface alarm regardless of room temperature
HYST = 2 # must fall this far below a level to clear it
# ------------------------------------------------------------------
# HARDWARE
# ------------------------------------------------------------------
ds = ds18x20.DS18X20(onewire.OneWire(machine.Pin(DS_PIN)))
buzzer = machine.Pin(BUZZER_PIN, machine.Pin.OUT, value=0)
led = machine.Pin(LED_PIN, machine.Pin.OUT, value=0)
button = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_UP)
RANK = {'STARTING': 0, 'OK': 0, 'WATCH': 1, 'WARNING': 2,
'ALARM': 3, 'SENSOR FAULT': 3}
state = {
'gpo': None, 'amb': None, 'rise': None,
'level': 'STARTING',
'max_gpo': None, 'max_rise': None,
'readings': 0, 'uptime_min': 0, 'muted': False,
}
gpo_rom = None
amb_rom = None
mute_until = None
start_ms = time.ticks_ms()
def hexrom(rom):
return ''.join('%02x' % b for b in rom)
def find_sensors():
"""Scan the bus and work out which sensor is which."""
global gpo_rom, amb_rom
try:
roms = ds.scan()
except Exception:
roms = []
print('Found %d DS18B20 sensor(s):' % len(roms))
for r in roms:
print(' ', hexrom(r))
gpo_rom = amb_rom = None
for r in roms:
h = hexrom(r)
if GPO_ROM and h == GPO_ROM.lower():
gpo_rom = r
elif AMB_ROM and h == AMB_ROM.lower():
amb_rom = r
# No addresses set: first sensor = GPO, second = room
if gpo_rom is None and not GPO_ROM and roms:
gpo_rom = roms[0]
if amb_rom is None and not AMB_ROM:
for r in roms:
if r != gpo_rom:
amb_rom = r
break
print('GPO sensor :', hexrom(gpo_rom) if gpo_rom else 'NOT FOUND')
print('Room sensor:', hexrom(amb_rom) if amb_rom else 'NOT FOUND')
def read_temp(rom):
"""Return deg C rounded to 0.1, or None for a missing/bad reading."""
if rom is None:
return None
try:
t = ds.read_temp(rom)
except Exception: # CRC error or sensor unplugged
return None
# 85.0 is the power-on value = conversion didn't happen
if t is None or t == 85.0 or t < -50 or t > 125:
return None
return round(t, 1)
def classify(gpo, rise, prev):
"""Pick the alarm level, with hysteresis so it doesn't flicker."""
if gpo is None:
return 'SENSOR FAULT'
p = RANK.get(prev, 0)
r = rise if rise is not None else 0 # no room sensor: absolute only
def hit(value, limit, rank):
return value >= limit or (p >= rank and value >= limit - HYST)
if hit(gpo, ALARM_ABS, 3) or hit(r, ALARM_RISE, 3):
return 'ALARM'
if hit(r, WARN_RISE, 2):
return 'WARNING'
if hit(r, WATCH_RISE, 1):
return 'WATCH'
return 'OK'
def update_readings():
if gpo_rom is None: # try again in case a sensor was plugged in
find_sensors()
gpo = read_temp(gpo_rom)
amb = read_temp(amb_rom)
rise = round(gpo - amb, 1) if (gpo is not None and amb is not None) else None
state['gpo'], state['amb'], state['rise'] = gpo, amb, rise
state['level'] = classify(gpo, rise, state['level'])
state['readings'] += 1
state['uptime_min'] = time.ticks_diff(time.ticks_ms(), start_ms) // 60000
if gpo is not None and (state['max_gpo'] is None or gpo > state['max_gpo']):
state['max_gpo'] = gpo
if rise is not None and (state['max_rise'] is None or rise > state['max_rise']):
state['max_rise'] = rise
print('GPO %s C | Room %s C | Rise %s C | %s' %
(gpo, amb, rise, state['level']))
# ------------------------------------------------------------------
# BUZZER + LED patterns (timer runs every 250 ms)
# ------------------------------------------------------------------
tick = 0
def is_muted():
return mute_until is not None and time.ticks_diff(mute_until, time.ticks_ms()) > 0
def alarm_tick(t):
global tick
tick = (tick + 1) % 8 # 8 ticks = 2 s cycle
lvl = state['level']
quiet = is_muted()
if lvl == 'ALARM': # fast flash + fast beep
led.value(tick % 2)
buzzer.value(0 if quiet else tick % 2)
elif lvl == 'SENSOR FAULT': # slow flash + chirp every 2 s
led.value(1 if tick < 4 else 0)
buzzer.value(1 if (tick == 0 and not quiet) else 0)
elif lvl == 'WARNING': # LED on + chirp every 2 s
led.value(1)
buzzer.value(1 if (tick == 0 and not quiet) else 0)
elif lvl == 'WATCH': # short blink every 2 s, no sound
led.value(1 if tick == 0 else 0)
buzzer.value(0)
else: # OK / STARTING
led.value(0)
buzzer.value(0)
try:
timer = machine.Timer(0) # ESP32
except Exception:
timer = machine.Timer(-1) # ESP8266 virtual timer
timer.init(period=250, mode=machine.Timer.PERIODIC, callback=alarm_tick)
# ------------------------------------------------------------------
# WEB PAGE
# ------------------------------------------------------------------
COLOURS = {'OK': '#2e7d32', 'WATCH': '#f9a825', 'WARNING': '#ef6c00',
'ALARM': '#c62828', 'SENSOR FAULT': '#6a1b9a', 'STARTING': '#607d8b'}
def fmt(v):
return '--' if v is None else '%.1f' % v
def web_page():
lvl = state['level']
note = ''
if amb_rom is None:
note = '<p class="s">Room sensor not found - alarm uses GPO temperature only.</p>'
if state['muted']:
note += '<p class="s">Buzzer muted</p>'
return """<!DOCTYPE html><html><head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="refresh" content="%d">
<title>GPO Monitor</title>
<style>
body{font-family:Arial,sans-serif;text-align:center;margin:0;background:#f4f4f4}
.b{background:%s;color:#fff;padding:18px;font-size:2rem;font-weight:bold}
.c{display:inline-block;background:#fff;border-radius:10px;margin:10px;
padding:14px 22px;min-width:120px;box-shadow:0 1px 4px #0002}
.v{font-size:2.4rem;font-weight:bold}.l{color:#555}.s{color:#555;font-size:.9rem}
</style></head><body>
<div class="b">%s</div>
<div class="c"><div class="l">GPO</div><div class="v">%s°C</div></div>
<div class="c"><div class="l">Room</div><div class="v">%s°C</div></div>
<div class="c"><div class="l">Rise</div><div class="v">%s°C</div></div>
<p class="s">Highest since start: GPO %s°C, rise %s°C</p>
<p class="s">Levels (rise): watch %d, warning %d, alarm %d °C · GPO alarm %d °C</p>
%s
<p class="s">Readings: %d · Up %d min · AP Design Labs</p>
</body></html>""" % (SAMPLE_S, COLOURS.get(lvl, '#607d8b'), lvl,
fmt(state['gpo']), fmt(state['amb']), fmt(state['rise']),
fmt(state['max_gpo']), fmt(state['max_rise']),
WATCH_RISE, WARN_RISE, ALARM_RISE, ALARM_ABS,
note, state['readings'], state['uptime_min'])
def handle(conn):
try:
conn.settimeout(3)
req = conn.recv(1024)
path = '/'
try:
path = req.split(b' ')[1].decode()
except Exception:
pass
if path.startswith('/json'):
body, ctype = json.dumps(state), 'application/json'
else:
body, ctype = web_page(), 'text/html'
conn.send('HTTP/1.1 200 OK\r\nContent-Type: %s\r\n'
'Connection: close\r\n\r\n' % ctype)
conn.sendall(body)
except OSError:
pass
finally:
conn.close()
# ------------------------------------------------------------------
# MAIN LOOP
# ------------------------------------------------------------------
find_sensors()
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(('', 80))
srv.listen(2)
srv.settimeout(0.2) # short wait so sensors keep being read
next_read = time.ticks_ms()
conv_start = 0
converting = False
while True:
now = time.ticks_ms()
# 1. Start a temperature conversion when it's time
if not converting and time.ticks_diff(now, next_read) >= 0:
try:
ds.convert_temp()
except Exception: # no sensors on the bus
pass
conv_start = now
converting = True
# 2. 750 ms later, read the result
if converting and time.ticks_diff(now, conv_start) >= 750:
converting = False
update_readings()
next_read = time.ticks_add(conv_start, SAMPLE_S * 1000)
gc.collect()
# 3. BOOT button mutes the buzzer (LED keeps showing the level)
if button.value() == 0:
mute_until = time.ticks_add(now, MUTE_MIN * 60000)
print('Buzzer muted for %d min' % MUTE_MIN)
time.sleep_ms(300)
state['muted'] = is_muted()
# 4. Answer any web request
try:
conn, addr = srv.accept()
except OSError:
conn = None
if conn:
handle(conn)
Setup and testing in Thonny
- Flash MicroPython onto the ESP32 if it isn't already (Thonny: Tools → Options → Interpreter → Install or update MicroPython).
- In Tools → Options → Interpreter, choose MicroPython (ESP32) and the board's COM port.
- Open boot.py, add your Wi-Fi details, then File → Save as… → MicroPython device and name it
boot.py. Do the same formain.py. - Press the board's EN/RST button. The Shell shows the Wi-Fi address and the sensors it found.
- Identify the sensors. Copy the two addresses from the Shell. Hold one sensor in your fingers for 20 seconds and watch which reading climbs. Paste that one into
GPO_ROM, the other intoAMB_ROM, and save main.py again. (Skip this and the code guesses, which may swap them.) - Test the alarm before trusting it: lower
WATCH_RISE,WARN_RISEandALARM_RISEto 2, 4 and 6, warm the GPO sensor in your hand, and check each LED/buzzer pattern. Then unplug the GPO sensor and check you get Sensor Fault. Put the levels back afterwards. - Fit the sensors (above), start a charge, and open the IP address on your phone.
The page refreshes every 10 seconds. For logging or Home Assistant, http://<ip>/json returns the readings as JSON.
Alarm levels
| Level | Default trigger | LED | Buzzer |
|---|---|---|---|
| OK | Rise under 10 °C | Off | Off |
| Watch | Rise 10–20 °C | Short blink every 2 s | Off |
| Warning | Rise 20–30 °C | Steady on | Chirp every 2 s |
| Alarm | Rise over 30 °C, or GPO over 60 °C | Fast flash | Fast beeping |
| Sensor Fault | GPO sensor missing or bad reading | Slow flash | Chirp every 2 s |
A level clears only once the reading falls 2 °C below it, so it doesn't flicker on the boundary. The BOOT button mutes the buzzer for 15 minutes; the LED keeps showing the level. The blog post explains what to do at each level.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| "Found 0 DS18B20 sensor(s)" | Missing pull-up or wrong pin | Check the 4.7 kΩ between GPIO 4 and 3V3, and the pin order |
| Reading stuck at 85.0 or −127 | Bad conversion or loose wire | The code treats these as faults; check the connections |
| GPO and room readings swapped | Addresses not set | Do step 5 of the setup |
| No web page | Wi-Fi didn't connect, or wrong IP | Check the Shell for the address; the alarm still works without Wi-Fi |
| Buzzer silent | Passive buzzer fitted | Use an active buzzer (it has its own oscillator) |
| Watch level on a near-new GPO | Plug not fully home, or the charger box is levering it | Support the cable and box; if it stays at Watch, get it checked |
Disclaimer
This is a hobby early-warning aid, not a certified safety device, and it does not replace an inspection by a licensed electrician. It measures the outside of the faceplate only. Never open a GPO or work on fixed wiring yourself. Shared free by AP Design Labs, with no warranty; build and use it at your own risk.