esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
417 stars 26 forks source link

Add GIT support via UI for configuration management #1239

Open XtremeOwnageDotCom opened 3 years ago

XtremeOwnageDotCom commented 3 years ago

Describe the problem you have/What new integration you would like The ability to specify a upstream git repository for managing configuration versioning.

Please describe your use case for this integration and alternatives you've tried: Currently, the workaround is to manually initialize a git repository in the esphome data directory, and to either manually trigger a git add/git push after updates are performed, or to setup a cron job to invoke a script to check in changes to a git repository.

Ideally- this proposed feature, would enable some basic git integration, to automatically push changes to a upstream git repository. As a future goal, the ability to see previous version directly via the esphome UI would be nice too.

Additional context

gregmac commented 2 years ago

I'm a bit surprised more people aren't asking for this. This lets you freely make experimental changes to a working setup, and then "go back" to an earlier version in case it doesn't work out.

A viable MVP for this feature could be:

This would allow viewing history on the remote repository and at least getting an earlier verison.

Nice to have or future features (in no particular order):

  1. Allow specifying the commit message
  2. Commit manually instead of at every save
  3. Pull changes as long as there are no conflicts
  4. When a firmware is installed, tag it with the install datetime
  5. View log and revert to older versions
  6. Individual repositories for each device
  7. Allow adding a device by cloning a remote repository
nagyrobi commented 2 years ago

Think off the fact that the concept is to use the entire system offline, most people use the Dashboard as Home Assistant add-on...

ramonsmits commented 2 years ago

Just had the same thought. Would be nice if edits would be auto committed so they can easily be restored but I just discoved that these files are just written to the file system 1-1. I'm committing my docker folders to git as an alternative.

I personally only need a little version control. Would be nice though if esphome would git commit when clicking save.

lacrimal commented 1 month ago

agree but ... not agree :-) adding whole mechanism to mimic git behavior in ui looks like overkill. Maybe (I'm saying maybe) it can be done like in node-red, when changes are simply auto-committed but there is no ui way to restore them ? So you have your git but not git ui :-)

XtremeOwnageDotCom commented 1 month ago

Will note, the scope of my request is simple- just the ability to specify a git repo- to where changes can be tracked/pushed.

Not- even anything fancy- the ability to see commits/rollback- that- is a stretch goal. All baby steps here.

But- anyways, this ticket gets buried with the others, and doesn't get enough attention/votes/etc... So, will prob sit here for a few more years.

lacrimal commented 3 weeks ago

Maybe this:

sh script inside config directory auto_git_push.sh

#!/bin/bash

shopt -u extglob
# Directory containing your ESPHome yaml files
WATCH_DIR="/home/me/esphome/config"
SSH_KEY_PATH="/home/me/esphome/config/id_ed25519"
BRANCH="master"  # Change if needed

# Store the GIT_SSH_COMMAND for reuse
GIT_CMD="GIT_SSH_COMMAND='ssh -i $SSH_KEY_PATH' git -C $WATCH_DIR"

# Watch for changes in .yaml files
inotifywait -m -e modify,create,delete,move --format '%w%f' --exclude '(\.git|\.esphome|trash|secrets\.yaml|id_ed25519|id_ed25519\.pub|auto_notify_push\.sh)' "$WATCH_DIR" |
while read -r FILE
do
  if [[ "$FILE" == *.@(yaml|csv) ]]; then
    # Add the modified file
    eval "$GIT_CMD add \"$FILE\""

    # Get the number of lines changed for this file
    LINES_CHANGED=$(eval "$SSH_CMD $GIT_CMD diff --cached --stat \"$FILE\" | awk '{print \$1}'")

    # Personalized commit message
    COMMIT_MSG="Updated $LINES_CHANGED lines in $(basename "$FILE")"

    # Commit and push changes
    eval "$GIT_CMD commit -m \"$COMMIT_MSG\"" && \
    eval "$GIT_CMD push origin \"$BRANCH\""
  fi
done

service esphome-auto-git-push.service

[Unit]
Description=Automatic Git Add, Commit, and Push for YAML files in ESPHome Directory
After=network.target

[Service]
ExecStart=/home/me/esphome/config/auto_git_push.sh
WorkingDirectory=/home/me/esphome/config
Restart=always
User=root
[Install]
WantedBy=multi-user.target

.gitignore

# Gitignore settings for ESPHome
# This is an example and may include too much for your use-case.
# You can modify this file to suit your needs.
/.esphome/
/.git/
/secrets.yaml
/trash/
id_ed25519
id_ed25519.pub

you need to:

So anytime when you make save in esphome it will automatically add, commit to local repo and push to remote. As you see - only yaml and csv extension go automatically, rest you can do manually if you like.

That make automate half of your concern, all other you need to do manually :-)

XtremeOwnageDotCom commented 3 weeks ago

That make automate half of your concern, all other you need to do manually :-)

Oh, I already have that part scripted/automated. But- the basic functionality, would be quite handy for the product itself.

Pretty simple one too.