Post

Install "Home Assistant" as Windows service

Home Assistant is automation platform for home written on Python. It allows to connect a whole bunch of devices and create rules to perform automated tasks.

For Mac OS and Linux there are instruction on how to daemonize (autostart) the platform. So, here are the missing for Windows.

There numerous way to run a Python script as Windows Service, including the accepted answer on StackOverflow, but IMHO a much simpler approach is by using NSSM.

  1. Download and extract NSSM from here

  2. Run from command line \win64\nssm.exe install HomeAssistant which will launch configuration UI for service

  3. In this example I installed “Home Assistant” under Python Virtual Environment located at C:\hass-env\, which places executable at C:\hass-env\Scripts\hass.exe. The configuration folder is located in %appdata%\.homeassistant\, hence will pass it location via argument -c:

  4. Details screen is self explanatory:

  5. I’m running it with Local System account (this is why I needed to specify configuration folder in step #3 to my %appdata%):

  6. To catch log information written to console I defined I/O redirection to custom log file:

  7. You can define file rotation in case output file growths fast as following:

  8. Click Install service and you be able to find it in SCM:

    Installed Services

At this stage you should be now able to start, stop and restart the service. If error thrown during startup, the service won’t start and you can check the log file for details.