Techne: A practical knowledge base

Table of Contents generated with DocToc

Home Assistant

DietPi installation

Dawarich

docker-compose.yml:

networks:
  dawarich:
services:
  dawarich_redis:
    image: redis:7.0-alpine
    container_name: dawarich_redis
    command: redis-server
    networks:
      - dawarich
    volumes:
      - dawarich_shared:/data
    restart: always
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 10s
      retries: 5
      start_period: 30s
      timeout: 10s
  dawarich_db:
    image: imresamu/postgis:17-3.5-alpine
    shm_size: 1G
    container_name: dawarich_db
    volumes:
      - dawarich_db_data:/var/lib/postgresql/data
      - dawarich_shared:/var/shared
      # - ./postgresql.conf:/etc/postgresql/postgresql.conf # Optional, uncomment if you want to use a custom config
    networks:
      - dawarich
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: dawarich_development
    restart: always
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres -d dawarich_development" ]
      interval: 10s
      retries: 5
      start_period: 30s
      timeout: 10s
    # command: postgres -c config_file=/etc/postgresql/postgresql.conf # Use custom config, uncomment if you want to use a custom config
  dawarich_app:
    image: freikin/dawarich:latest
    container_name: dawarich_app
    volumes:
      - dawarich_public:/var/app/public
      - dawarich_watched:/var/app/tmp/imports/watched
      - dawarich_storage:/var/app/storage
    networks:
      - dawarich
    ports:
      - 3000:3000
      - 9394:9394 # Prometheus exporter, uncomment if needed
    stdin_open: true
    tty: true
    entrypoint: web-entrypoint.sh
    command: ['bin/dev', 'server', '-p', '3000', '-b', '::']
    restart: on-failure
    environment:
      RAILS_ENV: development
      REDIS_URL: redis://dawarich_redis:6379/0
      DATABASE_HOST: dawarich_db
      DATABASE_USERNAME: postgres
      DATABASE_PASSWORD: password
      DATABASE_NAME: dawarich_development
      MIN_MINUTES_SPENT_IN_CITY: 60
      APPLICATION_HOSTS: localhost
      TIME_ZONE: America/Chicago
      APPLICATION_PROTOCOL: http
      PROMETHEUS_EXPORTER_ENABLED: "true"
      PROMETHEUS_EXPORTER_HOST: 0.0.0.0
      PROMETHEUS_EXPORTER_PORT: 9394
      SELF_HOSTED: "true"
      STORE_GEODATA: "true"
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "5"
    healthcheck:
      test: [ "CMD-SHELL", "wget -qO - http://127.0.0.1:3000/api/v1/health | grep -q '\"status\"\\s*:\\s*\"ok\"'" ]
      interval: 10s
      retries: 30
      start_period: 30s
      timeout: 10s
    depends_on:
      dawarich_db:
        condition: service_healthy
      dawarich_redis:
        condition: service_healthy
    deploy:
      resources:
        limits:
          cpus: '0.50'    # Limit CPU usage to 50% of one core
          memory: '4G'    # Limit memory usage to 4GB
  dawarich_sidekiq:
    image: freikin/dawarich:latest
    container_name: dawarich_sidekiq
    volumes:
      - dawarich_public:/var/app/public
      - dawarich_watched:/var/app/tmp/imports/watched
      - dawarich_storage:/var/app/storage
    networks:
      - dawarich
    stdin_open: true
    tty: true
    entrypoint: sidekiq-entrypoint.sh
    command: ['sidekiq']
    restart: on-failure
    environment:
      RAILS_ENV: development
      REDIS_URL: redis://dawarich_redis:6379/0
      DATABASE_HOST: dawarich_db
      DATABASE_USERNAME: postgres
      DATABASE_PASSWORD: password
      DATABASE_NAME: dawarich_development
      APPLICATION_HOSTS: localhost
      BACKGROUND_PROCESSING_CONCURRENCY: 10
      APPLICATION_PROTOCOL: http
      PROMETHEUS_EXPORTER_ENABLED: "true"
      PROMETHEUS_EXPORTER_HOST: dawarich_app
      PROMETHEUS_EXPORTER_PORT: 9394
      SELF_HOSTED: "true"
      STORE_GEODATA: "true"
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "5"
    healthcheck:
      test: [ "CMD-SHELL", "bundle exec sidekiqmon processes | grep $${HOSTNAME}" ]
      interval: 10s
      retries: 30
      start_period: 30s
      timeout: 10s
    depends_on:
      dawarich_db:
        condition: service_healthy
      dawarich_redis:
        condition: service_healthy
      dawarich_app:
        condition: service_healthy
    deploy:
      resources:
        limits:
          cpus: '0.50'    # Limit CPU usage to 50% of one core
          memory: '4G'    # Limit memory usage to 4GB

volumes:
  dawarich_db_data:
  dawarich_shared:
  dawarich_public:
  dawarich_watched:
  dawarich_storage:

Edit /mnt/dietpi_userdata/homeassistant/configuration.yaml to add Dawarich configuration:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# dawarich
rest_command:
    push_position_to_dawarich:
      url: http://localhost:3000/api/v1/overland/batches?api_key=<APIKEY>
      method: POST
      content_type: 'application/json'
      payload: >
        {
          "locations": [
          {
           "type": "Feature",
           "geometry":{
             "type": "Point",
             "coordinates":[
               {{ longitude }},
               {{ latitude }}
              ]
           },
           "properties":{
              "api_key": "<APIKEY>",
              "timestamp": "{{ now().isoformat() }}",
              "altitude": {{ altitude }},
              "speed": {{ speed }},
              "horizontal_accuracy": 0,
              "vertical_accuracy": {{ vertical_accuracy }},
              "motion": [],
              "pauses": false,
              "activity": "{{ activity }}",
              "desired_accuracy": 0,
              "deferred": 0,
              "significant_change": "unknown",
              "locations_in_payload": 1,
              "device_id": "{{device_id}}",
              "wifi": "unknown",
              "battery_state": "unknown",
              "battery_level": {{ battery_level }}
           }
          }
          ]
        }        

alias: Push pixel6 position to dawarich
description: ""
trigger:
  - platform: state
    entity_id:
      - device_tracker.pixel_6
    attribute: longitude
  - platform: state
    entity_id:
      - device_tracker.pixel_6
    attribute: latitude
condition: []
action:
  - service: rest_command.push_position_to_dawarich
    data:
      latitude: "{{ state_attr('device_tracker.pixel_6','latitude') }}"
      longitude: "{{ state_attr('device_tracker.pixel_6','longitude') }}"
      speed: "{{ state_attr('device_tracker.pixel_6','speed') }}"
      altitude: "{{ state_attr('device_tracker.pixel_6','altitude') }}"
      vertical_accuracy: "{{ state_attr('device_tracker.pixel_6','vertical_accuracy') }}"
      activity: "{{ states('sensor.pixel_6_detected_activity') }}"
      device_id: pixel7
      battery_level: "{{ states('sensor.pixel_6_battery_level') }}"
mode: single

PicoTTS

On DietPi, install dependencies.

sudo apt install -y libtool build-essential automake autoconf libpopt-dev pkg-config
git clone https://github.com/ihuguet/picotts
cd picotts/pico
./autogen.sh
./configure
make
sudo make install

Test.

pico2wave -l en-US -w test.wav "Hello. How may I assist?"

Copy the test.wav file to desktop machine. Play the file in a media player.

Configure PicoTTS in /mnt/dietpi_userdata/homeassistant/configuration.yaml:

tts:
  - platform: picotts
    language: "en-US"

Reply to this post by email ↪