Skip to content

Instantly share code, notes, and snippets.

@cgtobi
Last active December 28, 2018 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgtobi/5597887d7ded60bd96e55c817659ad21 to your computer and use it in GitHub Desktop.
Save cgtobi/5597887d7ded60bd96e55c817659ad21 to your computer and use it in GitHub Desktop.
Getting HASS data science lab up and running on Ubuntu 18.10.

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:my_secret_password@hostname.to.your.hass.instance/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment