Wednesday, 19 October 2016

Getting HADashboard up and running on Jessie for use with Home Assistant

HADashboard is a very cool dashboard for use with Home Assistant. I’ve tested the installation process on a Raspberry Pi1 version B (yes I know) and although it took nearly a whole day to get working, work it does and by golly, does it look good. More info on GitHub here https://github.com/home-assistant/hadashboard
  1. First step is to install docker on your Raspberry Pi if you have never done that before:
    curl -sSL get.docker.com | sh
  2. If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:
    sudo usermod -aG docker pi
  3. Set Docker to auto-start:
    sudo systemctl enable docker
More info here and credit to Alex Ellis http://blog.alexellis.io/getting-started-with-docker-on-raspberry-pi/



Installing HADashboard for Home Assistant on Jessie
  1. Clone the Repository:
    Clone the hadashboard repository to the current local directory on your machine.
    git clone https://github.com/home-assistant/hadashboard.git
  2. Change your working directory to the repository root. Moving forward, we will be working from this directory:
    cd hadashboard
  3. Install the hadashboard docker file:
    Raspberry pi needs to use a different docker build file so the build command is slightly different:
    docker build -f Docker-raspi/Dockerfile -t hadashboard . (Don’t forget the full stop (.) at the end. N.B This took 5hrs on a Pi1 B so be prepared to wait).
  4. Next, in the ./lib directory, copy the ha_conf.rb.example file to ha_conf.rb and edit its settings to reflect your installation, pointing to the machine Home Assistant is running on and adding your api_key.

    $ha_url = "http://10.0.2.17:8123"
    $ha_apikey = "your key"

    $ha_url is a reference to your home assistant installation and must include the correct port number and scheme (http:// or https:// as appropriate)
    $ha_apikey should be set to your key if you have one, otherwise it can remain blank.

    The file also contains example newsfeeds for the News widget:

    $news_feeds = {
      "Traffic" => "http://api.sr.se/api/rss/traffic/2863",
      "News" => http://feeds.bbci.co.uk/news/rss.xml,
    }

    You can leave these alone for now or if you prefer customize them as described in the News widget section here https://github.com/home-assistant/hadashboard#news.
  5. Make a copy of dashboards/example.erb and call it 'main.erb', then edit this file to reference the items you want to display and control and to get the layout that you want. Leave the original example.erb intact and unchanged so that you don't run into problems when trying to update using the git commands mentioned later in "Updating the Dashboard". Full instructions here https://github.com/home-assistant/hadashboard#configuring-the-dashboard-all-installations.
  6. In the directory /home/pi/hadashboard/hapush, copy the hapush.cfg.example file to hapush.cfg then edit it to reflect your environment. This is what mine looks like.

    ha_url = "http://10.0.2.17:8123"
    ha_key =
    dash_host = "10.0.2.17:3030"
    dash_dir="/app/dashboards"
    logfile = "/app/hapush/hapush.log"
  7. You are now ready to run the docker image.
    docker run --name="hadashboard" -d -v /home/pi/hadashboard/dashboards:/app/dashboards -v /home/pi/hadashboard/lib/ha_conf.rb:/app/lib/ha_conf.rb -v /home/pi/hadashboard/hapush:/app/hapush --net=host hadashboard (all in one line)

    You may need to double check your paths are correct for mapping to the dashboards, ha_conf.rb and hapush locations? These are for my Pi with a standard Jessie install.
  8. You should get back something like this meaning your container has at least started:
    0aac704f2093dd10ff0413f0e77c50769c5c569ee25fd57cb67ee1d338e51f3b
  9. You should now be able to go to <ipaddressofyourPi>:3030/main to see the example hadashboard. By default, if you do not append the /main it will load the example file <ipaddressofyourPi>:3030/example
DEBUGGING STEPS
  1. Test your docker instance:
    docker ps -a
  2. This should return:
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
    0aac704f2093        hadashboard         "/bin/sh -c '/app/hap"   About an hour ago   Up 59 minutes                           hadashboard
    You need the “Container ID” for the next step.
  3. Using the container ID, inspect the logs:
    docker logs xxxxxxx (Transpose xxxxxxx with your container ID).
  4. To restart your docker container:
    docker restart <yourcontainerID>
  5. To check all of your file mappings and to make sure everything is supposed to be where it supposed to be, try this:
    docker exec -t -i <yourcontainerID> /bin/bash then,

    ls /app/hapush/ should give you:

    root@raspberrypi:/app# ls /app/hapush/
    hapush.cfg  hapush.cfg.example  hapush.log  hapush.py
    root@raspberrypi:/app#

    ls /app/dashboards should give you:

    root@raspberrypi:/app# ls /app/dashboards
    example.erb  layout.erb  main.erb
    root@raspberrypi:/app#
  6. Navigate to /home/pi/hadashboard/hapush/hapush.log using WinSCP to see what is going on. If everything is OK, there should only be two lines:

    2016-10-18 21:48:27,891 INFO Reading dashboard: /app/dashboards/main.erb
    2016-10-18 21:48:27,948 INFO Reading dashboard: /app/dashboards/example.erb
For the more adventurous out there that even know what a docker-compose.yaml file is, user @snizzleorg has provide some information on starting the docker containers using a better method. More info here https://github.com/home-assistant/hadashboard#starting-at-reboot


“I personally prefer docker-compose to create and run the images:
This is my docker-compose.yaml file for hadashboard:”
---
home-assistant:
  build: Dockerfile-rpi
  restart: always
  net: "host"
  volumes:
    - '/etc/localtime:/etc/localtime:ro'
    - '/etc/timezone:/etc/timezone:ro'
    - '/etc/home-assistant/hadashboard/dashboards:/app/dashboards
    - '/etc/home-assistant/hadashboard/config/:/app/lib/
    - '/etc/home-assistant/hadashboard/hapush/:/app/hapush/


Good luck and may the force be with you.
Post your issues in GitHub here https://github.com/home-assistant/hadashboard/issues