Z-Wave and Emacs

I’ve had a 433-MHz-based “home automation” system (i.e., light switches) for quite some time. It works kinda OK. That is, I’m able to switch the lights on and off, which is the main point.

But, man, the range of 433MHz devices sucks, including all Telldus models. I’ve been able to overcome the problems by having transmitters all over the apt, but getting wall-mounted light switches to work with any kind of reliability has proven impossible.

The problem is that the protocol is just inherently unreliable: It just sends commands out into the ether, and doesn’t have any replay logic or ACKs going on.

But there’s newer (but also old) tech available, and 433MHz devices are disappearing from the stores, and the winning protocol is Z-Wave.

So I got a Z-Stick:

It’s a nice device: You plug it in and it shows up as either /tty/USBx or /tty/ACMx (depending on the model, but it makes no difference), and you talk to it by squirting some bytes at it.

I had expected the protocol to be really well-defined and open, but it’s a proprietary protocol that people have been reverse-engineering for years, which led me to believe that there surely would be a nice repository somewhere that describes the protocol in detail, and has, say, an XML file that describes all the different network packages.


But after some googling I found this gist that at least let me check whether I can talk to the device…

… and it works!

It turns out that the Z-Wave protocol is kinda nice. Each package has a checksum, and devices retransmit commands a few times unless they get an ACK, and Z-Wave plugged-in devices (like outlets) work as repeaters, so the Z-Wave network works as a mesh. It’s kinda cool.

There’s a ton of software to control these devices, but using something like Open HAB is just so… end userish.

Instead I wanted to just plug it into my existing Emacs-based system so that I don’t have to, like, use software. Software sucks.

If no machine-parseable spec is available, at least there must be some other sensible software out there that I can just crib implementation details from, right? So I binged “z-wave python”.

And just found Python OpenZwave, which turns out to be nothing but a wrapper around OpenZWave, which is a C++ library.


It’s a simple protocol, really. You just read from a serial device and then squirt some bytes at the device. It’s not like you need to do Fourier realtime transforms on a vast byte stream or anything.

But who am I to criticise people for choosing odd programming languages to implement their free software? Since it’s C++, at least probably they created some kind of over-engineered monster where you have some XML files that define the protocol, and then they create objects from the stream and use a lot of polymorphism that’ll make the control flow impossible to follow (according to the “everything happens somewhere else” object oriented methodology), but that’s good, because I can just use the protocol definition files and ignore the rest.



No, the main work flow is based on nested if statements with lots of “switch( _data[1] )”. But surely after that they’ll parse the protocol packages into something sensible?


Well, at least they used variable names that’s understandable. But what’s data[4] and data[6]?



Ok, again, I have no business giving a code critique of this library written by, I’m sure, very nice people and put on the intertubes for the world to peruse and use, and despite being written in the “least information density per pixel displayed” style, it’s clear and easy to follow, and has an impressive amount of comments. It’s still all kinds of wrong.

Perhaps it’s just coming from a different culture? It’s Windows-style programming?

I don’t know, but anyway, with the guidance from this excellent piece of, er, software, I was able to make Emacs parse and execute commands when I touch a wall switch.

And Z-Wave works! Where a couple my light switches were a bit hit and miss before, they now work with 100% reliability over the last week.

I don’t have any Z-Wave outlets yet, so I haven’t bothered to implement sending commands to devices, but I’m sure I’ll have to implement that at some point. But as far as I can tell, that should be pretty straight-forward. I foresee a lot of “but what’s _data[7]?” in my future.

Somebody should still create a Z-Wave repo with protocol definitions, especially since it’s now an open-ish standard. But only as PDFs, of course.

[Edit: I should have googled a bit more, because it pretty much looks like everything I wondered about is in the OpenHAB distribution, which is in Java and has more XML protocol definition files than you can shake a stick at. Well done, Java peeps.]

August 1940: Night Train to Munich

Night Train to Munich. Carol Reed. 1940.

I’m guessing that Carol Reed isn’t a woman? Yes? It just occurred to me that I did no filtering for gender when I bought these films, so I’m wondering whether this is going to be a 120 movie sausage fest…

Anyway! I was very impressed by the montage at the beginning of the movie, showing Germany moving into one neighbouring country after another. Very efficient.

