Script and Docker image for monitoring an EKM meter over GPIO and logging readings in SQLite.
- Build the image:
docker build -t ekm-meter-watcher .- Create a
docker-compose.yamllike this:
services:
ekm-meter-watcher:
image: ghcr.io/snoack/ekm-meter-watcher:latest
restart: unless-stopped
devices:
- /dev/gpiochip4:/dev/gpiochip4
# environment:
# EKM_GPIO: "27"
# EKM_TIMEOUT: "10"
# EKM_LOG_LEVEL: WARNING
# EKM_AGGREGATE_AFTER_WEEKS: "6"
# EKM_AGGREGATE_BY_SECONDS: "3600"
volumes:
- ./data:/dataThese environment variables are optional; the commented values shown above are the defaults.
- Start it:
docker compose up -dThe host still needs to expose the GPIO character device you map in devices.
By default the watcher reads pulses from GPIO 27, which is physical pin 13
on the Raspberry Pi. If using a different GPIO pin set EKM_GPIO accordingly.
The EKM meter pulse output behaves like a switch that closes and opens 800
times per kWh used. Wire it like this:
- Supply
3.3 Vfrom the Pi to the meter. - Put a
1 kOhmresistor in series with the input GPIO pin to limit current. - Add a
10 kOhmpull-down resistor on the GPIO input, on the meter side of the1 kOhmresistor. - Connect the meter pulse output to the GPIO input.
The script requests the GPIO line with bias disabled, so the external pull-down is required.