Migrate Home Assistant to Argon One M.2 SSD

Now that my previous issues with the Argon ONE M.2 case have been resolved, I’m able to finally put the case to use for its originally intended purpose, as the new home for running my Home Assistant instance. Over the years I’ve had a small number of MicroSD cards fail in my Pi’s running Home Assistant, though this has been mitigated over time by switching to using SanDisk Max Endurance micro SD cards, along with switching the SQLite running on the Pi to a MariaDB on a network-connected server. However, now that the Raspberry Pi 4 and Home Assistant support USB boot for SSD storage, I thought I could consolidate and get a speed boost from the SSD storage.

My Home Assistant Server Hardware

  • Argon ONE M.2 Case for Raspberry Pi 4
  • Raspberry Pi 4 – 4GB version
  • Transcend 240GB M.2 SATA SSD (short 42mm M.2 card, just what I had available)
  • RFXCOM RFXtrx433E USB 433.92MHz Transceiver
  • Nortek HUSBZB-1 USB Zigbee Hub (Z-Wave USA frequencies only)

Preparation

Prepare Snapshot

If you’re performing a new install and not a migration, you can skip this step.

If you’re starting with an existing installation then create a full Snapshot and download the file, we’ll upload this later to restore the system to persist the current setup. This will also serve as a second backup (in addition to the SD-Card) should things go wrong along the way. You create a Snapshot via the Home Assistant UI: Supervisor > Snapshots > Create Snapshot. Once created, click on the Snapshot and then “Download Snapshot“, which will save the .tar file to a location of your choice.

Now, shutdown the current Home Assistant Raspberry Pi and remove the micro SD-Card.

Prepare Raspberry Pi 4 for USB Boot

Being able to boot from a USB connected SATA drive, is a relatively recent update to the Raspberry Pi, as such you may need to configure your Raspberry Pi with the latest firmware to allow it to work. If you’ve not updated your Pi you may need to update and enable USB boot. Fortunately, this process has been simplified thanks to the new Raspberry Pi Imager tool.

First, you’ll need a spare micro SD-Card (assuming you want to keep your current card as a backup), secondly, you’ll need to download the Raspberry Pi Imager, once downloaded run the Imager:

  • Operating System: Choose OS > Misc utility images > Bootloader > USB Boot
  • Using your spare micro SD-card, insert this into your card reader and under Storage: Choose Storage > [Pick your SD card from the dialog]
  • Choose: Write and wait for the image to be written to the card and unmounted (ejected).
  • Insert the micro SD-card into your Raspberry Pi and power up the Pi and give it a few mins to boot, update the firmware and set the device to boot from USB.
  • After a few mins, power off the Pi and remove the SD-card.

Installing Home Assistant Directly onto SSD

Whilst the Raspberry Pi Imager includes Home Assistant under the “Operating System” list, it may not be the latest version. So better to download the latest image directly from the HomeAssistant.io website, opting for the 64bit image. At time of writing, this was: haos_rpi4-64-6.1.img.xz

In order to install Home Assistant directly onto the SSD in the base of the Argon ONE M.2 case, you’ll need to connect the Argon M.2 board to your PC. To do this requires a USB-A to USB-A cable, a slightly unusual cable you may not have on hand, but easily sourced and inexpensive. Alternatively, you’ll need an adapter to allow the M.2 drive to be directly connected to your PC via USB.

  • Using the Raspberry Pi Imager (or Balena Etcher, or similar) set Operating System: Choose OS > Use custom then pick the haos image file downloaded previously.
  • Connect the M.2 SATA SSD drive via a suitable cable or adapter to your PC, it should be recognised as a USB drive. Select Choose Storage > Argon Forty SCSI Disk Device
  • Time to Write the image. Once complete you can disconnect the drive from your computer and it’s ready to be used with the Pi.

Preparation is now complete, you can assembly your Argon ONE M.2 case, ensuring you’ve removed the micro SD-card from your Raspberry Pi.

Setup Home Assistant

Network Connection

If you can, I’d recommend setting up Home Assistant initially with the Pi connected via a wired ethernet connection to your network. Wireless can be configured via the Home Assistant UI later (Supervisor > System > Host > IP Address > Change > WI-Fi) if needed. If this isn’t an option you can configure WiFi via a number of means, I’ll cover just one method.

WiFi Configuration

  • Reconnect Argon ONE M.2 drive to your computer. The drive should mount as: hassos-boot
  • Create folders \Config\Network
  • Create a file \Config\Network\my-network (ensure it doesn’t have any file extension, e.g. .txt)
  • Edit the file my-network with either Visual Studio Code or Notepad++ (as we need to change the file line endings)
  • Using the template below, enter your WIRELESS_SSID and WIRELESS_PASSWORD, if you have multiple devices you may also want to set a new uuid, you can generate using this Online UUID Generator.
  • Before saving the file set the line endings to LF not the Windows defauly CRLF. In VSCode this can be done using the selector in the footer area