While The Mortal Storm was a melancholic look at what happened inside Nazi Germany, Reed displays none of that diffidence in his movie. Instead this is a call to arms. But of course, that was an American movie, and this is a British one.

This is a really good spy thriller, with lots of turns and twists and fun. Great, roaming cinematography and likeable actors, too.

And very funny.

The version I saw was the Criterion blu-ray, and it looks good and sounds great, which is a relief after being subjected to a Amazon Prime version of a film earlier today.

Popular movies in August 1940 according to IMDB:

Poster Votes Rating Movie
sc-tt0032484.jpg 14154 7.6 Foreign Correspondent
sc-tt0032617.jpg 2247 7.5 I Love You Again
sc-tt0032842.jpg 3229 7.3 Night Train to Munich
sc-tt0032986.jpg 253 7.1 Rhythm on the River
sc-tt0032273.jpg 2397 7.1 Boom Town
sc-tt0033107.jpg 2611 6.9 Stranger on the Third Floor
sc-tt0032983.jpg 2168 6.7 The Return of Frank James
sc-tt0032376.jpg 1302 6.7 Dance, Girl, Dance
sc-tt0033288.jpg 266 6.6 Young People
sc-tt0032481.jpg 236 6.6 Flowing Gold

This blog post is part of the Decade series.

July 1940: The Great McGinty

The Great McGinty. Preston Sturges. 1940.

I like the plot structure, what with most of the movie being a flashback, and I like that the protagonist is, well, a crook. But such a personable crook. It’s all about grift and the mob running US politics and stuff, really, and we’re cheering them on.

Being a crook is the greatest!

The ending is nothing like I expected it to be. Cool!

(Is that a beaver skin top hat?)

Popular movies in July 1940 according to IMDB:

Poster Votes Rating Movie
sc-tt0033028.jpg 7390 7.8 The Sea Hawk
sc-tt0032194.jpg 3301 7.7 All This, and Heaven Too
sc-tt0032554.jpg 2535 7.5 The Great McGinty
sc-tt0032943.jpg 6220 7.4 Pride and Prejudice
sc-tt0033149.jpg 5625 7.3 They Drive by Night
sc-tt0032206.jpg 598 6.8 Andy Hardy Meets Debutante
sc-tt0032277.jpg 477 6.8 Boys of the City
sc-tt0033254.jpg 411 6.6 When the Daltons Rode
sc-tt0032829.jpg 341 6.4 My Love Came Back
sc-tt0032686.jpg 433 6.4 The Lady in Question

This blog post is part of the Decade series.

June 1940: The Mortal Storm

The Mortal Storm. Frank Borzage. 1940.

This is the first war film in this blog series, and I assume that there’ll be a lot more, but perhaps not before December 1941? It’s the first one that touches on the war in Europe at all, except for a throw-away line in His Girl Friday.

Anyway, this isn’t quite the war movie I was expecting. It’s a movie about Germans, and the ones that aren’t Nazis are portrayed very positively indeed. So it’s an anti Nazi film, but with more pacifist overtones than would follow once Hollywood became a part of the war effort.

For all its good intentions, it’s a kinda pedestrian film? The actors mostly just stroll through the movie without making much impression. (But I did enjoy the old woman at the farm while the Nazis were looking for that guy. So stoic.) There’s nothing particularly exciting about the cinematography.

So it’s more about the idea of the movie than the film itself, and I was watching it with ever-increasing detachment.

(Except the final chase scene, which was thrilling, of course.)

Popular movies in June 1940 according to IMDB:

Poster Votes Rating Movie
sc-tt0032811.jpg 3373 7.9 The Mortal Storm
sc-tt0031359.jpg 2717 7.4 Gaslight
sc-tt0032520.jpg 2363 7.3 The Ghost Breakers
sc-tt0032285.jpg 1789 7.1 Brother Orchid
sc-tt0032840.jpg 394 7.1 New Moon
sc-tt0033169.jpg 314 6.8 Tom Brown’s School Days
sc-tt0032901.jpg 218 6.2 Phantom Raiders
sc-tt0033117.jpg 834 5.7 Susan and God

This blog post is part of the Decade series.

May 1940: Our Town

Our Town. Sam Wood. 1940.

I hadn’t quite realised how many of films from the early 40s were based on theatre plays. I think so far it’s been… all of them? Almost all of them? This is another one.

