I love Home Assistant and use it to control my house. I run it on a Pine64 board and it handles everything. However for developing and modifying it I want to have a slightly better environment than nano and a console screen :) So using the Subsystem for Linux I have a Linux based setup to run the hass instance in and can use Visual Studio code to develop the modules as I go, best of both worlds.
To install the subsystem go to add/remove programs and tick the Windows Subsystem for Linux (Beta) then run
bash.exe and this will start the installation, this may take a while as it pulls down the bits. Once completed and you restarted you can run bash again and then you are ready to start. [caption id=”attachment_1213” align=”aligncenter” width=”534”] Installing the Windows Subsystem for Linux[/caption]
The https://home-assistant.io/developers/ page has lots of great information but here is how I do it condensed into a single process. In windows I have a dev folder under my user profile. This is
c:\Users\myaccount\dev, in the bash console it is mapped to
/mnt/c/Users/myaccount/dev/. This way you can work on the files in windows and run them in Linux, just watch out for a CR ;) Run the following in the bash terminal and replace the myaccount with your windows account and myrepo with your fork.
# ensure linux is up to date. sudo apt-get update sudo apt-get upgrade sudo apt-get install git # make local repo mkdir /mnt/c/Users/myaccount/dev/ mkdir /mnt/c/Users/myaccount/dev/home-assistant-bash-config cd /mnt/c/Users/myaccount/dev/ git clone https://github.com/myrepo/home-assistant.git home-assistant-bash cd home-assistant-bash git remote add upstream https://github.com/home-assistant/home-assistant.git # Ensure we are up to date git fetch upstream dev git rebase upstream/dev # dev environment setup sudo apt-get install python-pip python3-dev sudo apt-get install build-essential libssl-dev libffi-dev python-cffi sudo pip install --upgrade virtualenv # make and switch to virtual environment. virtualenv -p python3 . source ./bin/activate # prepare dev bits and install all the requirements, this does take a while. pip install --upgrade cryptography flake8 flake8-docstrings tox colorlog script/setup
If you do not have it download it here http://code.visualstudio.com/ once it is installed got to File -> Open Folder and navigate to
c:\Users\myaccount\dev\home-assistant-bash and open that location. Visual Studio Code (or just Code from now on) is smart enough to know it is on an enlistment in Linux and will work with just LF endings so you do not have to worry about that. Code has a concept of extensions, for Python I use Python, MagicPython and Python for VSCode. These provide syntax checking, lint and other actions in the UI to make life easier. Also as you work with files Code may suggest other extension to help you along, and it handles YAML as a bonus and I do all my configuration editing in it.
Open up bash and run the following.
cd /mnt/c/Users/myaccount/dev/ virtualenv -p python3 . source ./bin/activate hass -c /mnt/c/Users/myaccount/dev/home-assistant-bash-config
This is the rough process I use.
- Open up bash and shift to the virtual environment and run hass as a check to see if all is good.
- Rebase with upstream to ensure I am not drifting to much (the code base in Home Assistant is very fast moving)
- Run hass again to ensure all is good.
- Open up Code against the hass folder
- Open up Code against the configuration folder
- Hack away!
- Restart hass as needed and switch between windows while drinking coffee and wondering how you can automate the walking of the dog.
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you!