Home Assistant in a Docker container

I’ve managed to move my current Home Assistant install from a python virtual environment to Docker. This will allow me to upgrade the host operating system or move to a new computer without too much difficulty. The most difficult thing to get working was the networking and it took me a while to work out which containers needed to be on the host network and which could be on the default docker network.

My Docker stack has the following components:

  • Mosquitto
  • Zigbee2MQTT
  • Home Assistant
  • NodeRed
  • ESPhome
  • Lets-encrypt
  • My own personal power monitor Perl script
  • Watchtower
  • MySQL
  • phpMyAdmin

Eventually I’ll move my Plex install into the same environment but I’m waiting for me new 8Tb hard drive.

The docker-compose file looks like this:

version: '3.5'
services:
  mosquitto:
    container_name: mqtt
    hostname: mqtt
    image: eclipse-mosquitto
    labels:
      - com.centurylinklabs.watchtower.enable=true
    restart: always
    ports:
      - 1883:1883
      - 8883:8883
      - 9001:9001
    volumes:
      - /mnt/data/docker/mosquitto/config:/mosquitto/config
      - /mnt/data/docker/mosquitto/data:/mosquitto/data
      - /mnt/data/docker/mosquitto/log:/mosquitto/log
      - /etc/localtime:/etc/localtime:ro

  zigbee2mqtt:
    container_name: zigbee2mqtt
    hostname: zigbee2mqtt
    image: koenkk/zigbee2mqtt:latest
    volumes:
      - /mnt/data/docker/zigbee2mqtt:/app/data
      - /run/udev:/run/udev:ro
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
    depends_on:
      - mosquitto
    restart: always
    privileged: true
    environment:
      - TZ=Australia/Hobart

  homeassistant:
    container_name: homeassistant
    hostname: homeassistant
    image: homeassistant/home-assistant
    volumes:
      - /mnt/data/docker/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      - mosquitto
    restart: always
    network_mode: host

  nodered:
    container_name: nodered
    hostname: nodered
    labels:
      - com.centurylinklabs.watchtower.enable=true
    network_mode: host
    image: nodered/node-red-docker:latest
    ports:
      - 1880:1880
    volumes:
      - /mnt/data/docker/node-red:/data
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      - mosquitto
      - homeassistant
    restart: always
    environment:
      - TZ=Australia/Hobart

  esphome:
    container_name: esphome
    hostname: esphome
    image: esphome/esphome
    labels:
      - com.centurylinklabs.watchtower.enable=true
    volumes:
      - /mnt/data/docker/esphome:/config
      - /etc/localtime:/etc/localtime:ro
    restart: always
    network_mode: host
    
  lets-encrypt:
    container_name: letsencrypt
    hostname: letsencrypt
    image: linuxserver/letsencrypt
    labels:
      - com.centurylinklabs.watchtower.enable=true
    restart: always
    volumes: 
      - /mnt/data/docker/homeassistant/letsencrypt:/config
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 433:433
    cap_add:
      - NET_ADMIN
    environment:
      - PUID=1000
      - PGID=1000
      - EMAIL=chris.jennings@riscy.biz
      - URL=#####
      - VALIDATION=duckdns
      - TZ=Australia/Hobart
      - DUCKDNSTOKEN=#######

  powerlog:
    container_name: powerlog
    hostname: powerlog
    image: powerlog
    restart: always
    privileged: true
    volumes:
      - /mnt/data/docker/powerlog:/usr/src/myapp
      - /run/udev:/run/udev:ro
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    links:
      - mysql:mysql
    command: perl /usr/src/myapp/powerlog.pl      

  watchtower:
    container_name: watchtower
    image: containrrr/watchtower
    command: --cleanup --label-enable
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
  mysql:
    container_name: mysql
    hostname: mysql
    image: mysql
    ports:
      - 3306:3306
    restart: always
    volumes:
      - /mnt/data/docker/mysql:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro

  phpmyadmin:
    container_name: phpmyadmin
    hostname: phpmyadmin
    image: phpmyadmin/phpmyadmin
    ports:
      - 8080:80
    restart: always
    volumes:
      - /mnt/data/docker/phpmyadmin:/sessions
      - /etc/localtime:/etc/localtime:ro
    links:
      - mysql:db

I have all the docker mounted volumes in a folder /mnt/data/docker. To migrate MySQL I had to export the data and then import it into the new docker container. Copying the files over didn’t work, maybe it was because the MySQL version was incompatible. Best practice usually requires a mysqldump and import instead of just copying the MySQL files over.

Ensure that host names are set correctly so that containers can talk to each other. I also mounted /etc/localtime on each container to ensure the time is correct. Initially my Perl script was time stamping incorrectly because I didn’t map the time through.

Posted in Computers | Leave a comment

Quadcopters

Well a while ago I went to a friends place and there was someone with a quadcopter and they had it hooked up to their laptop and mucking around with it. I thought that looks like great fun so I bought some stuff and made my own. I got all the parts from a combination of RCTimer and HobbyKing but I think there is some good advice required for people who want to do the same.

I chose the RCTimer Spider UAV quadcopter:
RCTimer Spider

This is a good medium size quadcopter which has the capability of having a gimbal added to it later. These are the things I learnt that hopefully will help others to make the right decisions for their first quadcopter.

The XT60 connectors seem to be the new standard for all battery connections. You will need to buy male and female connectors to put on your power distribution board and batteries:
XT60 Connectors

Use 3.5mm connectors between your motors and ESCs, they can come loose but it makes field repairs easier. Just make sure you check ALL connections before each flight.
3.5mm connectors

The screws that come with the RCTimer quadcopter are total rubbish, they have ruined at least 4 hex key drivers. I decided to use screws from Element14 (hex head and torx).
Cheap hex head
Stainless steel hex head
Torx head

You need heatshrink, lots of it and some wire as well so you can extend the length of the ESC cables. You should twist the ESC cables that run back to the power distribution board. This will reduce the magnetic interference. AWG16 should be sufficient for a quadcopter this size:
Black cable
Red cable
Get a range of different sizes

Clear heatshrink is good for protecting some components that you need to see LEDs on (transmitters and receivers etc). I’d go into Jaycar and pick some up that looks the right size. You don’t save that much from getting it off eBay.

Make sure you get some nyloc nuts for your props. It is guaranteed that the nuts will come off otherwise, perhaps midair. Check the tightness of props and nuts before every launch. I got my nyloc nuts from Mitre 10.

These are other parts you should buy from RCTimer as well:
Telemetry kit
Spare frame (you will need it)
LiPo bag
Battery straps
Battery monitor
Spare props (plastic is better to start with, it cuts less OUCH!)
Cable ties, you can never have too many
Power monitor (and power supply for APM)

These instructions are great for putting it all together:
Build photos

This is a great guide with more detailed instructions:
Build tutorial

Now for parts you want from HobbyKing, they have a warehouse in Australia so they can send LiPo batteries by truck. You will want batteries, a charger and a transmitter. Start cheap and then work up to good stuff if you want:
Transmitter
4000mAh 4S battery (get two)
Battery charger

You will need a DC power supply for the battery charger. Jaycar has some, they are more expensive than they should be and I’ve had two blow up (one DOA the other after 3 months). But I couldn’t find anything better in Hobart for the price.
Power supply

In my next post I’ll discuss hints on how to make the build go smoothly.

Posted in Arduino, Drone | Comments Off on Quadcopters