Home Assistant: Difference between revisions

From NixOS Wiki
imported>Mweinelt
Configure home-assistant's http component in reverse proxy example
imported>Fab
m Minor tweaking
Line 32: Line 32:
= Adding postgresql support =
= Adding postgresql support =


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.


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.
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.


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
Line 56: Line 56:
</syntaxHighlight>
</syntaxHighlight>


= Run home-assistant from github repository =
= Run Home Assistant from GitHub repository =


When developing home-assistant for some test dependencies additional libraries are needed.
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].
A nix-shell expression for this is available [https://github.com/nix-community/nix-environments here].



Revision as of 10:27, 14 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.

Home Assistant with nginx as a reverse proxy

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;
      };
    };
  };

Adding postgresql support

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";
      };
    }];
  };

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.

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