diff --git a/hosts/freun-dev/services.nix b/hosts/freun-dev/services.nix index b709575..c748840 100644 --- a/hosts/freun-dev/services.nix +++ b/hosts/freun-dev/services.nix @@ -290,5 +290,85 @@ in }; }; }; + + home-assistant = { + enable = true; + subdomain = "home"; + config = { + homeassistant = { + name = "Koti"; + unit_system = "metric"; + time_zone = "Europe/Helsinki"; + }; + http = { + server_port = 8123; + use_x_forwarded_for = true; + trusted_proxies = [ + "127.0.0.1" + "::1" + ]; + }; + mqtt = [ + { + climate = { + unique_id = "nappula"; + name = "Nappula"; + current_humidity_topic = "homie/nappula/humidity/value"; + current_humidity_template = "{{ value | float }}"; + current_temperature_topic = "homie/nappula/temperature/value"; + current_temperature_template = "{{ value | float }}"; + mode_state_topic = "homie/nappula/ac/trigger"; + mode_state_template = "{% if value == 'true' %}heat{% else %}off{% endif %}"; + availability = { + topic = "homie/nappula/$online"; + payload_available = "true"; + payload_not_available = "false"; + }; + modes = [ + "off" + "heat" + ]; + }; + } + { + button = { + unique_id = "nappula_button"; + name = "Nappula anschalten"; + command_topic = "homie/nappula/button/trigger/set"; + payload_press = "true"; + availability = { + topic = "homie/nappula/$online"; + payload_available = "true"; + payload_not_available = "false"; + }; + icon = "mdi:power"; + }; + } + { + sensor = { + unique_id = "nappula_pressure"; + name = "Luftdruck"; + state_topic = "homie/nappula/pressure/value"; + device_class = "atmospheric_pressure"; + unit_of_measurement = "hPa"; + state_class = "measurement"; + value_template = "{{ value | float // 100 }}"; + }; + } + ]; + }; + extraComponents = [ + "default_config" + "esphome" + "met" + "radio_browser" + "mqtt" + ]; + extraPackages = ( + python3Packages: with python3Packages; [ + paho-mqtt + ] + ); + }; }; } diff --git a/modules/services/default.nix b/modules/services/default.nix index 3c1e44b..dc35b85 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -22,5 +22,6 @@ ./mealie.nix ./uptime-kuma.nix ./mosquitto.nix + ./home-assistant.nix ]; } diff --git a/modules/services/home-assistant.nix b/modules/services/home-assistant.nix new file mode 100644 index 0000000..601c594 --- /dev/null +++ b/modules/services/home-assistant.nix @@ -0,0 +1,20 @@ +{ config, lib, ... }: +let + cfg = config.services.home-assistant; + fqdn = "${cfg.subdomain}.${config.networking.domain}"; +in +{ + options.services.home-assistant = { + subdomain = lib.mkOption { + type = lib.types.str; + description = "The subdomain to use for Home Assistant"; + }; + }; + + config = lib.mkIf cfg.enable { + services.webserver = { + enable = lib.mkDefault true; + vHosts.${fqdn}.locations."/".proxyPort = cfg.config.http.server_port; + }; + }; +}