From 61034a47cc1e31f8d5c44ad5112c7a931af405b7 Mon Sep 17 00:00:00 2001 From: Ben Kristinsson Date: Wed, 26 Oct 2022 01:51:40 +0200 Subject: [PATCH 1/2] fix error in config file, add sensor for workdays --- roles/hass/templates/configuration.yaml.j2 | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/roles/hass/templates/configuration.yaml.j2 b/roles/hass/templates/configuration.yaml.j2 index 327c43e..c50bd80 100644 --- a/roles/hass/templates/configuration.yaml.j2 +++ b/roles/hass/templates/configuration.yaml.j2 @@ -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 -- 2.40.1 From 224f1aa4bfcb1cdd63ef85aab1a0a6b350342f5c Mon Sep 17 00:00:00 2001 From: Ben Kristinsson Date: Wed, 26 Oct 2022 01:52:01 +0200 Subject: [PATCH 2/2] sync hass config to git (only push so far) --- roles/hass/tasks/hass.yml | 71 +++++++++++++++++++++- roles/hass/templates/git-hass-config.sh.j2 | 42 +++++++++++++ roles/hass/templates/gitconfig.j2 | 9 +++ roles/hass/templates/hass-cron.j2 | 11 ++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 roles/hass/templates/git-hass-config.sh.j2 create mode 100644 roles/hass/templates/gitconfig.j2 create mode 100644 roles/hass/templates/hass-cron.j2 diff --git a/roles/hass/tasks/hass.yml b/roles/hass/tasks/hass.yml index 612aa64..a6ea193 100644 --- a/roles/hass/tasks/hass.yml +++ b/roles/hass/tasks/hass.yml @@ -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 - # only depends on requests, which hass image has + # 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 diff --git a/roles/hass/templates/git-hass-config.sh.j2 b/roles/hass/templates/git-hass-config.sh.j2 new file mode 100644 index 0000000..4090c66 --- /dev/null +++ b/roles/hass/templates/git-hass-config.sh.j2 @@ -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 diff --git a/roles/hass/templates/gitconfig.j2 b/roles/hass/templates/gitconfig.j2 new file mode 100644 index 0000000..6bc9871 --- /dev/null +++ b/roles/hass/templates/gitconfig.j2 @@ -0,0 +1,9 @@ +[user] +email = {{ systems_email }} +name = Home Assistant + +[init] +defaultBranch = main + +[push] +default = current diff --git a/roles/hass/templates/hass-cron.j2 b/roles/hass/templates/hass-cron.j2 new file mode 100644 index 0000000..2b08717 --- /dev/null +++ b/roles/hass/templates/hass-cron.j2 @@ -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 + + + + +# -- 2.40.1