I present to you, Home Assistant Supervised running on Docker in Windows 10 WSL2.
Please note: everything you need with the exception of Docker install is on this page, external links are provided for those who want a deeper dive.
- Install WSL (Don’t install a linux distro yet):
Open PowerShell as Administrator and run
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart your computer when prompted.
Open PowerShell as Administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Restart computer to apply changes.
Open PowerShell as Administrator and run:
wsl --set-default-version 2
(If you get an error running this then you must update Windows to the latest release).
Keep PowerShell open
Open the Microsoft Store and install Ubuntu, launch it and let it install, it will prompt to set a username and password.
Run in Ubuntu
sudo apt-get update
For Ubuntu 18.04:
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
For Ubuntu 19.04:
wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
For Ubuntu 20.04 (This appears to be the version that is installed from the store currently for “Ubuntu”)
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
For Ubuntu 21.04
wget https://packages.microsoft.com/config/ubuntu/21.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
The rest should be the same for all of them
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
now let’s install genie, first run sudo -s
then run:
wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg
chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
cat << EOF > /etc/apt/sources.list.d/wsl-transdebian.list
deb https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
EOF
apt update
sudo apt install -y systemd-genie
We’ll also need to install net-tools for later, run
sudo apt install net-tools
System restart might be needed, run:
genie -s
or if that doesnt work:
genie -c bash
*(Inside Genie) Run sudo su and install:
Docker CE instructions here: Docker Install
apt-get install the rest of the dependencies:
sudo apt-get install \
bash \
jq \
curl \
avahi-daemon \
dbus \
apparmor-utils \
network-manager
It’s now time to install HA
(Still inside Genie) Run as root (sudo su), hit y when requested.
wget https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb
dpkg -i homeassistant-supervised.deb
Within a few minutes you’ll be able to access HA on localhost:8123
- Networking & Starting with Windows
Unfortunately, WSL2 does not yet support bridged networking
So in order to be able to access HASS from outside the local machine we’ll need to run this workaround script at startup, it will also run HASS with the “genie -i” command.
Save this script somewhere on your PC with a .ps1 ending, note that you can add/remove/edit the ports you want forwarded from WSL
bash.exe -c "genie -i"
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
#[Ports]
#All the ports you want to forward separated by coma
$ports=@(80,443,8123,1880,1883,1884,8883,8884);
#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";
#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
for( $i = 0; $i -lt $ports.length; $i++ ){
$port = $ports[$i];
iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}
Open Task Scheduler and add click “Create Task”, enter a name for the task
Under General - “Check run whether user is logged in or not” and “Run with the highest privileges”
Under triggers click New, Begin the task at logon of any user
Under Actions click New, Select Start a program and type in program/script ‘Powershell.exe’
in arguments type ‘-ExecutionPolicy Bypass c:\Users\User\hass.ps1’
(Change the path to your saved script file)
Under settings uncheck “Stop the task if it runs longer than”
(Optional: Under settings you can check “if the task fails, restart every X minutes” if you’re having issues)
hit OK. (If you are unable to save the task you must have a password for your computer set)
- Power options - Set sleep to Never
- If you want your user to autologin → open start → Run, type ‘control userpasswords2’ and uncheck “Users must enter a name and password to use this computer”