Home Assistant Configuration
Also see https://diy-smarthome.com/how-to-set-up-git-to-version-control-your-home-assistant-configuration/
To create the .gitignore execute the following
.gitignore file contents
# WARNING: Make your GitHub repo Private if you are using this as it is # Example .gitignore file for your config dir. # An * ensures that everything will be ignored. * # You can whitelist files/folders with !, these will not be ignored. !*.yaml !.gitignore !*.md !*.sh !*.js* # Comment these 2 lines if you don't want to include your SSH keys !.ssh/ !id_rsa* # Comment this if you don't want to include your Node-RED flows. # This is only valid if you install Node-RED as Home Assistant Add-on !node-red/ # Uncomment this if you don' want to include secrets.yaml # secrets.yaml # Ignore these files/folders .storage .cloud .google.token home-assistant.log
Git repository initialisation
Add all files to the repository
Commit changes with message “first commit”
Add git remote
AUTOMATED HOME ASSISTANT GITHUB BACKUP
Create a .ssh folder inside your HA config folder
Generate a private and public SSH keys
CHOOSE as path – .ssh/id_rsa
Get the content of this file
Paste content in GitHub SSH and GPG keys menu
Tell Git where to find the newly created SSH keys
When you do the first push you need to enter Yes to the Fingerprint Question.
To create the script execute the following
# Go to /config folder or # Change this to your Home Assistant config folder if it is different cd /config # Add all files to the repository with respect to .gitignore rules git add . # Commit changes with message with current date stamp git commit -m "config files on `date +'%d-%m-%Y %H:%M:%S'`" # Push changes towards GitHub git push -u origin master
Save file and the make it executable
Automation
Put this in automations.yaml - id: l1k3 alias: push HA configuration to GitHub repo trigger: # Everyday at 23:23:23 time - at: ’23:23:23’ platform: time action: - data: addon: a0d7b954_ssh input: /config/ha_gitpush.sh service: hassio.addon_stdin
Reset to HEAD / RESTORE # Going back to the commit before HEAD git reset --hard HEAD^ # Going back two commits before HEAD git reset --hard HEAD~2 # To undo a hard reset on Git git reset --hard HEAD@{1}