[connection]
id=my-network
uuid=e9fd4bfd-91f6-4684-b85e-759c66de6976
type=wifi

[wifi]
mode=infrastructure
ssid=WIRELESS_SSID

[wifi-security]
auth-alg=open
key-mgmt=wpa-psk
psk=WIRELESS_PASSWORD

[ipv4]
method=auto

[ipv6]
addr-gen-mode=stable-privacy
method=auto

Initial Home Assistant Setup

It can take several minutes for HomeAssistant to complete the initial setup, you can monitor progress if you connected to the HDMI connection, or just have a cup of tea and check back later. Once set up the Home Assistant instance should be available at alternatively check your DHCP allocations and determine what IP address has been issued.

Restore Snapshot

If your snapshot doesn’t have a password select the link at the bottom of the initial screen, to upload and restore your snapshot.

Otherwise, if your snapshot is password-protected, create a temporary user account, and complete the setup wizard. Don’t worry about the details as all this will be reset once the snapshot is restored. Once the wizard is complete navigate to: Supervisor > Snapshots and click on the 3 dots menu in the top right, then select: Upload snapshot and pick your snapshot. Once uploaded enter the password and select Restore.

Once the snapshot has been restored, you should see your Home Assistant instance running as before the migration. We now need to make configuration changes specific to running with the Argon ONE enclosure.

Argon ONE Configuration

The Argon ONE enclosure provides a great passive cooling solution, but with the option to control a fan to provide active cooling if needed. The enclosure also provides a power button that can be used, but both use I2C, which isn’t enabled by default in Home Assistant.

Enable i2c Support

As always there are multiple ways of enabling i2c, I’ll cover one method here.

  • If powered on, shutdown your Raspberry Pi.
  • Reconnect Argon ONE M.2 drive to your computer. The drive should mount as: hassos-boot
  • Create folders \Config\modules
  • Create and edit a file \Config\modules\rpi-i2c.conf and the following line:
i2c-dev
  • Before saving the file set the line endings to LF not the Windows defauly CRLF. In VSCode this can be done using the selector in the footer area.
  • Next edit \config.txt at the the root of hassos-boot. Add these to the end of the configuration file:
dtparam=i2c_vc=on
dtparam=i2c_arm=on
  • Save changes, then disconnect the M.2 SSD from your computer and reconnect to the Raspberry Pi and boot it once again.
  • Upon boot hassos will read the rpi-i2c.conf file, however it requires a further reboot before this can be used. So once booted goto: Supervisor > System > Host > Reboot Host

Fan Control

I found a couple of options for adding automated Fan Control to Home Assistant and went with the Argon ONE Active Cooling Addon.

  • Navigate to the Argon ONE Active Cooling Addon page and press the “Add Respository” button. Alternatively within your Home Assistant goto: Supervisor > Add-on Store select Respositories from the tripple dot menu in the top left and add: https://github.com/adamoutler/HassOSArgonOneAddon
  • Once added, select ArgonOne Active Cooling from the list of available Add-ons and install it
  • Once installed, select Start then navigate to the Addon Log. The log should look similar to:
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: ArgonOne Active Cooling
 Actively keeping your Argon One cool.
-----------------------------------------------------------
 Add-on version: 23
 You are running the latest version of this add-on.
 System: Home Assistant OS 6.1  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2021.7.1
 Home Assistant Supervisor: 2021.06.8
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Detecting Layout of i2c, we expect to see "1a" here.
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- 1a -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Settings initialized. Argon One Detected. Beginning monitor..
Current Temperature 46 °C
2021-07-11_14:36:35 Level 1 - Fan 0% (OFF)
  • If you get an error when i2c, check you completed the steps to enable i2c above and that you have rebooted your Pi.
  • The configration can be changed between degrees F and degrees C. My configuration (in YAML) is:
CorF: C
LowRange: 55
MediumRange: 60
HighRange: 75
QuietProfile: true
Create a Fan Speed entity in Home Assistant: true
Log current temperature every 30 seconds: false
  • Note that the option to “Create a Fan Speed entity in Home Assistant”, isn’t all that useful. As it only works if you start/restart the add-on after Home Assisatant has started.
  • You can monitor Home Assisatant temperature using the built in sensor: sensor.ha_cpu_temperature which appears to update every minute.

Power “Always On”

Current versions of the Argon ONE case have a jumper that can be configured so that when power is connected, the Pi boots immediately without needing to press the power button. This is probably what we want for Home Assistant, in order to ensure that after a power cut, our system is up and running. Sadly older versions of the Argon ONE, Lacked this jumper and could only be set via a special command being sent via i2c. I doubt this is going to be a problem for anyone with a current case, so I’ll not cover that hack here, instead, you can learn about the code here.

SSD Optimisations

