hass-config #32

Merged
ben merged 2 commits from hass-config into main 2022-10-25 23:53:37 +00:00
5 changed files with 156 additions and 7 deletions

View File

@ -48,6 +48,20 @@
tags:
- ufw
- name: copy ssh keys for {{ hass_config_repo_name }}
template:
src: "private/sshkeys/{{ item }}"
dest: "{{ systemuserlist.hass.home }}/.ssh/{{ item }}"
owner: "{{ systemuserlist.hass.uid }}"
group: "{{ systemuserlist.hass.gid }}"
mode: 0600
no_log: true
with_items:
- "{{ hass_config_repo_name }}"
- "{{ hass_config_repo_name }}.pub"
tags:
- hass-git
# hass + zwave
- name: create dir structure
@ -57,6 +71,8 @@
mode: 0755
owner: hass
group: hass
tags:
- hass-dirs
with_items:
- home-assistant
- home-assistant/config
@ -65,6 +81,32 @@
- zwavejs
- zwavejs/app
- zwavejs/app/store
- git
- name: template gitconfig
template:
src: gitconfig.j2
dest: "{{ systemuserlist.hass.home }}/.gitconfig"
owner: "{{ systemuserlist.hass.uid }}"
group: "{{ systemuserlist.hass.gid }}"
mode: 0644
tags:
- hass-git
- name: set up the {{ hass_config_repo_name }} repo
git:
repo: "{{ hass_config_repo }}"
dest: "{{ systemuserlist.hass.home }}/git/{{ hass_config_repo_name }}"
version: main
clone: true
update: false
force: false
accept_newhostkey: true
key_file: "{{ systemuserlist.hass.home }}/.ssh/{{ hass_config_repo_name }}"
become_user: "{{ systemuserlist.hass.username }}"
tags:
- hass-git
- hass-git-clone
- name: home assistant main configuration.yaml
template:
@ -88,6 +130,28 @@
tags:
- hass-config
- name: install git sync script
template:
src: git-hass-config.sh.j2
dest: /usr/local/bin/git-hass-config.sh
mode: 0775
owner: hass
group: hass
tags:
- hass-git
- name: cron file
template:
src: hass-cron.j2
dest: /etc/cron.d/hass
owner: root
group: root
mode: 0640
tags:
- cron
- hass-cron
- hass-git
# docker run --run -it -p 8091:8091 -p 3000:3000 --network
#bridgewithdns --device /dev/ttyACM0:/dev/zwave -v
# /home/ben/zwavejs:/usr/src/app/store zwavejs/zwavejs2mqtt:latest
@ -160,11 +224,14 @@
- type: bind
source: "{{ systemuserlist.hass.home }}/home-assistant/media"
target: /usr/var/media
# from role: common
# scripts from role: common
# only depends on requests, which hass image has
- type: bind
source: /usr/local/bin/authelia-auth.py
target: /usr/local/bin/authelia-auth.py
- type: bind
source: /usr/local/bin/matrixmsg.py
target: /usr/local/bin/matrixmsg.py
tags:
- home-assistant
- home-assistant-container

View File

@ -1,4 +1,5 @@
# ansible: roles/hass/templates/configuration.yaml.j2
#
# Loads default set of integrations. Icluding the cloud crap. Do remove.
# havent gotten it to work wthough, hass doesnt load properly
default_config:
@ -58,12 +59,27 @@ default_config:
# Text to speech
tts:
- platform: voicerss
api_key: !secret voicerss_api_key
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
{# calendar:
# {% for item in hass_caldav.urls %}
#
# - platform: caldav
# days: 30
# username: !secret caldav_user
# password: !secret caldav_passwd
# # {{ item.name }}
# url: {{ item.url }}
#
# {% endfor %}
#}
calendar:
- platform: caldav
days: 30
@ -127,7 +143,11 @@ sensor:
# Stadt Berlin
region_name: 811000000
tts:
- platform: voicerss
api_key: !secret voicerss_api_key
- platform: google_translate
binary_sensor:
- platform: workday
country: DE
workdays: [mon, tue, wed, thu, fri]
excludes: [sat, sun, holiday]
shell_command:
matrixmsg: /usr/local/bin/matrixmsg.py

View File

@ -0,0 +1,42 @@
#!/bin/bash
set -e
NAME_REPO="{{ hass_config_repo_name }}"
PATH_REPO="{{ systemuserlist.hass.home }}/git/${NAME_REPO}"
PATH_HASS="{{ systemuserlist.hass.home }}/home-assistant"
export GIT_SSH_COMMAND="ssh -i ~/.ssh/${NAME_REPO}"
cd $PATH_REPO
if test -n "$(git status --porcelain)" ; then
echo "repo is dirty"
git status --short
exit 2
fi
if ! grep -q "secrets.y[a]ml" ${PATH_REPO}/.gitignore; then
echo "'secrets.yaml' missing from '.gitconfig'"
exit 3
fi
mkdir -p ${PATH_REPO}/config/
{% for item in hass_config_repo_files -%}
cp ${PATH_HASS}/config/{{ item }} ${PATH_REPO}/config/{{ item }}
{% endfor %}
if test -n "$(git status --porcelain)" ; then
{% for item in hass_config_repo_files -%}
git add config/{{ item }} > /dev/null
{% endfor %}
git commit -m "config updated" > /dev/null
fi
git pull --quiet
git push --quiet 2> /dev/null
# TODO: copy changes from git

View File

@ -0,0 +1,9 @@
[user]
email = {{ systems_email }}
name = Home Assistant
[init]
defaultBranch = main
[push]
default = current

View File

@ -0,0 +1,11 @@
# distributed from ansible
# m h dom mon dow
# sync hass config to {{ hass_config_repo }}
*/15 * * * * {{ systemuserlist.hass.username }} /usr/local/bin/git-hass-config.sh
#