Simple Shell Script to Manage HA

People may or may not find this useful, but I put together a shell script that I use to manage my Home Assistant from any of my Macs (or any POSIX OS with BASH).

I built it for my personal use, but essentially you would just need to set the Variables to your settings and setup shared SSH keys (if desired).

Workflow:

  • All HA configs are stored locally within Dropbox (doesn’t have to be but I like the versioning and access to it from any machine).
  • Edit locally with Text Editor (Currently using Atom).
  • When I select the deploy HA configs option it creates a tar file of the current configs and moves it to my local machine in a backup folder (in Dropbox). That way I always have a backup before it pushes out any changes.
  • Syncs updated files
  • Verifies config

Variables:

hauser=“USER_ACCOUNT” <-- Home Assistant User Account
habin="/usr/local/bin/hass" <-- Home Assistant Binary
haconfigdir="/home/USER/.homeassistant" <-- Home Assistant Config Directory
hahost=“HOSTNAME/IP” <-- Home Assistant Hostname or IP address
localuser=“USER_ACCOUNT” <-- Local Computer Username, account from where this shell script will run
localhost=“HOSTNAME/IP” <-- Local Computer Hostname or IP address
localpath=“PATH_TO_LOCAL_HA_CONFIGS” <-- Where I store my local HA configs and backups

Within the local folder, variable localpath="PATH_TO_LOCAL_HA_CONFIGS", I have two folders:

Config: All of the .yaml files for Home Assistant
Backup: Place for backup tar files

It has a few other options that will stop, start, restart, etc. These assume that you are using systemd, but could be modified as needed.

Nothing fancy but it does the job.

4 Likes

Nice work and nice of you to share it. Thanks!

Best line of your script :grinning:.

echo "Invalid Option Stupid"

Thanks for sharing! :+1:

3 Likes