Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95295

How to switch to MacOS

$
0
0

@fmon wrote:

How to switch over to MacOS

Like many of us here, I started as a newb and had to learn how to SSH into a Raspberry Pi, write basic YAML and effectively use the command line. As soon as I thought I had it all under control, I decided to switch over to a Mac Mini; unfortunately, however, this task isn’t as easy as copying over one’s HA config files, and there’s no real guide that I could find. It took a lot of messing around to figure it out, so I thought I might put a little PSA out for anyone else embarking on this process without the full knowledge of how to do so. Before I even start, I’m barely more than a noob, so take what you see with a grain of salt.

First off, why switch? Briefly my mini ( I was feeling spendy, so it’s the new model) offers:

  • speed: HA graphs render instantly; restarts take ~12 seconds instead of minutes; etc.
  • functions as a NAS and media server. USB 3.0 ports = cheap, fast storage.
  • Spotify to homepods. Airfoil.
  • Time Machine backups = no need for rsync and no worrying about SD card fails
  • HDMI out to nearby TV + wireless keyboard/trackpad (or VNC) = biggest monitor in the house

Now, things to know before you start:

  • Starting with El Capitan, and progressing with each new OS, Apple introduced some new security components with which you shall tangle. First off, “Full Disk Access” is a feature that requires you to give permission to apps- including Terminal and any emulators you may be using (Termius in my case)- permission to work with the entire disk. Go to System prefs -> security & privacy -> privacy, then select full disk access and add what you need. Also you may like to read about SIP (System Integrity Protection), which limits access to certain system folders. This gets even more restrictive in Catalina (see below).
  • Decide on your setup: I chose to run in a VENV because that’s how I did it on my Pi, and you can follow the standard HA installation documentation (although the autostart script to which it links didn’t work for me):
    https://www.home-assistant.io/docs/installation/macos/
    I don’t know if there’s a way to run Hassio on a MacOS volume… maybe with Docker or something.
  • Package installer: there is no apt-get on MacOS; the best alternative is Homebrew. You can read about this elsewhere, but installing an updated version of Python in your VENV is easy with Homebrew.
  • Restarting a headless Mac: at first this was really frustrating, as I was trying to run a headless mini via SSH like we do with the RPi’s, but because of full disk encryption, it turns out that issuing a restart on a mac brings you to a login screen at a point in the boot where VNC and/or the built-in screen sharing modality in Mojave or Catalina isn’t active yet. Which means that you need a physical keyboard and monitor to log in, which means that you’re not headless any more. Well it turns out that there’s a command you can issue that will take you straight to the user login screen at which point VNC will have started, and you can login in that way. The command:
    sudo fdesetup authrestart
    Also, I discovered that it IS possible to write a bash script using this command so that you have a button to restart your Mac in HA. Slick.

Now comes what was I think the most frustrating issue that I faced: who is HA running as, and where are the config files??? Well it turns out that on a mac this all has to do with how you START HA. I shall explain.

  • Let’s start by reviewing the fact that HA should not run as root. However, we sudo the systemctl command to start HA on a pi as detailed here:
    https://www.home-assistant.io/docs/installation/hassbian/common-tasks/
    However, if you sudo your start command on a mac, by using sudo you have specified that root owns the process. As a result, HA not only runs as root but also looks here for the config files:
    /var/root/.homeassistant
    … but var is a symlink, so the actual path is:
    /private/var/root/.homeassistant
    Confused yet? I sure was. My solution to this was NOT to create a new user just for HA which would always be logged in but rather just to use the default user which, given that it has admin privileges may not be as secure as a limited user, but it’s better than root. Also, the config files wind up in a non-perplexing location at:
    /Users/yourusername/.homeassistant
  • So, how to start HA as your user? Well, ideally you want HA to start at boot, so you can use crontab, but I elected to educate myself on launchd, which is MacOS’s updated version of crontab. This involves creating a .plist file that you put in your ~/Library/LaunchAgents folder (which by virtue of its location will start as the user). Good advice here:
    https://alvinalexander.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs
  • In that article he uses launchctl load/unload for start/stop, but FYI there’s even newer syntax using boostrap/bootout and even kickstart (to stop and then restart). This looks like:
    launchctl bootstrap gui/<user PID> /Users/yourusername/Library/Launchagents/org.homeassistant.plist
  • Activating your VENV looks familiar if you created it in your user folder:
    source /Users/yourusername/homeasistant/bin/activate

Dependencies

  • I had remarkably few issues here. Just remember that if you’re looking for something you would normally need apt-get for, there’s probably an analogous package in Homebrew. For example, I was looking for libssl for an updated Apple TV integration and realized that openssl was already installed and filled the bill.
  • Also remember to re-install anything that you had to install separately on your pi (like iStats in my instance).

Catalina-specific issues

  • / isn’t what it used to be, which broke a few things (like system monitor’s disk percent usage). The system now exists on a protected volume, and the path to what the user can access is:
    /system/volumes/data
  • 32 bit support is gone. Find updated versions of those old programs.
  • The default shell is now zh instead of bash, but if you upgrade an existing Mojave system your default shell doesn’t change unless you tell it to. Terminal gives you a blurb about it.

What I’m into lately

I sure hope this saves someone some time, because I wasted a lot figuring it out. Big brains please correct my errors!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95295

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>