Home Assistant: Difference between revisions

From NixOS Wiki
imported>Mweinelt
Describe how to use a recent home assistant version from unstable
imported>Mweinelt
Reorder
Line 31: Line 31:
</syntaxHighlight>
</syntaxHighlight>


= Home Assistant with nginx as a reverse proxy =
= Snippets =
 
== Reverse Proxying with nginx ==


If you run a public Home Assistant instance it is a good idea to enable SSL/TLS.
If you run a public Home Assistant instance it is a good idea to enable SSL/TLS.
Line 60: Line 62:
</syntaxHighlight>
</syntaxHighlight>


= Adding postgresql support =
== Using PostgreSQL ==


Home Assistant supports PostgreSQL as a database backend for, among other things, its logger and history components. It's a lot more scalable and typically provides faster response times than the SQLite database, that is used by default.
Home Assistant supports PostgreSQL as a database backend for, among other things, its logger and history components. It's a lot more scalable and typically provides faster response times than the SQLite database, that is used by default.
Line 86: Line 88:
</syntaxHighlight>
</syntaxHighlight>


= Run Home Assistant from GitHub repository =


When developing Home Assistant for some test dependencies additional libraries are needed.
== Add custom lovelace modules ==
A nix-shell expression for this is available [https://github.com/nix-community/nix-environments here].
 
= Add custom lovelace modules =


This [https://github.com/NixOS/nixpkgs/pull/89136 pull request] describes how to add custom lovelace modules.
This [https://github.com/NixOS/nixpkgs/pull/89136 pull request] describes how to add custom lovelace modules.


= Add custom components =
== Add custom components ==


In order to install a custom component, you have to place it in <code>/var/lib/hass/custom_components</code>. This can be achieved using systemd tmpfiles like so (for sonoff custom component):
In order to install a custom component, you have to place it in <code>/var/lib/hass/custom_components</code>. This can be achieved using systemd tmpfiles like so (for sonoff custom component):
Line 106: Line 104:
</syntaxHighlight>
</syntaxHighlight>


== Example configurations ==
= Example configurations =


- [https://github.com/Mic92/dotfiles/tree/master/nixos/eve/modules/home-assistant Mic92's config]
- [https://github.com/Mic92/dotfiles/tree/master/nixos/eve/modules/home-assistant Mic92's config]


- [https://github.com/balsoft/nixos-config/blob/master/modules/servers/home-assistant.nix Balsoft's config]
- [https://github.com/balsoft/nixos-config/blob/master/modules/servers/home-assistant.nix Balsoft's config]
= Misc =
== Run Home Assistant from GitHub repository ==
When developing Home Assistant for some test dependencies additional libraries are needed.
A nix-shell expression for this is available [https://github.com/nix-community/nix-environments here].

Revision as of 14:37, 15 June 2021

Home Assistant is an open source home automation software that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts.

Limited upstream support

Upstream has defined several installation methods which they are willing to support. NixOS is obviously not one of them. If you find a problem you can still report it upstream if you are certain that the issue is relevant to upstreams supported installation methods as well. If not, or if in doubt, please open an isssue on the nixpkgs issue tracker or visit us via matrix in #nixos-homeautomation:lossy.network.

Running a recent version using an overlay

Home Assistant is a fast-paced open source project, that currently features one major release every month, and a handful of minor ones in between. Firmwares and API endpoints tend to change from time to time, so Home Assistant and its bindings need to keep up to keep things work. The version we provide at the branch off is just a snapshot in time, and does not receive any updates, because there would just be too many dependencies to backport. But with NixOS it is still possible to use the version in nixpkgs/unstable by creating an overlay.

let
  # Track NixOS unstable via nix-channel, or replace it with something like niv at your own discretion
  # nix-channel --add http://nixos.org/channels/nixos-unstable nixos-unstable
  unstable = import <nixos-unstable> {};
{
  nixpkgs.overlays = [
    (self: super: {
      inherit (unstable) home-assistant;
    }
  ];

  disabledModules = [
    "services/misc/home-assistant.nix"
  ];

  imports = [
    "${unstable}/nixos/modules/services/misc/home-assistant.nix"
  ];
}

Snippets

Reverse Proxying with nginx

If you run a public Home Assistant instance it is a good idea to enable SSL/TLS. The following configuration generates a certificate using letsencrypt:

  services.home-assistant.config
    server_host = "::1";
    trusted_proxies = [ "::1" ];
    use_x_forwarded_for = true;
  };

  services.nginx = {
    recommendedProxySettings = true;
    virtualHosts."home.example.com" = {
      forceSSL = true;
      enableACME = true;
      extraConfig = ''
        proxy_buffering off;
      '';
      locations."/" = {
        proxyPass = "http://[::1]:8123";
        proxyWebsockets = true;
      };
    };
  };

Using PostgreSQL

Home Assistant supports PostgreSQL as a database backend for, among other things, its logger and history components. It's a lot more scalable and typically provides faster response times than the SQLite database, that is used by default.

Remember to make backups of your database, for Home Assistant is becoming more and more stateful and has moved away from a completely declarative YAML configuration for new and core components.

  services.home-assistant = {
    package = (pkgs.home-assistant.override {
      extraPackages = py: with py; [ psycopg2 ];
    });
    config.recorder.db_url = "postgresql://@/hass";
  };

  services.postgresql = {
    enable = true;
    ensureDatabases = [ "hass" ];
    ensureUsers = [{
      name = "hass";
      ensurePermissions = {
        "DATABASE hass" = "ALL PRIVILEGES";
      };
    }];
  };


Add custom lovelace modules

This pull request describes how to add custom lovelace modules.

Add custom components

In order to install a custom component, you have to place it in /var/lib/hass/custom_components. This can be achieved using systemd tmpfiles like so (for sonoff custom component):

  systemd.tmpfiles.rules = [
    "C /var/lib/hass/custom_components/sonoff - - - - ${sources.sonoff-lan}/custom_components/sonoff"
    "Z /var/lib/hass/custom_components 770 hass hass - -"
  ];

Example configurations

- Mic92's config

- Balsoft's config

Misc

Run Home Assistant from GitHub repository

When developing Home Assistant for some test dependencies additional libraries are needed. A nix-shell expression for this is available here.