I got my Z-Wave Raspberry Pi setup a few weeks ago, and then spent a ton of time setting up my Bedroom Lights, Bathroom Fan+Light, and ordered even more Z-wave hardware. I also started up an RTL-433 server for a yet unfinished project, and about a week later, Home Assistant suddenly reported all of my Z-wave devices offline. Home Assistant was unable to connect to the WebSocket of ZWaveJS. The Pi was acting really weird. SSH responded but rejected my login, and when I plugged in an HDMI cable and rebooted it got a kernel panic due to mmc driver failure. The SD card had failed. It wasn’t a new SD card, so I guess I should buy a bulk pack and stop re-using them. Since I really liked having a Z-Wave network, I want to make sure that I properly setup the new raspberry pi OS install to prevent excessive logging from taking down the whole thing in the future. This also gives me a huge appreciation for how nice the backup features of virtual machines are, and how much I miss them on the Raspberry Pi. I don’t have a backup of the Z-Wave network, so that’s another feature that would be nice to consider in the second try.

I started with a brand new SD card and imaged it with Raspberry Pi OS in Etcher. I did the usual raspi-config, set the hostname, timezone, apt-get update/upgrade, the usual. Then I proceeded to install ZWaveJS2MQTT according to their instructions (using the Snap package). Thankfully, a lot of the Z-wave network parameters are actually stored in the dongle, so I didn’t have to re-associate all of the devices (whew!). But, the metadata is stored locally, and was lost. Home Assistant didn’t care about the loss of metadata, since it keeps its own metadata for each node ID, but things like node names in zwavejs2mqtt were gone. Not nearly as bad as I thought it would be.

My next plan is to start backing up the zwavejs2mqtt install’s store folder for safe keeping. With the snap package it’s stored in:

/var/snap/zwavejs2mqtt/current

So I can just make an autofs mount to the place I keep backups on my NAS, then tar that directory into the backup folder. This won’t keep revisions, but it will keep the latest copy. What I really want is to keep the last few days of backups (presumably I’d notice something within a few days?), but with as simple a script as possible. I found this script helpful in creating my own. After mounting my desired backup location using autofs to /mnt/backup, I wrote my backup script and added it to root’s crontab.

#!/bin/bash
####################################
#
# Backup the ZWaveJS2MQTT stores directory
#
####################################

# Create archive filename based on the day of the week
day=$(date +%A)

# Backup the files using tar. Need h since 'current' is a symlink from Snap
tar chzf /mnt/backup/zeus_store_$day.tar.gz /var/snap/zwavejs2mqtt/current

After stripping down the script to the bare minimum, it will generate a new tar.gz file for each day of the week, overwriting the previous. Now I need to add a cron job to run the backup script

sudo crontab -e

And the new contents - this will run at the 0 minute of the 0 hour (midnight), all days of all weeks of all months (so every day).

0 0 * * * bash /mnt/backup/backup.sh

After making sure my backups are in order, I need to make the SD card stop dying. After reading some Raspberry Pi specific help, it seems like /var/run used to be on the SD card but is now a symlink to /run, which is a tmpfs in RAM. So that’s good. /var/log is still on the SD card and I could make that a tmpfs as well, but I’m not sure if that’s actually being written to regularly. It doesn’t seem like ZWaveJS2MQTT is creating any trouble on the filesystem, so maybe it was RTL-433 that was on my last setup, and I’ll need to more closely monitor it when I get to fixing that.

At this point, ZWave is working again (very happy about that), so I need to setup RTL-433 again, and write the project page on my 433Mhz sensors. More to come!