Home automations with Home Assistant (HA)

I'm running Home Assistant from docker-compose (image homeassistant/home-assistant) on a Raspberry Pi 3 (Model B+) with an attached 5" HDMI touchscreen running a simple kivy Python app.

Other hardware components:


This is my docker-compose.yml:

version: '3.4'
services:
  homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:latest
    volumes:
      - /home/pi/ha/config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/udev:/run/udev:ro
      - /home/pi/ha/scripts:/scripts
    restart: unless-stopped
    network_mode: host
    devices:
      - /dev/ttyACM0
    command: sh -c "python3 /scripts/carheating-runner.py& exec python3 -m homeassistant --config /config"
  slimserver:
    container_name: logitech-media-server
    image: toertel/logitech-media-server:latest
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /home/pi/ha/slimserver:/srv/squeezebox
      - /home/pi/ha/slimserver-music:/srv/music
    ports:
      - "9000:9000/tcp"
      - "9090:9090/tcp"
      - "3483:3483/tcp"
      - "3483:3483/udp"
    expose:
      - "9000/tcp"
      - "9090/tcp"
      - "3483/tcp"
      - "3483/udp"
    restart: unless-stopped
  mqtt:
    container_name: mqtt
    image: eclipse-mosquitto:latest
    network_mode: host
    environment:
      - MOSQUITTO_USERNAME=this_is_secret
      - MOSQUITTO_PASSWORD=this_is_secret
      - TZ=Europe/Stockholm
    volumes:
      - /home/pi/ha/mosquitto/config:/mosquitto/config
      - /home/pi/ha/mosquitto/log:/mosquitto/log
      - /home/pi/ha/mosquitto/data:/mosquitto/data
    restart: unless-stopped
    depends_on:
      - homeassistant
Everything is quite standard, except a script that is started in the HA container, carheating-runner.py (using linknx.py). We have two outdoor switches (left and right) for controlling the car pre-heaters. In HA you can enter the time you want the car to be ready and depending on the outside temperature, the car pre-heater starts max(0,60-temperature*3) minutes before that time (temperature in °C). When the time or activation changes, another script carheating-updater.py is called from HA. It is possible to implement the automation for this in HA, but it's messy, so I just made a few Python scripts instead.

Here is my HA configuration.yaml:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

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

shell_command:
  update_car_heating: python /scripts/carheating-updater.py {{ states("input_datetime.motorvarmare_vanster_tid") }} {{ states("input_boolean.motorvarmare_vanster_aktivera") }} {{ states("input_datetime.motorvarmare_hoger_tid") }} {{ states("input_boolean.motorvarmare_hoger_aktivera") }}

linknx:
    host: "linknx.host.ip.number"
    port: 1028

light:
  - platform: linknx
    entities:
      - { id: light_kitchen, dim: light_kitchen_dim, name: "Belysning kök" }
#     ... and many more    
switch:
  - platform: linknx
    entities:
      - { id: plug_library, name: "Uttag bibliotek" }
#     ... and some more

  - platform: mqtt
    name: "Alarm Hemma"
    state_topic: "keypad_out"
    command_topic: "keypad_in"
    qos: 0
    payload_on: "ALARM_ON"
    payload_off: "ALARM_OFF"
    retain: true

  - platform: mqtt
    name: "Armera Hemma"
    state_topic: "keypad_out"
    command_topic: "keypad_in"
    qos: 0
    payload_on: "ALARM_MODE_ON"
    payload_off: "ALARM_MODE_OFF"
    retain: true

sensor:
  - platform: linknx
    scan_interval: 60
    entities:
      - { id: temp, name: "Utetemperatur", type: "°C" }
#     ... and some more

binary_sensor:
  - platform: linknx
    scan_interval: 60
    entities:
      - { id: is_workday, name: "Arbetsdag", type: "workday" }

media_player:
  - platform: squeezebox
    host: ip.for.ha.server
    port: 9000

mqtt:
  broker: ip.for.ha.server
  port: 1883