From 4533a09a61c4cb61e55807d2231a7d2fbb175365 Mon Sep 17 00:00:00 2001 From: Christian Elberfeld <elberfeld@web.de> Date: Sun, 15 Jan 2023 00:41:47 +0100 Subject: [PATCH] Basiskonfiguration homeassistant --- functions | 2 +- intern/docker_homeassistant/tasks/main.yml | 42 ++++++++++++++ .../templates/config/automations.yaml | 0 .../templates/config/configuration.yaml | 55 +++++++++++++++++++ .../templates/config/scenes.yaml | 0 .../templates/config/scripts.yaml | 0 .../templates/docker-compose.yml | 46 ++++++++++++++++ site.yml | 7 +++ 8 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 intern/docker_homeassistant/tasks/main.yml create mode 100644 intern/docker_homeassistant/templates/config/automations.yaml create mode 100644 intern/docker_homeassistant/templates/config/configuration.yaml create mode 100644 intern/docker_homeassistant/templates/config/scenes.yaml create mode 100644 intern/docker_homeassistant/templates/config/scripts.yaml create mode 100644 intern/docker_homeassistant/templates/docker-compose.yml diff --git a/functions b/functions index 900377e4..e8a04941 160000 --- a/functions +++ b/functions @@ -1 +1 @@ -Subproject commit 900377e4f72486f6699ecf736f96adfbc04e92da +Subproject commit e8a049414bca2b14b158444dac1b94c2ca90d9be diff --git a/intern/docker_homeassistant/tasks/main.yml b/intern/docker_homeassistant/tasks/main.yml new file mode 100644 index 00000000..ec625b05 --- /dev/null +++ b/intern/docker_homeassistant/tasks/main.yml @@ -0,0 +1,42 @@ +--- + +- include: ../functions/get_secret.yml + with_items: + - { path: "{{ basedir }}/homeassistant_admin_password", length: 12 } + - { path: "{{ basedir }}/influxdb_password", length: 12 } + - { path: "{{ basedir }}/influxdb_token", length: 32 } + + +- name: "create folder struct for {{ basedir }}" + file: + path: "{{ item }}" + state: "directory" + with_items: + - "{{ basedir }}" + - "{{ basedir }}/config/" + + +- name: "copy config files for {{ basedir }}" + template: + src: "{{ item }}" + dest: "{{ basedir }}/{{ item }}" + with_items: + - docker-compose.yml + - config/automations.yaml + - config/configuration.yaml + - config/scenes.yaml + - config/scripts.yaml + register: config_files + + +- name: "stop {{ servicename }} docker" + docker_compose: + project_src: "{{ basedir }}" + state: absent + when: config_files.changed + + +- name: "start {{ servicename }} docker" + docker_compose: + project_src: "{{ basedir }}" + state: present diff --git a/intern/docker_homeassistant/templates/config/automations.yaml b/intern/docker_homeassistant/templates/config/automations.yaml new file mode 100644 index 00000000..e69de29b diff --git a/intern/docker_homeassistant/templates/config/configuration.yaml b/intern/docker_homeassistant/templates/config/configuration.yaml new file mode 100644 index 00000000..e30d8071 --- /dev/null +++ b/intern/docker_homeassistant/templates/config/configuration.yaml @@ -0,0 +1,55 @@ + +# Loads default set of integrations. Do not remove. +default_config: + +# includes +automation: !include automations.yaml +script: !include scripts.yaml +scene: !include scenes.yaml + +# Load frontend themes from the themes folder +frontend: + themes: !include_dir_merge_named themes + +# https://www.home-assistant.io/docs/configuration/basic/ +homeassistant: + name: "warpzone" + latitude: 51.944514 + longitude: 7.638933 + elevation: 70 + unit_system: metric + currency: EUR + country: DE + time_zone: Europe/Berlin + internal_url: https://{{ domain }} + auth_providers: + - type: trusted_networks + trusted_networks: + - 10.0.0.0/22 + allow_bypass_login: true + - type: homeassistant + +# https://www.home-assistant.io/integrations/http/ +http: + server_port: 8123 + ip_ban_enabled: False + login_attempts_threshold: 10 + use_x_forwarded_for: true + trusted_proxies: + - 172.0.0.0/8 + +# https://www.home-assistant.io/integrations/logger +# log_level= critical, fatal, error, warning, warn, info, debug, notset +logger: + default: info + +# https://www.home-assistant.io/integrations/influxdb/ +influxdb: + api_version: 2 + host: influxdb + port: 8086 + ssl: false + organization: homeassistant + bucket: homeassistant + token: {{ influxdb_token }} + default_measurement: units diff --git a/intern/docker_homeassistant/templates/config/scenes.yaml b/intern/docker_homeassistant/templates/config/scenes.yaml new file mode 100644 index 00000000..e69de29b diff --git a/intern/docker_homeassistant/templates/config/scripts.yaml b/intern/docker_homeassistant/templates/config/scripts.yaml new file mode 100644 index 00000000..e69de29b diff --git a/intern/docker_homeassistant/templates/docker-compose.yml b/intern/docker_homeassistant/templates/docker-compose.yml new file mode 100644 index 00000000..0f416227 --- /dev/null +++ b/intern/docker_homeassistant/templates/docker-compose.yml @@ -0,0 +1,46 @@ + +version: "3" + +services: + + app: + + image: homeassistant/home-assistant:2023.1 + restart: always + volumes: + - "/etc/localtime:/etc/localtime:ro" + - "{{ basedir }}/config:/config" + environment: + TZ: "Europe/Berlin" + labels: + - traefik.enable=true + - traefik.http.routers.{{ servicename }}.rule=Host(`{{ domain }}`) + - traefik.http.routers.{{ servicename }}.entrypoints=websecure + - traefik.http.services.{{ servicename }}.loadbalancer.server.port=8123 + networks: + - default + - web + + + influxdb: + + image: influxdb:2.6.0 + restart: always + ports: + - {{ int_ip4 }}:{{ influxdb_port }}:8086 + volumes: + - "{{ basedir }}/influxdb:/var/lib/influxdb2" + environment: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: homeassistant + DOCKER_INFLUXDB_INIT_PASSWORD: {{ influxdb_password }} + DOCKER_INFLUXDB_INIT_ORG: homeassistant + DOCKER_INFLUXDB_INIT_BUCKET: homeassistant + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: {{ influxdb_token }} + networks: + - default + + +networks: + web: + external: true diff --git a/site.yml b/site.yml index 2029d7ca..4ea42d1a 100644 --- a/site.yml +++ b/site.yml @@ -62,6 +62,13 @@ basedir: /srv/heimdall, domain: "services.warpzone.lan" } + - { + role: intern/docker_homeassistant, tags: homeassistant, + servicename: homeassistant, + basedir: /srv/homeassistant, + domain: "ha.warpzone.lan", + influxdb_port: 38086 + } - { role: intern/docker_mqtt, tags: mqtt, servicename: mqtt, -- GitLab