Power Moves

The plight of the self-made home automator is fraught with setbacks, weird workarounds and lots and lots of tinkering, and mine is no exception.

The Photo-Resistor Hack

In my previous home automation update, I was looking for a way to count the light pulses in my brand new, EDP-provided smart meter. I closed that post musing about hacking one of the Xiaomi Aqara contact sensors (an MCCGQ11LM), and guess what, I woke up one morning with an epiphany (if the diode didn’t, might a simple photo-resistor work?) and decided to try it.

I grabbed my IC probe clips and did the simplest thing that could possibly work–I disassembled one of my spare sensors, clipped each end of the magnetic reed switch and stuck the photo-resistor to the meter with some Blu-Tack:

This is by far the ugliest hack I ever did

And guess what, it worked:

You can clearly see when the heaters were switched on.

As to why this trivial hack actually works, I’m guessing the contact sensor has a built-in debouncer for the reed switch and that is doing the proper logic level conversion for the photo-resistor.

I was a bit worried about battery drain, but so far the sensor battery has held steady at 100% despite sending out a massive amount of events per day compared to all the other sensors. But it’s been only a week, so it’s really too early to tell.

From an MQTT standpoint, I get two events per LED flash: contact=1 and contact=0. Since I feed all the sensor telemetry into a simple SQLite database, grouping ticks per hour to generate the chart above is trivial (although I did some trickery for hourly grouping):

SELECT 
    substr(datetime(time, "unixepoch", "localtime"),0,14) as hour, 
    count(value) as ticks
FROM metrics 
WHERE 
    sensor = 'meter_test' AND
    metric = 'contact' AND 
    value = 1 AND
    time >= strftime('%s','now','-24 hour')
    GROUP by hour
ORDER BY hour ASC;

I’m still not sure this is 100% reliable due to occasional Zigbee wonkiness, but it’s been consistent for over a week, so I’ll be duplicating the setup for my other meter as soon as I get an identical photo-resistor (I had only the one, alas) and 3D print a couple of tiny cases.

Give it a month or two and if both sensors keep working reliably, I’ll check this off my to-do list.

Boosting Zigbee Range

My current setup consists of three CC2531 dongles - a coordinator plugged into the box that runs my zigbee2mqtt container and two others with routing firmware that are plugged in to the USB ports of my twin Airport Extreme base stations (which are themselves placed strategically inside two closets on opposite sides of our U-shaped flat).

However, the “far” router keeps losing connectivity, so I decided to up the ante by sheer brute force, which in this case entails adding a dipole antenna to each by soldering an SMA connector . I’m hoping that will enable them to talk to each other properly across four brick walls, which just isn’t happening right now–temperature measurements from the “far” side of the house are spotty at best.

Thanks to the jitter involved in getting several different little packages shipped from China, I got two new CC2531 dongles and the dipole antennae, but no SMA connectors yet, so I all I could do was prep the dongles for soldering the connectors:

The two new routers, all ready for soldering the SMA connectors in place

These will also get 3D printed cases, and the “old” ones will be turned into a test setup (I want to try out a few things with software-defined radios that have nothing to do with Zigbee, but that’s another story).

Lights, Neutral, Action

With power power monitoring on the verge of being sorted out, I have been thinking about automating lights again.

Since none of my wall switches have neutral wires (neutral only meets phase at ceiling mounts), I finally resorted to adding a Sonoff Basic module to my office light (which works great, since it’s a fluorescent fixture) and am pondering getting some IKEA TRADFRI bulbs for testing.

But most of my ceiling lights are either GU10 or 12V LEDs, so that’s going to be a challenge… I sense more Sonoffs in my future.

See Also: