Data Science quick start guide for non-hass.io users

Quick start on Ubuntu

Installation

Starting with a fresh Ubuntu 18.10.

sudo apt update
sudo apt upgrade
sudo apt install python3-pip
sudo pip3 install jupyterlab
sudo pip3 install HASS-data-detective
sudo pip3 install homeassistant
sudo pip3 install sqlalchemy

If using postgreSQL:

pip3 install psycopg2-binary

Prepare environment

su - ubuntu
mkdir ~/Notebook
cd ~/Notebook
git clone https://github.com/home-assistant/home-assistant-notebooks.git

Launch Jupyter Lab as systemd service

sudo curl -o /etc/systemd/system/jupyterlab.service https://gist.githubusercontent.com/cgtobi/11439422a65610680127dcb2d507482a/raw/0ba0574bafc160c1cc9edf0d1361c7ae62af7453/jupyterlab.service
sudo systemctl daemon-reload
sudo systemctl enable jupyterlab.service
sudo systemctl start jupyterlab.service

Create read-only database user

PostgreSQL

Run where your HASS DB lives:

sudo -u postgres psql
postgres=# CREATE USER datascience WITH encrypted password 'my_secret_password';
sudo -u postgres psql -dhass
hass=# GRANT CONNECT ON DATABASE hass to datascience;
hass=# ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO datascience;
hass=# GRANT USAGE ON SCHEMA public to datascience; 
hass=# GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO datascience;
hass=# GRANT SELECT ON ALL TABLES IN SCHEMA public TO datascience;

Run the GETTING STARTED notebook

Open the GETTING STARTED notebook and modify the database connection accordingly.

db = HassDatabase("postgresql://datascience:[email protected]/hass")

Now follow the instructions in the notebook, click on “Run” in the top menubar and click on “Run All Cells”.

See the quick start guide.