Home Assistant config editing with git workflow after using the "All in one installer"

#Home Assistant config editing with git workflow after using the “All in one installer” on your Raspberry Pi

This workflow allows you to edit your configs locally on say your OS X, Linux host, or even Windows (modify commands to account for windows centric commands) and simply push them to your raspberry pi via git. A “git hook” on the raspberry pi takes your config updates and automatically moves them to the “hass” config directory and corrects the permissions.

###Before starting:
Download a current copy of all configs you wish to use in this workflow.
Use Git, SCP, or any other tool you’re comfortable with to a directory but note this dir for later.

Setup Home Assistant config repo in git for “pi” user on remote raspberry pi:

cd /home/pi
mkdir hass_updates_pending && cd hass_updates_pending
mkdir hass_configs.git && cd hass_configs.git
git init --bare

Post Receive Hook Setup

cd hooks

Create the Git Hook

sudo nano post-receive

Paste the below script: (note theres 2 commands on one line each)

#!/bin/sh
sudo git --work-tree=/home/hass --git-dir=/home/pi/hass_updates_pending/hass_configs.git checkout -f
sudo chown hass:hass -R /home/hass

On your local host (not your remote raspberry pi), Setup local project repo for your Home Assistant configs This will be the “Working Directory”. Move your config files you previously downloaded to the new

cd /your/project/directory
mkdir hass_configs && cd hass_configs
git init

Move your config files you previously downloaded to the new “hass_configs”

add a remote called ‘live’:

git remote add live ssh://[email protected]/home/pi/hass_updates_pending/hass_configs.git

Edit config’s, add edited files to git for upload, comment your changes, and upload:

git add configuration.yaml
git commit -m "added component xyz"
git push --set-upstream live master

all future changes will only require:

git push live master

6 Likes

It works! Thanks for this cool hack.

I noticed a couple of minor issues when following along:

add a remote called 'live':
git remote add live ssh://[email protected]/home/pi/hass_updates_pending/hass_configs.git

Should be all one line - I am guessing the forum software made it into 2.

git comment -m "added component xyz"

Should be git commit

Otherwise perfect - thanks again!

Hey thanks for this tip. I’m having an issue though where the files aren’t actually checked out into the hass install once they’re pushed to my server. On my local computer (where I’m editing the files), I have no problems committing or pushing them to the Raspberry Pi. Except once they’re pushed, the updated files never wind up in my HASS directory. I’m not even sure where to look for error logs from a git hook script. Any advice?

EDIT: I figured it out. The post-receive script didn’t have execute permissions. chmod +x did the trick.

Nice, I just set this up, and it works great! One small thing that might be worth adding: The hook needs to be chmod’d to work: chmod 0755 post-receive after sudo nano post-receive

Just tried setting this up, and noticed one issue and can’t seem to get it to work.

First off, there needs to be a change to the post-receive file for use with the AiO script. sudo git --work-tree=/home/hass --git-dir=/home/pi/hass_updates_pending/hass_configs.git should be sudo git --work-tree=/home/hass/.homeassistant --git-dir=/home/pi/hass_updates_pending/hass_configs.git Otherwise this puts the files in the parent folder to where the config.yaml file resides, not updating the current ones.

So after making that change and doing the initial commit, the files appeared in the correct directory, no issue, but now they refuse to be updated. I changed the name in one of my friendly names in known_devices and ran git push live master. Git said everything is up-to-date, but running cat on the remote pi does not reflect the changes. Any help?

Yeah, this was written before I changed the installer to use the “dot” config directory. I used to simply use “/home/hass”. As to your issue, have you verified you marked the post-receive script executable?

I have, based off the comments here. Still won’t update.

Hi,
Has anyone managed to get this working. Have followed the steps above, including changing permissions for post-receive, Git successfully reports the push, but the files in my HASS/Config dont get updated.

I have managed to make this work. The hook I use is strangely:

#!/bin/sh
GIT_WORK_TREE=$HOME/projects/homeassistant git checkout -f

But now I have the problem, that my stuff gets overwritten when I use the UI to setup automations. Can this be?

OK. It’s definitely a problem when you try to modify the config other then with the yaml files on your remote machine. The UI changes will get overriden with a git checkout -f