Midnight Pub

Home Automation and Zigbee

~tetris

~tetris sidles up to the bar, holds up two fingers, claps, and watches with a shit-eating grin as all the lights go out~

So I've been dabbling a little in home automation this week.

Ever had to signal your SO by flashing on and off the sofa light because you're stuck outside in the cold since you forgot your keys, and she's not answering the phone?

Until yesterday, this was not something I'd have had to do, but I've crossed this threshold now in the relationship and I expect full retribution sometime later when I'm seemingly home alone.

Current Setup

It started out with me just wanting to know how much energy I was using, and looking for a digital energy reader plug socket. Then I went down a rabbit hole and ended up automating everything.

I've got full control of all of the side lights (i.e. lights that go into a socket), the fridge, the kettle, and have digital thermostats on all but two radiators. These are all Zigbee devices controlled by Home Assistant, running off my Raspberry Pi 4.

Um, Zigbee?

Zigbee

This is a wireless low-energy radio specification that runs in similar frequencies to Wifi, but isn't Wifi. As in, it has no access to the internet and can't actively spy on you by sending telemetry to some suspicious Chinese server.

Zigbee devices form a mesh network with one another, and can ping each other for information via a Zigbee gateway device (again, NOT WiFi). A mesh network allows Device A to talk to Device B, via a path of C, D, and E if A and B are too far away to directly ping each other.

In order to interact with this network, you need a Zigbee gateway device that you can interact with, so for the Raspberry Pi I bought this USB device "SONOFF Zigbee 3.0 USB Dongle Plus, TI CC2652P + CP2102(N)"

Home Assistant

Home Assistant

This is an open source automation software that integrates with a bunch of different wireless or wired devices, offers up their capabilities in a manageable way.

e.g.1 When it's [trigger:Sunny] , [action:switch off] the [device:Front Light], and set the [device:Kitchen Radiator] to [action:18°C].

Home Assistant works with pretty much anything (e.g.2. the battery level on your phone, the GPS coordinates of your car, the amount of energy being supplied by your solar array (one day this dream will be mine....))

Home Assistant works also very well with Zigbee devices, and manages them via a library called ZHA (ZigbeeHomeAutomation).

Is Home Assistant Trust-worthy?

I think so. It's free and open source, but it has a very commercial-ly kind of vibe, which leads me to believe that they might monetize soon in the same way that Owncloud did.

That being said, if you want direct control over your Zigbee devices without giving all the control the Home Assistant, there are some great alternatives:

Zigbee2MQTT and
Mosquitto.

MQTT?

MQTT

Yeah so, Zigbee I think is the mesh protocol that allows devices to connect with one another in a low-power way. MQTT is the actual communication protocol that runs on top of it(?) that creates a "message broker <-> client" relationship, where one of your zigbee devices (the Zigbee Gateway Device) manages the messaging between your Zigbee clients.

Zigbee2MQTT therefore is a piece of software that translates(?) the Zigbee signalling into something compliant with MQTT.

Okay..., and Mosquitto?

Mosquitto is the software that provides a working open source implementation of the MQTT protocol.

The idea then is that instead of the using the ZHA library from Home Assistant, you would put on your tinfoil hat and run Zigbee2MQTT which would feed data into Mosquitto, and then you could control your Zigbee devices via Mosquitto.

Um, why Zigbee2MQTT -> Mosquitto instead of Home Assistant?

Why indeed. Well, for one, you get much more control over your Zigbee devices and their sensors, and can perform over-the-air updates to the firmware of these devices, which ZHA cannot do.

For another, if Home Assistant decide to sell out and start doing something malicious, then there is a good alternative via Zigbee2MQTT.

Zigbee2MQTT also has a fantastic list of supported devices (see above Zigbee2MQTT link) and their capabilities, whilst Home Assistant does not.

Lasting Thoughts

Home Assistant is great. It's simplified and overcomplicated my life in the last few days, and I'm enjoying and hating every minute of it. I'm planning to replace all my actual light switches with Zigbee devices, and also add motion detectors that can act as light triggers, and my own outside temperature controls just coz.

I'm using the current devices flawlessly:


johano

Noswaith dda, ~tetris!

This is an interesting post, and something I've given tiny amounts of thought to in the past... once I got into having a home server and self-hosting things, the next thought was "what else can I tinker around with?" I don't think I'll jump in *just* yet, but if/when I do, what you wrote will be a good reference!

Or who knows, maybe I'll start messing around with software defined radio and revive my younger habit of listening to shortwave broadcasts...

reply

tetris

Bore da, ~johano!

I started out the same way. It was first me trying to get Nextcloud working so I could move away from Google (spoiler: Nextcloud is more of a backup thing now, as my SO finds nextcloud slow, and so she still uses Google Fotos for most things).

Then I struggled a lot in getting an HTTPS Let's Encrypt certificate running on my home server without a public IP4 address (Spoiler: do an ssh reverse proxy to a machine that has a public IP, and forward only your port 80 so that the certificates are still installed on your home server).

And then I disappeared down this rabbit hole :-)

I'm currently dabbling in open source drone programs, converting an old Parrot Bebop drone into an automated device I can control with my Pi. I'm at stage one currently: getting the damn Arducopter firmware on to the damn drone, and communicating with it via Mission Control. The calibration is the next step, and it's way more fiddly then the original firmware. Speaking of radios, I might have to erect something serious keep the drone connected....

Messing around is fun!

reply

johano

Sut wyt ti gyda'r nos 'ma, ~tetris?

My path was kinda the same, I wanted to get away from using Google Drive and Dropbox, etc, so I set up Nextcloud and then wound up using it for syncing calendars and contacts and so on. It's worked pretty well, although it's getting to the point where I may need to upgrade my hardware to make it snappier... that's my other homelab project for the year, I guess.

I also had struggles getting Let's Encrypt setup while behind CG-NAT, my solution was to go ahead and pay for static IP but I might do your solution in the future.

Ooohh drones are intriguing to play with too :)

reply

contrarian

Home automation IS the future we were promised.

reply

tetris

and it's delivering, but the potential for abuse is absolutely huge. I won't be surprised if this becomes the next big scandal of the decade, where you have to pay a monthly stipend to some company to put the kettle on for you when you come home, and the kettle won't switch on otherwise because dumb devices become scarcer and scarcer

reply