Counting vends on the office drinks machine: send each vend or a running total?
Fun side project. I read the old story of the university Coke machine that reported its stock over the network in the early 80s and wanted to do the same for our office drinks machine (old Sanden unit, no electronics worth talking to).
I’ve put a microswitch on the drop chute of each of the 6 columns, wired to a Wemos D1 mini. It counts drops. Now I don’t know what to send to Hermetry. Option 1: on each vend send {“col3”: 1}. Option 2: keep a running total per column and send it every 5 minutes. I want a chart of vends per day and I’d like to know when a column is probably empty (we refill on Mondays, 40 cans per column).
Which way do people do this?
Whatever you do, debounce the microswitch. A can bouncing down a chute will give you 3 counts.
Some of those machines have an MDB bus inside that reports vends properly, might be worth a look before you drill more holes.
What happens to the running total when the Wemos reboots? Power cuts when the cleaners unplug it, I’d bet.
It starts at zero again. I hadn’t thought about that. No MDB on this one, I checked, it’s older than me.
I did this for the laundry machines in two of our buildings (coin counts), so here’s what worked for me even though I’m no programmer.
Send a running total per column, every few minutes, as plain numbers:
{"vend.col1": 1834, "vend.col2": 977, "vend.col3": 2210, ...}
Then on the chart card pick the aggregate “increase”. It’s made for counters: each bucket shows how much the counter went up, and if the value goes down because the board rebooted, it counts from zero instead of showing a huge negative. So a reboot costs you nothing as long as you don’t reboot twice inside one bucket and land above the old value.
Sending {“col3”: 1} per vend also works with “sum”, but if a message is lost the count is gone for good. With totals the next message catches up.
One thing that tripped me: day buckets are UTC days. We’re on Eastern time, so my “per day” bars were split at 7 or 8 pm. For local days use hourly buckets and add up the hours, or just live with it.
For “probably empty”: store the total at refill time (I write a server attribute per column on Monday from the device page) and alert when total minus that passes 38 or so. I do that part in a flow because an alarm condition can’t do arithmetic between two values.
Page is Aggregates and rollups.
Switched to running totals every 5 min and “increase” with 1h buckets. Unplugged it twice on purpose and the chart didn’t flinch. Jason was right as well, column 4 counted triple until I added a 150 ms debounce. Empty-column alert is next weekend’s job.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

