From c8fce8af5101064ea3dcfcb9d2bc39f1b9b83755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 14 Dec 2022 15:20:26 +0100 Subject: Add Home Assistant Now running on Errol as the cross compilation for python cryptography does not work correctly. --- nixos/machine/errol.nix | 28 +++++++++++++++++++++++++ nixos/machine/hass/light.nix | 13 ++++++++++++ nixos/machine/hass/sensors.nix | 19 +++++++++++++++++ nixos/machine/spt-mox.nix | 46 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 nixos/machine/hass/light.nix create mode 100644 nixos/machine/hass/sensors.nix (limited to 'nixos') diff --git a/nixos/machine/errol.nix b/nixos/machine/errol.nix index 06e2446..835999a 100644 --- a/nixos/machine/errol.nix +++ b/nixos/machine/errol.nix @@ -60,6 +60,34 @@ with lib; configDir = "/home/cynerd/.config/syncthing"; }; + services.home-assistant = { + enable = true; + openFirewall = true; + configDir = "/var/lib/hass"; + config = { + homeassistant = { + name = "SPT"; + latitude = "!secret latitude"; + longitude = "!secret longitude"; + elevation = "!secret elevation"; + time_zone = "Europe/Prague"; + country = "CZ"; + }; + http.server_port = 8808; + mqtt = { + broker = config.cynerd.hosts.spt.mox; + port = 1883; + username = "homeassistant"; + password = "!secret mqtt_password"; + sensor = import ./hass/sensors.nix; + light = import ./hass/light.nix; + }; + met = {}; + default_config = {}; + }; + extraComponents = []; + }; + }; } diff --git a/nixos/machine/hass/light.nix b/nixos/machine/hass/light.nix new file mode 100644 index 0000000..a9d158b --- /dev/null +++ b/nixos/machine/hass/light.nix @@ -0,0 +1,13 @@ +[ + { + name = "RGB Osvětlení"; + command_topic = "homeassistant/led-strip"; + brightness_scale = 100; + brightness_command_topic = "bigclown/node/power-controller:0/led-strip/-/brightness/set"; + #brightness_state_topic = "bigclown/node/power-controller:0/led-strip/-/brightness/set"; + rgb_command_template = ''"#{{"%02x" % red}}{{"%02x" % green}}{{"%02x" % blue}}"''; + rgb_command_topic = "bigclown/node/power-controller:0/led-strip/-/color/set"; + #rgb_value_template = ''{{int(value[2:4],16)}},{{int(value[5:7],16)}},{{int(value[8:10],16)}}''; + #rgb_state_topic = "bigclown/node/power-controller:0/led-strip/-/color/set"; + } +] diff --git a/nixos/machine/hass/sensors.nix b/nixos/machine/hass/sensors.nix new file mode 100644 index 0000000..fadd4eb --- /dev/null +++ b/nixos/machine/hass/sensors.nix @@ -0,0 +1,19 @@ +[ + { + name = "Teplota"; + state_class = "measurement"; + state_topic = "bigclown/node/climate-monitor:0/thermometer/0:0/temperature"; + unit_of_measurement = "°C"; + } + { + name = "Vlhkost"; + state_class = "measurement"; + state_topic = "bigclown/node/climate-monitor:0/hygrometer/0:4/relative-humidity"; + unit_of_measurement = "%"; + } + { + name = "Osvětlení"; + state_class = "measurement"; + state_topic = "bigclown/node/climate-monitor:0/lux-meter/0:0/illuminance"; + } +] diff --git a/nixos/machine/spt-mox.nix b/nixos/machine/spt-mox.nix index b01c48a..acca74c 100644 --- a/nixos/machine/spt-mox.nix +++ b/nixos/machine/spt-mox.nix @@ -75,6 +75,13 @@ with lib; acl = ["readwrite bigclown/#"]; passwordFile = "/run/secrets/mosquitto.bigclown.pass"; }; + homeassistant = { + acl = [ + "readwrite bigclown/#" + "readwrite homeassistant/#" + ]; + passwordFile = "/run/secrets/mosquitto.homeassistant.pass"; + }; }; } ]; @@ -170,6 +177,45 @@ with lib; serviceConfig.ExecStart = "${pkgs.bigclown-leds}/bin/bigclown-leds /run/secrets/bigclown-leds.ini"; }; + services.home-assistant = { + enable = false; + openFirewall = true; + configDir = "/var/lib/hass"; + config = { + homeassistant = { + name = "SPT"; + latitude = "!secret latitude"; + longitude = "!secret longitude"; + elevation = "!secret elevation"; + time_zone = "Europe/Prague"; + country = "CZ"; + }; + http.server_port = 8808; + mqtt = { + broker = config.cynerd.hosts.spt.mox; + port = 1883; + username = "homeassistant"; + password = "!secret mqtt_password"; + sensor = import ./hass/sensors.nix; + light = import ./hass/light.nix; + }; + met = {}; + default_config = {}; + }; + extraComponents = []; + package = pkgs.home-assistant.override { + packageOverrides = (self: super: { + scapy = super.scapy.override { + withPlottingSupport = false; + }; + s3transfer = super.s3transfer.overridePythonAttrs (oldAttrs: { + dontUsePytestCheck = true; + dontUseSetuptoolsCheck = true; + }); + }); + }; + }; + }; } -- cgit v1.2.3