Show the commit of the config HA is currently running on

As my HA config is constantly evolving I sometimes am not sure on which version of my config HA is currently running on. Sometimes I forget to pull the latest version from my git repo to my server and wonder why something is not showing up in the frontend.

I am now showing a sensor on my Home View with the Current commit:

On my server I am using this script which pulls the latest version from Git, writes the commit info to a text file and restarts my Docker Container.

A command_line sensor and template sensor show the content of the file in the frontend:
current_commit
sensor.yaml

- platform: command_line
  name: current_commit
  command: cat /config/currentCommit.txt
- platform: template
  sensors:
    current_commit_id:
      friendly_name: Id
      value_template: "{{states.sensor.current_commit.state.split(' ',1)[0]}}"
    current_commit_name:
      friendly_name: Message
      value_template: "{{states.sensor.current_commit.state.split(' ',1)[1]}}"

group.yaml:

default_view:
  view: yes
  icon: mdi:home
  entities:
    - group.current_commit
current_commit:
  name: Basiert auf Commit
  entities:
    - sensor.current_commit_id
    - sensor.current_commit_name
2 Likes

I liked this idea, but since I was running in a virtual environment rather than docker, I could use the git log directly without an intermediate file

  - platform: command_line
    name: current_commit
    command: "cd /home/homeassistant/.homeassistant;git log -1 --oneline | cut -d' ' -f1"

I’m running HASS on docker, and been thinking about how to setup GIT, so it would work as it is meant to.

Are you running GIT from a docker, or on your host?

Can you help with a short walk trough?

I use @silvrr’s implimentation

 #https://home-assistant.io/components/sensor.command_line/
  -  platform: command_line
     command: python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"
     name: Current HA Version

  -  platform: command_line
     name: Installed version
     command: "head -5 /home/user/.homeassistant/.HA_VERSION"

This shows the current version of HA itself. So for example 0.73.2

What my implementation is showing is the version of my own configuration which i store on github.

1 Like

Sure thing. Here is the “official” documentation which I followed:

I skipped Step 6 because I am developing on my laptop and push my changes to Github from there.

Thanks ! Don’t know why I never found that one.

Just to be right, you setup git on your host OS, and not in a docker container . But how do you then execute git from HASS, or do you SSH in to your host every time?

I ssh into my system.