Skip to content

Home Assistant

Is an Home automation platform, runs on Python

Setup

Proxmox

  • This scrip helps to set up a VM: bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/vm/haos-vm.sh)"

Raspberry Pi

  • Raspberry Pi 2 images are still present in GitHub releases

Ubuntu KVM

  1. Download the image here
  2. Decompress xz --decompress FILE
  3. Move somewhere like /var/lib/libvirt/images/hassos.qcow2
  4. Create the VM sudo virt-install --name hassos --graphics vnc,listen=0.0.0.0 --memory=2048 --vcpus=2 --disk=/var/lib/libvirt/images/hassos.qcow2,format=qcow2 --boot uefi --import --os-variant=debian9 --network=bridge=br0
  5. Login in http://homeassistant.local:8123

TrueNAS SCALE

Source 1. Download the image here 2. Unzip it 3. Convert the image using VirtualBox: VBoxManage clonehd source/hassos_vm.vdi destination/hassos_vm.img --format raw 4. Copy the image to TrueNAS 5. Create a zvol with β‰₯ 32 Gb 6. Create a VM - Navigate to Virtual Machines add Virtual Machine (VM) - Set Guest OS as Linux and Boot Method as UEFI - Add number of Virtual CPUs and Memory size accessible to the VM (this can be modified later) - Select Use existing disk image and select the Zvol created above - Modify Network Adapter if needed (ie. in order to easily locate the NIC when router leases its IP) - Don’t add installation image 7. Burn the image to the zvol: dd if=/mnt/pool_name/dataset_name/location_of_hassos_vm/hassos_vm.img of=/dev/zvol/pool_name/zvol_name

HTTPS Setup

  1. Install Let's Encrypt add-on and follow the documentation
  2. Go to Configuration > General and define External URL and Internal URL
  3. Configure configuration.yaml yaml http: ssl_certificate: /ssl/fullchain.pem ssl_key: /ssl/privkey.pem
  4. Restart the server

Migrate to another server

  1. Set up the new Home Assistant server
  2. In the old one, go to backups and do a full one
  3. In the new one, import before creating a user (OS) or copy backup in /config/

Enable reverse proxy like Cloudflared

Set up the HTTP Integration.

SMS Gateway via 3G/4G USB Modem Stick

  • Official SMS integration which uses Gammu
    • Device to use
      • Check ls /dev/*USB*
      • This post suggested to use /dev/serial/by-id/usb-Technology_Mobile_FFFFFFFFFFFFFFFF-if01-port0
      • If you use KVM, make sure to passthrough USB with EHCI controller
    • Send an SMS via the service:
    • Receive SMS via the Event sms.incoming_sms
      • ⚠️ Listening to the event make the integration to switch to Unavailable
  • I used Huawei E3272 that needed to be reflashed to work with

Configuration

Lovelace

  • Display an entity attribute:
type: entities
entities:
  - type: attribute
    entity: media_player.abc
    attribute: sound_mode

Mobile app

  • Reinstall the mobile app on a reset phone - source
    1. remove app from phone
    2. remove integration in HA via the UI
    3. redownload app and do onboarding
    4. after onboarding restart HA and keep your app alive (so screen on)

Integrations

Calendar from Nextcloud

  • Useful to silence notification: just use a calendar to set "Silence" days
  • Relevant integration page
  • Events must have a name
  • Configuration to show full days: ```yaml calendar:
    • platform: caldav username: nextcloud_username password: nextcloud_pass url: https://nextcloud.com custom_calendars:
      • name: "Name for HA" calendar: "Nextcloud Name" search: ".*" ```

Send SSH commands

Guide - Setup SSH keys for passwordless authentication - Store the keys - NOT in ~/.ssh/ as it's not shared across containers - In /config/.ssh/ so it get preserved across updates - Set the known host in /config/.ssh/ for the same reason than keys - Call the command with ssh HOST_CLIENT@HOST_IP -i /config/.ssh/HOST_privkey -o UserKnownHostsFile=/config/.ssh/HOST_known_hosts 'command' - -i to specify the private key (without .pub) - -o UserKnownHostsFile=/config/.ssh/HOST_known_hosts to approve the hos - If inexistent, it will be populated - This can be used in Command Line integration or Shell Command integration

Receive sensors data from other systems

  • Webhooks Template sensors can be set ```yml template:
    • trigger:
      • platform: webhook webhook_id: my-super-secret-webhook-id allowed_methods:
        • POST local_only: true sensor:
      • name: "Webhook Temperature" state: "{{ trigger.json.temperature }}" unit_of_measurement: Β°C ```
  • A device can do a POST

Automations

Notifications

  • Build Actionable notification
  • Get an attribute value with a space: use {{ states.sensor.abc.attributes["X Y Z"] }}
  • Use Developer Tools β†’ Services and Template to try out

Statistics

Clean the Statistics/Recorder database

Using the SSH add-on:

cd ~/config
sqlite3 home-assistant_v2.db
.header on
.mode column
.width 50, 10,
SELECT states_meta.entity_id as Entity, count(states.metadata_id) as Count FROM states INNER JOIN states_meta ON states.metadata_id = states_meta.metadata_id GROUP BY states.metadata_id ORDER BY count(states.metadata_id) DESC LIMIT 30;

Templates

"allows creating entities which derive their values from other data." - Templating documentation - Integration documentation

Monitor for broken automation

  • Names can changes when updating Home Assistant
  • The Watchman create reports to identify broken things

Energy

  • Several energy sources can be defined, each coupled with a cost
  • Fixed-cost can be defined as

Development

Verbose logging

Debugger

Documentation

Dev Setup