As Home Assistant (HAOS) runs using a collection of Docker images, using SSH to connect into your Home Assistant opened a session within a docker container, whereas for the low-level changes we need to do, we need to access the underlying OS. For obvious security reasons access to this isn’t enabled by default and you’d want to ensure you restrict access to this endpoint.

This guide provides some clear steps to get access to the underly system that we need. Though the page needs to be translated from Italian by google translate.

Enable Trim Support

Not all SATA SSD Controllers support Trim, however, those that do will increase the life of your SSD. The controller used in the Argon ONE M.2 case does support trim, but it’s not enabled automatically. At least not at the moment.

Connect to your Pi on port 22222 logging in as root. Below shows the initial series of commands showing trim isn’t enabled. The lsusb command lists out the attached USB devices, depending on the version of the M.2 board the last 4 digits of the device ID may be different, but I believe they all have the same prefix 174c.

# fstrim -v /
fstrim: /: the discard operation is not supported
# lsblk -D
NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda           0        0B       0B         0
|-sda1        0        0B       0B         0
|-sda2        0        0B       0B         0
|-sda3        0        0B       0B         0
|-sda4        0        0B       0B         0
|-sda5        0        0B       0B         0
|-sda6        0        0B       0B         0
|-sda7        0        0B       0B         0
`-sda8        0        0B       0B         0
zram0         0        4K       2T         0
zram1         0        4K       2T         0
zram2         0        4K       2T         0
# lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 006: ID 10c4:8a2a
Bus 001 Device 002: ID 2109:3431
Bus 002 Device 002: ID 174c:1156
Bus 002 Device 001: ID 1d6b:0003
Bus 001 Device 004: ID 0403:6001

To enable trim you’ll need to use the editor vi (sorry that’s all there is).

  • Enter the command: vi /etc/udev/rules.d/50-usb-ssd-trim.rules
  • press i (to enter inserrt mode)
  • Type or copy and paste the following, updating your Vendor and Product IDs as needed:
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="1156", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"
  • Press ESC to exit insert mode
  • Type :wq then press enter (this will save and exit the editor)
  • Restart the operating system via the Home Assistant UI: Supervisor > System > Host > Restart Host
  • Once rebooted, reconnect to your Pi on port 22222
  • The lsblk command should now show non zero valudes for DISC-GRAN and DISC-MAX
  • You can now manually issue a trim command: fstrim -a -v
# lsblk --discard /dev/sda
NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda           0      512B       4G         0
|-sda1        0      512B       4G         0
|-sda2        0      512B       4G         0
|-sda3        0      512B       4G         0
|-sda4        0      512B       4G         0
|-sda5        0      512B       4G         0
|-sda6        0      512B       4G         0
|-sda7        0      512B       4G         0
`-sda8        0      512B       4G         0
# fstrim -a -v
/var: 30.9 MiB (32350208 bytes) trimmed on /dev/zram1
/tmp: 15.4 MiB (16162816 bytes) trimmed on /dev/zram2
/mnt/data: 215.8 GiB (231723094016 bytes) trimmed on /dev/sda8
/mnt/overlay: 87.3 MiB (91492352 bytes) trimmed on /dev/sda7
/mnt/boot: 24.9 MiB (26101760 bytes) trimmed on /dev/sda1
  • Now that it’s configured Home Assistant will perform trim opperations weekly without further intervention.

Reduce Writes

Using an SD Card or SSD it’s beneficial to reduce the number of writes occurring. One simple set of changes to consider is to configure Home Assistant to queue changes to write, this can be done using the commit_interval setting. Setting this to commit every 60 seconds, does mean that in the event of power loss up to 60 seconds worth of data could be lost.

You may also want to look at how many days of data you want to store here, I suspect it’s rare you need more than a few days. For longer-term trend data, I’d recommend you use InfluxDB and Grafana or similar, rather than trying to make Home Assistant try and do everything.

recorder:
  purge_keep_days: 3
  commit_interval: 60

Product Links

  • Raspberry Pi 4 (Amazon) (ThePiHut)
  • Argon ONE M.2 SSD case (Amazon) (ThePiHut)
  • Argon ONE M.2 expansion kit (Amazon) (ThePiHut)
  • USB 3.0 Type-A to Type-A cable (Amazon)
  • SanDisk Max Endurance Micro SD Card (Amazon)
  • Transcend 240GB 42mm M.2 SATA SSD (Amazon)
  • RFXCOM RFXtrx433E USB Transceiver (RFXCOM)
  • Nortek HUSBZB-1 USB Zigbee (and Z-Wave USA Frequencies only) (Amazon)
  • 90 Degree USB Adapter (UP) to mount Zigbee vertically (Amazon .COM, .UK)

Amazon links are affiliate links that help support the site, where possible I’ve used links that should take you to the product in the Amazon store in your region. Links to other suppliers are included for your convenience.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.