1
0
mirror of https://github.com/funkypenguin/geek-cookbook/ synced 2025-12-13 01:36:23 +00:00
Files
geek-cookbook/docs/recipes/homeassistant.md
David Young abf9309cb1 Experiment with PDF generation
Signed-off-by: David Young <davidy@funkypenguin.co.nz>
2022-08-19 16:40:53 +12:00

4.3 KiB

description
description
Assist your home automation

Home Assistant

Home Assistant is a home automation platform written in Python, with extensive support for 3rd-party home-automation platforms including Xaomi, Phillips Hue, and a bazillion others.

Home Assistant Screenshot{ loading=lazy }

This recipie combines the extensibility of Home Assistant with the flexibility of InfluxDB (for time series data store) and Grafana (for beautiful visualisation of that data).

--8<-- "recipe-standard-ingredients.md"

Preparation

Setup data locations

We'll need several directories to bind-mount into our container, so create them in /var/data/homeassistant:

mkdir /var/data/homeassistant
cd /var/data/homeassistant
mkdir -p {homeassistant,grafana,influxdb-backup}

Now create a directory for the influxdb realtime data:

mkdir /var/data/runtime/homeassistant/influxdb

Prepare environment

Create /var/data/config/homeassistant/grafana.env, and populate with the following - this is to enable grafana to work with oauth2_proxy without requiring an additional level of authentication:

GF_AUTH_BASIC_ENABLED=false

Setup Docker Swarm

Create a docker swarm config file in docker-compose syntax (v3), something like this:

--8<-- "premix-cta.md"

version: "3"

services:
    influxdb:
      image: influxdb
      networks:
        - internal
      volumes:
        - /var/data/runtime/homeassistant/influxdb:/var/lib/influxdb
        - /etc/localtime:/etc/localtime:ro

    homeassistant:
      image: homeassistant/home-assistant
      dns_search: hq.example.com
      volumes:
        - /var/data/homeassistant/homeassistant:/config
        - /etc/localtime:/etc/localtime:ro
      deploy:
        labels:
          # traefik common
          - traefik.enable=true
          - traefik.docker.network=traefik_public

          # traefikv1
          - traefik.frontend.rule=Host:homeassistant.example.com
          - traefik.port=8123     

          # traefikv2
          - "traefik.http.routers.homeassistant.rule=Host(`homeassistant.example.com`)"
          - "traefik.http.services.homeassistant.loadbalancer.server.port=8123"
          - "traefik.enable=true"
      networks:
        - traefik_public
        - internal
      ports:
        - 8123:8123

    grafana-app:
      image: grafana/grafana
      env_file : /var/data/config/homeassistant/grafana.env
      volumes:
        - /var/data/homeassistant/grafana:/var/lib/grafana
        - /etc/localtime:/etc/localtime:ro
      networks:
        - internal
        - traefik_public
      deploy:
        labels:
          # traefik common
          - traefik.enable=true
          - traefik.docker.network=traefik_public

          # traefikv1
          - traefik.frontend.rule=Host:grafana.example.com
          - traefik.port=3000     

          # traefikv2
          - "traefik.http.routers.grafana.rule=Host(`grafana.example.com`)"
          - "traefik.http.services.grafana.loadbalancer.server.port=3000"
          - "traefik.enable=true"

          # Remove if you wish to access the URL directly
          - "traefik.http.routers.grafana.middlewares=forward-auth@file"

networks:
  traefik_public:
    external: true
  internal:
    driver: overlay
    ipam:
      config:
        - subnet: 172.16.13.0/24

--8<-- "reference-networks.md"

Serving

Launch Home Assistant stack

Launch the Home Assistant stack by running docker stack deploy homeassistant -c <path -to-docker-compose.yml>

Log into your new instance at https://YOUR-FQDN, the password you created in configuration.yml as "frontend - api_key". Then setup a bunch of sensors, and log into https://grafana.YOUR FQDN and create some beautiful graphs :)

--8<-- "recipe-footer.md"