This was nominated for all the Oscar awards, including “best sound, recording”, and the sound is horrible. But perhaps “recording” doesn’t mean the actual sound on the film? I can barely make out what they’re saying.

Could be the transfer. I watched the Amazon Prime version, and those are frequently astoundingly awful.

It didn’t win any.

It’s a pretty unique movie. It’s a cod-serious presentation of the town interspersed with “dramatic” scenes. Very sentimental… but it really works, I think.

But my enjoyment was serious impaired by the sound quality, so the dice rolled lower than it would otherwise, I think.

Popular movies in May 1940 according to IMDB:

Poster Votes Rating Movie
sc-tt0033238.jpg 7198 7.8 Waterloo Bridge
sc-tt0032326.jpg 928 7.7 Charlie Chan’s Murder Cruise
sc-tt0029284.jpg 7317 7.4 My Favorite Wife
sc-tt0032432.jpg 1204 7.1 Edison, the Man
sc-tt0033175.jpg 980 6.9 Torrid Zone
sc-tt0032881.jpg 1762 6.8 Our Town
sc-tt0032247.jpg 885 6.7 Beyond Tomorrow
sc-tt0032710.jpg 306 6.7 Lillian Russell
sc-tt0033013.jpg 428 6.6 The Saint Takes Over

This blog post is part of the Decade series.

April 1940: The Doctor Takes A Wife

The Doctor Takes A Wife. Alexander Hall. 1940.

You gotta admire the sheer preposterousness (that’s a word) of the premise here, but it just doesn’t fire on all cylinders. It’s also a very typical “battle of the sexes” thing of the period, which doesn’t help.

But there’s a lot here to enjoy. The performances are on fleek, and it’s got a nice propulsive energy throughout. When it works, it really works.

Popular movies in April 1940 according to IMDB:

Poster Votes Rating Movie
sc-tt0033022.jpg 1821 7.2 Saps at Sea
sc-tt0032475.jpg 895 7.1 Flash Gordon Conquers the Universe
sc-tt0032289.jpg 240 7.1 Buck Benny Rides Again
sc-tt0032397.jpg 552 7.0 The Doctor Takes a Wife
sc-tt0032383.jpg 1742 6.9 Dark Command
sc-tt0032176.jpg 405 6.9 ‘Til We Meet Again
sc-tt0031828.jpg 262 6.7 The Proud Valley
sc-tt0032643.jpg 724 6.7 It All Came True
sc-tt0032412.jpg 1610 6.5 Dr. Cyclops
sc-tt0032753.jpg 386 6.5 The Man with Nine Lives

This blog post is part of the Decade series.

March 1940: Too Many Husbands

Too Many Husbands. Wesley Ruggles. 1940.

Hm… Did I see this before? I didn’t think so… Is it part of a box set I’ve bought some years ago?

*time passes while I rummage through the bookcase*

I dud have it! On “Icons of Screwball Comedy Volume One”. Well, this isn’t a very good track record for this blog series so far: I’ve seen 66% of the films previously.

Anyway, it’s a very high concept movie. A man was lost, presumed dead, and his wife remarried. Then he returns, and now she’s married to two people. Hilarity ensues.

There’s a lot of lines like “She’s our wife!” and people doing double takes. It’s fun! I, like, lol-ed out loud at bits. It dances around all the awkward bits and ends up being very modern.

But this isn’t exactly a masterpiece. I think it aims for madcap insanity, but it only achieves slightly bizarre quirkiness.

But it’s a great premise and they soldier through admirably. It’s from a veteran director, Wesley Ruggles, who’d made films from 1917 on.

Popular movies in March 1940 according to IMDB:

Poster Votes Rating Movie
sc-tt0032976.jpg 91851 8.2 Rebecca
sc-tt0032420.jpg 220 7.4 Drums of Fu Manchu
sc-tt0032993.jpg 3004 7.1 Road to Singapore
sc-tt0032651.jpg 789 7.0 Johnny Apollo
sc-tt0032946.jpg 944 7.0 Primrose Path
sc-tt0033105.jpg 1581 6.9 Strange Cargo
sc-tt0033226.jpg 1598 6.8 Virginia City
sc-tt0032644.jpg 374 6.7 It’s a Date
sc-tt0032609.jpg 293 6.5 The House Across the Bay
sc-tt0033174.jpg 946 6.5 Too Many Husbands

This blog post is part of the Decade series.